-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ns-openapi-2): add support for Security Scheme Object (#3227)
Refs #3097
- Loading branch information
Showing
12 changed files
with
291 additions
and
8 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
80 changes: 80 additions & 0 deletions
80
packages/apidom-ns-openapi-2/src/elements/SecurityScheme.ts
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,80 @@ | ||
import { | ||
ObjectElement, | ||
ArrayElement, | ||
StringElement, | ||
Attributes, | ||
Meta, | ||
} from '@swagger-api/apidom-core'; | ||
|
||
class SecurityScheme extends ObjectElement { | ||
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'securityScheme'; | ||
} | ||
|
||
get type(): StringElement | undefined { | ||
return this.get('type'); | ||
} | ||
|
||
set type(type: StringElement | undefined) { | ||
this.set('type', type); | ||
} | ||
|
||
get description(): StringElement | undefined { | ||
return this.get('description'); | ||
} | ||
|
||
set description(description: StringElement | undefined) { | ||
this.set('description', description); | ||
} | ||
|
||
get name(): StringElement | undefined { | ||
return this.get('name'); | ||
} | ||
|
||
set name(name: StringElement | undefined) { | ||
this.set('name', name); | ||
} | ||
|
||
get in(): StringElement | undefined { | ||
return this.get('in'); | ||
} | ||
|
||
set in(inVal: StringElement | undefined) { | ||
this.set('in', inVal); | ||
} | ||
|
||
get flow(): StringElement | undefined { | ||
return this.get('flow'); | ||
} | ||
|
||
set flow(flow: StringElement | undefined) { | ||
this.set('flow', flow); | ||
} | ||
|
||
get authorizationUrl(): StringElement | undefined { | ||
return this.get('authorizationUrl'); | ||
} | ||
|
||
set authorizationUrl(authorizationUrl: StringElement | undefined) { | ||
this.set('authorizationUrl', authorizationUrl); | ||
} | ||
|
||
get tokenUrl(): StringElement | undefined { | ||
return this.get('tokenUrl'); | ||
} | ||
|
||
set tokenUrl(tokenUrl: StringElement | undefined) { | ||
this.set('tokenUrl', tokenUrl); | ||
} | ||
|
||
get scopes(): ArrayElement | undefined { | ||
return this.get('scopes'); | ||
} | ||
|
||
set scopes(scopes: ArrayElement | undefined) { | ||
this.set('scopes', scopes); | ||
} | ||
} | ||
|
||
export default SecurityScheme; |
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
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
18 changes: 18 additions & 0 deletions
18
packages/apidom-ns-openapi-2/src/refractor/visitors/open-api-2/security-scheme/index.ts
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 stampit from 'stampit'; | ||
import { always } from 'ramda'; | ||
|
||
import SecuritySchemeElement from '../../../../elements/SecurityScheme'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; | ||
|
||
const SecuritySchemeVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { | ||
props: { | ||
specPath: always(['document', 'objects', 'SecurityScheme']), | ||
canSupportSpecificationExtensions: true, | ||
}, | ||
init() { | ||
this.element = new SecuritySchemeElement(); | ||
}, | ||
}); | ||
|
||
export default SecuritySchemeVisitor; |
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
35 changes: 35 additions & 0 deletions
35
...es/apidom-ns-openapi-2/test/refractor/elements/SecurityScheme/__snapshots__/index.ts.snap
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,35 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements SecuritySchemeElement should refract to semantic ApiDOM tree 1`] = ` | ||
(SecuritySchemeElement | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(ScopesElement | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement))))) | ||
`; |
45 changes: 45 additions & 0 deletions
45
packages/apidom-ns-openapi-2/test/refractor/elements/SecurityScheme/index.ts
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,45 @@ | ||
import { expect, assert } from 'chai'; | ||
import { sexprs, includesClasses } from '@swagger-api/apidom-core'; | ||
|
||
import { SecuritySchemeElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('SecuritySchemeElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const securitySchemeElement = SecuritySchemeElement.refract({ | ||
type: 'apiKey', | ||
description: 'simple description', | ||
name: 'api_key', | ||
in: 'header', | ||
flow: 'implicit', | ||
authorizationUrl: 'https://swagger.io/api/oauth/dialog', | ||
tokenUrl: 'https://swagger.io/api/oauth/token-url', | ||
scopes: { | ||
'write:pets': 'modify pets in your account', | ||
'read:pets': 'read your pets', | ||
}, | ||
}); | ||
|
||
expect(sexprs(securitySchemeElement)).toMatchSnapshot(); | ||
}); | ||
|
||
specify('should support specification extensions', function () { | ||
const securitySchemeElement = SecuritySchemeElement.refract({ | ||
type: 'apiKey', | ||
'x-extension': 'extension', | ||
}) as SecuritySchemeElement; | ||
|
||
assert.isFalse( | ||
includesClasses(['specification-extension'], securitySchemeElement.getMember('type')), | ||
); | ||
assert.isTrue( | ||
includesClasses( | ||
['specification-extension'], | ||
securitySchemeElement.getMember('x-extension'), | ||
), | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |