-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(open-api): add top-level security information
INT-407
- Loading branch information
Showing
4 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/.vuepress/theme/client/components/global/OpenApiSecurityRequirements.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<template> | ||
<div v-if="resolvedSchemes?.length"> | ||
<ul> | ||
<OpenApiSecurityScheme | ||
v-for="(securityItem, index) in resolvedSchemes" | ||
:key="index" | ||
:scheme="resolveRequirementToScheme(securityItem)" /> | ||
</ul> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {computed} from 'vue'; | ||
import {type OpenAPIV3_1 as OpenApiType} from 'openapi-types'; | ||
import {OpenApiSecurityScheme} from '@mptheme/client/components/global'; | ||
const props = defineProps<{ | ||
security: OpenApiType.SecurityRequirementObject[]; | ||
securitySchemes: Record<string, OpenApiType.SecuritySchemeObject>; | ||
}>(); | ||
const resolvedSchemes = computed(() => { | ||
const resolved: OpenApiType.SecurityRequirementObject[] = []; | ||
for (const requirement of props.security) { | ||
const scheme = resolveRequirementToScheme(requirement); | ||
if (scheme) { | ||
resolved.push(requirement); | ||
} | ||
} | ||
return resolved; | ||
}); | ||
function resolveRequirementToScheme( | ||
requirement: OpenApiType.SecurityRequirementObject, | ||
): OpenApiType.SecuritySchemeObject | undefined { | ||
// Find the securityScheme with the same key as the securityRequirement | ||
return props.securitySchemes[Object.keys(requirement)[0]]; | ||
} | ||
</script> |
18 changes: 18 additions & 0 deletions
18
src/.vuepress/theme/client/components/global/OpenApiSecurityScheme.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<template> | ||
<li v-if="scheme.type === 'apiKey'"> | ||
<strong>API Key</strong><br /> | ||
<code class="m-0 p-0 text-sm whitespace-nowrap"> {{ scheme.in }}: {{ scheme.name }} </code> | ||
</li> | ||
<li v-else-if="scheme.type === 'http'"> | ||
<strong>HTTP</strong><br /> | ||
<code class="m-0 p-0 text-sm whitespace-nowrap"> {{ scheme.scheme }}: {{ scheme.bearerFormat }} </code> | ||
</li> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {type OpenAPIV3_1 as OpenApiType} from 'openapi-types'; | ||
defineProps<{ | ||
scheme: OpenApiType.SecuritySchemeObject; | ||
}>(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters