-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: port security scheme model to ts (#513)
- Loading branch information
Showing
20 changed files
with
471 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BaseModel } from './base'; | ||
import { ExtensionsMixinInterface } from './mixins'; | ||
|
||
export interface OAuthFlowInterface extends BaseModel, ExtensionsMixinInterface { | ||
authorizationUrl(): string | undefined; | ||
hasRefreshUrl(): boolean; | ||
refreshUrl(): string | undefined; | ||
scopes(): Record<string, string> | undefined; | ||
tokenUrl(): string | undefined; | ||
} |
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,14 @@ | ||
import { OAuthFlowInterface } from './oauth-flow'; | ||
import { BaseModel } from './base'; | ||
import {ExtensionsMixinInterface} from './mixins'; | ||
|
||
export interface OAuthFlowsInterface extends BaseModel, ExtensionsMixinInterface { | ||
hasAuthorizationCode(): boolean; | ||
authorizationCode(): OAuthFlowInterface | undefined; | ||
hasClientCredentials(): boolean | ||
clientCredentials(): OAuthFlowInterface | undefined; | ||
hasImplicit(): boolean; | ||
implicit(): OAuthFlowInterface | undefined; | ||
hasPassword(): boolean; | ||
password(): OAuthFlowInterface | undefined; | ||
} |
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 @@ | ||
import { BaseModel } from './base'; | ||
import { DescriptionMixinInterface, ExtensionsMixinInterface } from './mixins'; | ||
import { OAuthFlowsInterface } from './oauth-flows'; | ||
|
||
export type SecuritySchemaType = 'userPassword' | 'apiKey' | 'X509' | 'symmetricEncryption' | 'asymmetricEncryption' | 'httpApiKey' | 'http' | 'oauth2' | 'openIdConnect' | 'plain' | 'scramSha256' | 'scramSha512' | 'gssapi'; | ||
|
||
|
||
export interface SecuritySchemeInterface extends BaseModel, DescriptionMixinInterface, ExtensionsMixinInterface { | ||
id(): string | ||
hasBearerFormat(): boolean; | ||
bearerFormat(): string | undefined; | ||
openIdConnectUrl(): string; | ||
scheme(): string | undefined; | ||
flows(): OAuthFlowsInterface | undefined; | ||
scopes(): string[]; | ||
type(): SecuritySchemaType; | ||
in(): string | undefined; | ||
} |
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,4 @@ | ||
import {Collection} from './collection'; | ||
import { SecuritySchemeInterface } from './security-scheme'; | ||
|
||
export interface SecuritySchemesInterface extends Collection<SecuritySchemeInterface> {} |
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
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,23 @@ | ||
import { OAuthFlowInterface } from '../oauth-flow'; | ||
import { BaseModel } from '../base'; | ||
import { Mixin } from '../utils'; | ||
import { ExtensionsMixin } from './mixins/extensions'; | ||
|
||
export class OAuthFlow extends Mixin(BaseModel, ExtensionsMixin) implements OAuthFlowInterface { | ||
authorizationUrl(): string | undefined { | ||
return this._json.authorizationUrl; | ||
} | ||
hasRefreshUrl(): boolean { | ||
return !!this._json.refreshUrl; | ||
} | ||
refreshUrl(): string | undefined { | ||
return this._json.refreshUrl; | ||
} | ||
scopes(): Record<string, string> | undefined { | ||
return this._json.scopes; | ||
} | ||
tokenUrl(): string | undefined { | ||
return this._json.tokenUrl; | ||
} | ||
|
||
} |
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,39 @@ | ||
import { OAuthFlowsInterface } from '../oauth-flows'; | ||
import { BaseModel } from '../base'; | ||
import { Mixin } from '../utils'; | ||
import { ExtensionsMixin } from './mixins/extensions'; | ||
import { OAuthFlowInterface } from 'models/oauth-flow'; | ||
import { OAuthFlow } from './oauth-flow'; | ||
|
||
export class OAuthFlows extends Mixin(BaseModel, ExtensionsMixin) implements OAuthFlowsInterface { | ||
hasAuthorizationCode(): boolean { | ||
return !!this._json.authorizationCode; | ||
} | ||
authorizationCode(): OAuthFlowInterface | undefined { | ||
if (!this._json.authorizationCode) return undefined; | ||
return new OAuthFlow(this._json.authorizationCode); | ||
} | ||
hasClientCredentials(): boolean { | ||
return !!this._json.clientCredentials; | ||
} | ||
clientCredentials(): OAuthFlowInterface | undefined { | ||
if (!this._json.clientCredentials) return undefined; | ||
return new OAuthFlow(this._json.clientCredentials); | ||
} | ||
hasImplicit(): boolean { | ||
return !!this._json.implicit; | ||
} | ||
implicit(): OAuthFlowInterface | undefined { | ||
if (!this._json.implicit) return undefined; | ||
return new OAuthFlow(this._json.implicit); | ||
} | ||
hasPassword(): boolean { | ||
return !!this._json.password; | ||
} | ||
password(): OAuthFlowInterface | undefined { | ||
if (!this._json.password) return undefined; | ||
return new OAuthFlow(this._json.password); | ||
} | ||
|
||
|
||
} |
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,55 @@ | ||
import { BaseModel, ModelMetadata } from '../base'; | ||
import { Mixin } from '../utils'; | ||
import { DescriptionMixin } from './mixins/description'; | ||
import { ExtensionsMixin } from './mixins/extensions'; | ||
import { SecuritySchemaType, SecuritySchemeInterface } from '../security-scheme'; | ||
import { OAuthFlowsInterface } from 'models/oauth-flows'; | ||
import { OAuthFlows } from './oauth-flows'; | ||
|
||
export class SecurityScheme extends Mixin(BaseModel, DescriptionMixin, ExtensionsMixin) implements SecuritySchemeInterface { | ||
constructor( | ||
private readonly _id: string, | ||
_json: Record<string, any>, | ||
_meta: ModelMetadata = {} as any | ||
) { | ||
super(_json, _meta); | ||
} | ||
|
||
id(): string { | ||
return this._id; | ||
} | ||
|
||
hasBearerFormat(): boolean { | ||
return !!this._json.bearerFormat; | ||
} | ||
|
||
bearerFormat(): string | undefined { | ||
return this._json.bearerFormat; | ||
} | ||
|
||
openIdConnectUrl(): string { | ||
return this._json.openIdConnectUrl; | ||
} | ||
|
||
scheme(): string | undefined { | ||
return this._json.scheme | ||
} | ||
|
||
flows(): OAuthFlowsInterface | undefined { | ||
if(!this._json.flows) return undefined; | ||
return new OAuthFlows(this._json.flows); | ||
} | ||
|
||
scopes(): string[] { | ||
return this._json.scopes; | ||
} | ||
|
||
type(): SecuritySchemaType { | ||
return this._json.type; | ||
} | ||
|
||
in(): string | undefined { | ||
return this._json.in; | ||
} | ||
|
||
} |
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,12 @@ | ||
import { SecuritySchemesInterface } from '../security-schemes'; | ||
import { Collection } from '../collection'; | ||
import { SecuritySchemeInterface } from '../security-scheme'; | ||
|
||
export class SecuritySchemes extends Collection<SecuritySchemeInterface> implements SecuritySchemesInterface { | ||
get(id: string): SecuritySchemeInterface | undefined { | ||
return this.collections.find(securityScheme => securityScheme.id() === id); | ||
} | ||
has(id: string): boolean { | ||
return this.collections.some(securityScheme => securityScheme.id() === id); | ||
} | ||
} |
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
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
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,24 @@ | ||
|
||
import { OAuthFlowInterface } from '../oauth-flow'; | ||
import { BaseModel } from '../base'; | ||
import { Mixin } from '../utils'; | ||
import { ExtensionsMixin } from './mixins/extensions'; | ||
|
||
export class OAuthFlow extends Mixin(BaseModel, ExtensionsMixin) implements OAuthFlowInterface { | ||
authorizationUrl(): string | undefined { | ||
return this._json.authorizationUrl; | ||
} | ||
hasRefreshUrl(): boolean { | ||
return !!this._json.refreshUrl; | ||
} | ||
refreshUrl(): string | undefined { | ||
return this._json.refreshUrl; | ||
} | ||
scopes(): Record<string, string> | undefined { | ||
return this._json.scopes; | ||
} | ||
tokenUrl(): string | undefined { | ||
return this._json.tokenUrl; | ||
} | ||
|
||
} |
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,40 @@ | ||
|
||
import { OAuthFlowsInterface } from '../oauth-flows'; | ||
import { BaseModel } from '../base'; | ||
import { Mixin } from '../utils'; | ||
import { ExtensionsMixin } from './mixins/extensions'; | ||
import { OAuthFlowInterface } from 'models/oauth-flow'; | ||
import { OAuthFlow } from './oauth-flow'; | ||
|
||
export class OAuthFlows extends Mixin(BaseModel, ExtensionsMixin) implements OAuthFlowsInterface { | ||
hasAuthorizationCode(): boolean { | ||
return !!this._json.authorizationCode; | ||
} | ||
authorizationCode(): OAuthFlowInterface | undefined { | ||
if (!this._json.authorizationCode) return undefined; | ||
return new OAuthFlow(this._json.authorizationCode); | ||
} | ||
hasClientCredentials(): boolean { | ||
return !!this._json.clientCredentials; | ||
} | ||
clientCredentials(): OAuthFlowInterface | undefined { | ||
if (!this._json.clientCredentials) return undefined; | ||
return new OAuthFlow(this._json.clientCredentials); | ||
} | ||
hasImplicit(): boolean { | ||
return !!this._json.implicit; | ||
} | ||
implicit(): OAuthFlowInterface | undefined { | ||
if (!this._json.implicit) return undefined; | ||
return new OAuthFlow(this._json.implicit); | ||
} | ||
hasPassword(): boolean { | ||
return !!this._json.password; | ||
} | ||
password(): OAuthFlowInterface | undefined { | ||
if (!this._json.password) return undefined; | ||
return new OAuthFlow(this._json.password); | ||
} | ||
|
||
|
||
} |
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,55 @@ | ||
import { BaseModel, ModelMetadata } from '../base'; | ||
import { Mixin } from '../utils'; | ||
import { DescriptionMixin } from './mixins/description'; | ||
import { ExtensionsMixin } from './mixins/extensions'; | ||
import { SecuritySchemaType, SecuritySchemeInterface } from '../security-scheme'; | ||
import { OAuthFlowsInterface } from 'models/oauth-flows'; | ||
import { OAuthFlows } from './oauth-flows'; | ||
|
||
export class SecurityScheme extends Mixin(BaseModel, DescriptionMixin, ExtensionsMixin) implements SecuritySchemeInterface { | ||
constructor( | ||
private readonly _id: string, | ||
_json: Record<string, any>, | ||
_meta: ModelMetadata = {} as any | ||
) { | ||
super(_json, _meta); | ||
} | ||
|
||
id(): string { | ||
return this._id; | ||
} | ||
|
||
hasBearerFormat(): boolean { | ||
return !!this._json.bearerFormat; | ||
} | ||
|
||
bearerFormat(): string | undefined { | ||
return this._json.bearerFormat; | ||
} | ||
|
||
openIdConnectUrl(): string { | ||
return this._json.openIdConnectUrl; | ||
} | ||
|
||
scheme(): string | undefined { | ||
return this._json.scheme | ||
} | ||
|
||
flows(): OAuthFlowsInterface | undefined { | ||
if(!this._json.flows) return undefined; | ||
return new OAuthFlows(this._json.flows); | ||
} | ||
|
||
scopes(): string[] { | ||
return this._json.scopes; | ||
} | ||
|
||
type(): SecuritySchemaType { | ||
return this._json.type; | ||
} | ||
|
||
in(): string | undefined { | ||
return this._json.in; | ||
} | ||
|
||
} |
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,12 @@ | ||
import { SecuritySchemesInterface } from '../security-schemes'; | ||
import { Collection } from '../collection'; | ||
import { SecuritySchemeInterface } from '../security-scheme'; | ||
|
||
export class SecuritySchemes extends Collection<SecuritySchemeInterface> implements SecuritySchemesInterface { | ||
get(id: string): SecuritySchemeInterface | undefined { | ||
return this.collections.find(securityScheme => securityScheme.id() === id); | ||
} | ||
has(id: string): boolean { | ||
return this.collections.some(securityScheme => securityScheme.id() === id); | ||
} | ||
} |
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
Oops, something went wrong.