Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multiple alternative security objects in route schema #817

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions examples/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const swaggerOption = {
type: 'apiKey',
name: 'apiKey',
in: 'header'
},
basicAuth: {
type: 'basic'
}
},
security: [{
Expand Down Expand Up @@ -281,6 +284,24 @@ const schemaSecurity = {
}
}

const schemaOpenapiSecurityMultipleAlterntives = {
schema: {
security: [
{ apiKey: [] },
{ bearerAuth: [] }
]
}
}

const schemaSwaggerSecurityMultipleAlterntives = {
schema: {
security: [
{ apiKey: [] },
{ basicAuth: [] }
]
}
}

const schemaConsumes = {
schema: {
consumes: ['application/x-www-form-urlencoded'],
Expand Down Expand Up @@ -376,6 +397,8 @@ module.exports = {
schemaHeaders,
schemaHeadersParams,
schemaSecurity,
schemaOpenapiSecurityMultipleAlterntives,
schemaSwaggerSecurityMultipleAlterntives,
schemaConsumes,
schemaProduces,
schemaCookies,
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ declare module 'fastify' {
consumes?: readonly string[];
produces?: readonly string[];
externalDocs?: OpenAPIV2.ExternalDocumentationObject | OpenAPIV3.ExternalDocumentationObject;
security?: ReadonlyArray<{ [securityLabel: string]: readonly string[] }>;
security?: ReadonlyArray<{ [securityLabel: string]: (readonly string[] | undefined) }>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is weird to allows undefined here.

/**
* OpenAPI operation unique identifier
*/
Expand All @@ -52,7 +52,7 @@ declare module 'fastify' {
[statusCode: string]: OpenAPIV3.ResponseObject['links'];
}
}

interface FastifyContextConfig {
swaggerTransform?: SwaggerTransform | false;
}
Expand Down
Loading