-
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 External Documentation Object (#3235
) Refs #3097
- Loading branch information
Showing
12 changed files
with
187 additions
and
1 deletion.
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
26 changes: 26 additions & 0 deletions
26
packages/apidom-ns-openapi-2/src/elements/ExternalDocumentation.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,26 @@ | ||
import { StringElement, ObjectElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class ExternalDocumentation extends ObjectElement { | ||
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'externalDocumentation'; | ||
} | ||
|
||
get description(): StringElement | undefined { | ||
return this.get('description'); | ||
} | ||
|
||
set description(description: StringElement | undefined) { | ||
this.set('description', description); | ||
} | ||
|
||
get url(): StringElement | undefined { | ||
return this.get('url'); | ||
} | ||
|
||
set url(url: StringElement | undefined) { | ||
this.set('url', url); | ||
} | ||
} | ||
|
||
export default ExternalDocumentation; |
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
...ges/apidom-ns-openapi-2/src/refractor/visitors/open-api-2/external-documentation/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 ExternalDocumentationElement from '../../../../elements/ExternalDocumentation'; | ||
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
|
||
const ExternalDocumentationVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { | ||
props: { | ||
specPath: always(['document', 'objects', 'ExternalDocumentation']), | ||
canSupportSpecificationExtensions: true, | ||
}, | ||
init() { | ||
this.element = new ExternalDocumentationElement(); | ||
}, | ||
}); | ||
|
||
export default ExternalDocumentationVisitor; |
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
11 changes: 11 additions & 0 deletions
11
...om-ns-openapi-2/test/refractor/elements/ExternalDocumentation/__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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements ExternalDocumentationElement should refract to semantic ApiDOM tree 1`] = ` | ||
(ExternalDocumentationElement | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement))) | ||
`; |
39 changes: 39 additions & 0 deletions
39
packages/apidom-ns-openapi-2/test/refractor/elements/ExternalDocumentation/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,39 @@ | ||
import { expect, assert } from 'chai'; | ||
import { sexprs, includesClasses } from '@swagger-api/apidom-core'; | ||
|
||
import { ExternalDocumentationElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('ExternalDocumentationElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const externalDocumentationElement = ExternalDocumentationElement.refract({ | ||
description: 'Find more info here', | ||
url: 'https://swagger.io', | ||
}); | ||
|
||
expect(sexprs(externalDocumentationElement)).toMatchSnapshot(); | ||
}); | ||
|
||
specify('should support specification extensions', function () { | ||
const externalDocumentationElement = ExternalDocumentationElement.refract({ | ||
description: 'Find more info here', | ||
'x-extension': 'extension', | ||
}) as ExternalDocumentationElement; | ||
|
||
assert.isFalse( | ||
includesClasses( | ||
['specification-extension'], | ||
externalDocumentationElement.getMember('description'), | ||
), | ||
); | ||
assert.isTrue( | ||
includesClasses( | ||
['specification-extension'], | ||
externalDocumentationElement.getMember('x-extension'), | ||
), | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |