-
Couldn't load subscription status.
- Fork 517
refactor(types): improved security scheme #1915
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,10 @@ import { isString, isUndefined, negate, pickBy } from 'lodash'; | |||||||||
| import { buildDocumentBase } from './fixtures/document.base'; | ||||||||||
| import { OpenAPIObject } from './interfaces'; | ||||||||||
| import { | ||||||||||
| ApiKeySchemeObject, | ||||||||||
| ExternalDocumentationObject, | ||||||||||
| HttpSchemeObject, | ||||||||||
| OAuth2SchemeObject, | ||||||||||
| SecurityRequirementObject, | ||||||||||
| SecuritySchemeObject, | ||||||||||
| ServerVariableObject, | ||||||||||
|
|
@@ -110,12 +113,11 @@ export class DocumentBuilder { | |||||||||
| } | ||||||||||
|
|
||||||||||
| public addBearerAuth( | ||||||||||
| options: SecuritySchemeObject = { | ||||||||||
| type: 'http' | ||||||||||
| }, | ||||||||||
| options: Partial<Omit<HttpSchemeObject, 'type'>> = {}, | ||||||||||
| name = 'bearer' | ||||||||||
| ): this { | ||||||||||
| this.addSecurity(name, { | ||||||||||
| type: 'http', | ||||||||||
| scheme: 'bearer', | ||||||||||
| bearerFormat: 'JWT', | ||||||||||
| ...options | ||||||||||
|
|
@@ -124,9 +126,7 @@ export class DocumentBuilder { | |||||||||
| } | ||||||||||
|
|
||||||||||
| public addOAuth2( | ||||||||||
| options: SecuritySchemeObject = { | ||||||||||
| type: 'oauth2' | ||||||||||
| }, | ||||||||||
| options: Partial<Omit<OAuth2SchemeObject, 'type'>> = {}, | ||||||||||
| name = 'oauth2' | ||||||||||
| ): this { | ||||||||||
| this.addSecurity(name, { | ||||||||||
|
|
@@ -137,40 +137,34 @@ export class DocumentBuilder { | |||||||||
| return this; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public addApiKey( | ||||||||||
| options: SecuritySchemeObject = { | ||||||||||
| type: 'apiKey' | ||||||||||
| }, | ||||||||||
| name = 'api_key' | ||||||||||
| public addBasicAuth( | ||||||||||
| options: Partial<Omit<HttpSchemeObject, 'type'>> = {}, | ||||||||||
| name = 'basic' | ||||||||||
|
Comment on lines
+141
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making the change I mentioned above here so it would be
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jmcdo29, Yes, this can also be added, but is it better in a minor update?.. |
||||||||||
| ): this { | ||||||||||
| this.addSecurity(name, { | ||||||||||
| type: 'apiKey', | ||||||||||
| in: 'header', | ||||||||||
| name, | ||||||||||
| type: 'http', | ||||||||||
| scheme: 'basic', | ||||||||||
| ...options | ||||||||||
| }); | ||||||||||
| return this; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public addBasicAuth( | ||||||||||
| options: SecuritySchemeObject = { | ||||||||||
| type: 'http' | ||||||||||
| }, | ||||||||||
| name = 'basic' | ||||||||||
| public addApiKey( | ||||||||||
| options: Partial<Omit<ApiKeySchemeObject, 'type'>> = {}, | ||||||||||
| name = 'api_key' | ||||||||||
| ): this { | ||||||||||
| this.addSecurity(name, { | ||||||||||
| type: 'http', | ||||||||||
| scheme: 'basic', | ||||||||||
| type: 'apiKey', | ||||||||||
| in: 'header', | ||||||||||
| name, | ||||||||||
| ...options | ||||||||||
| }); | ||||||||||
| return this; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public addCookieAuth( | ||||||||||
| cookieName = 'connect.sid', | ||||||||||
| options: SecuritySchemeObject = { | ||||||||||
| type: 'apiKey' | ||||||||||
| }, | ||||||||||
| options: Partial<Omit<ApiKeySchemeObject, 'type'>> = {}, | ||||||||||
| securityName = 'cookie' | ||||||||||
| ): this { | ||||||||||
| this.addSecurity(securityName, { | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would make it a breaking change, but would it make more sense to bring the name to be the first parameter instead of the options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmcdo29 , yep, you're right. Fixed