-
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(OpenApi3.1-Yaml): add support for Info, License and Contact
Refs #1
- Loading branch information
Showing
27 changed files
with
350 additions
and
17 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
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
11 changes: 11 additions & 0 deletions
11
apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/metadata.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,11 @@ | ||
import { Element } from 'minim'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const appendMetadata = <T extends Element>(metadata: string[], element: T): T => { | ||
metadata.forEach((md: string) => { | ||
element.classes.push(md); | ||
element.getMetaProperty('symbols', []).push(md); | ||
}); | ||
|
||
return element; | ||
}; |
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
10 changes: 8 additions & 2 deletions
10
apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/DocumentVisitor.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
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
77 changes: 77 additions & 0 deletions
77
...ser-adapter-openapi3-1-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.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,77 @@ | ||
import stampit from 'stampit'; | ||
import { noop } from 'ramda-adjunct'; | ||
import { YamlKeyValuePair, YamlMapping } from 'apidom-ast'; | ||
import SpecificationVisitor from '../SpecificationVisitor'; | ||
import { isOpenApiExtension } from '../../predicates'; | ||
import { visit } from '..'; | ||
|
||
const FixedFieldsYamlMappingVisitor = stampit(SpecificationVisitor, { | ||
props: { | ||
specPath: noop, | ||
ignoredFields: [], | ||
keyMap: { | ||
// @ts-ignore | ||
[YamlMapping.type]: ['children'], | ||
}, | ||
canSupportSpecificationExtensions: true, | ||
}, | ||
init({ | ||
// @ts-ignore | ||
specPath = this.specPath, | ||
// @ts-ignore | ||
ignoredFields = this.ignoredFields, | ||
// @ts-ignore | ||
canSupportSpecificationExtensions = this.canSupportSpecificationExtensions, | ||
} = {}) { | ||
this.specPath = specPath; | ||
this.ignoredFields = ignoredFields; | ||
this.canSupportSpecificationExtensions = canSupportSpecificationExtensions; | ||
}, | ||
methods: { | ||
mapping(mappingNode: YamlMapping) { | ||
this.maybeAddSourceMap(mappingNode, this.element); | ||
}, | ||
|
||
keyValuePair(keyValuePairNode: YamlKeyValuePair) { | ||
const specPath = this.specPath(keyValuePairNode); | ||
const fields = this.retrieveFixedFields(specPath); | ||
const { MemberElement } = this.namespace.elements.Element.prototype; | ||
|
||
const { key: keyNode, value: valueNode } = keyValuePairNode; | ||
const keyName = keyNode.content; | ||
|
||
if (fields.includes(keyName) && !this.ignoredFields.includes(keyName)) { | ||
const visitor = this.retrieveVisitorInstance([...specPath, 'fixedFields', keyName]); | ||
const keyElement = new this.namespace.elements.String(keyName); | ||
|
||
visit(keyValuePairNode.value, visitor); | ||
|
||
const memberElement = this.maybeAddSourceMap( | ||
keyValuePairNode, | ||
new MemberElement(this.maybeAddSourceMap(keyNode, keyElement), visitor.element), | ||
); | ||
memberElement.classes.push('fixedField'); | ||
this.element.content.push(memberElement); | ||
} else if ( | ||
this.canSupportSpecificationExtensions && | ||
isOpenApiExtension({}, keyValuePairNode) | ||
) { | ||
const visitor = this.retrieveVisitorInstance(['document', 'extension']); | ||
visit(keyValuePairNode, visitor); | ||
this.element.content.push(visitor.element); | ||
} else if (!this.ignoredFields.includes(keyName)) { | ||
const keyElement = new this.namespace.elements.String(keyName); | ||
const memberElement = this.maybeAddSourceMap( | ||
keyValuePairNode, | ||
new MemberElement( | ||
this.maybeAddSourceMap(keyNode, keyElement), | ||
this.nodeToElement(['kind'], valueNode), | ||
), | ||
); | ||
this.element.content.push(memberElement); | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
export default FixedFieldsYamlMappingVisitor; |
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
.../apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/OpenapiVisitor.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 { YamlScalar } from 'apidom-ast'; | ||
|
||
import { BREAK } from '..'; | ||
import SpecificationVisitor from '../SpecificationVisitor'; | ||
import { KindVisitor } from '../generics'; | ||
|
||
const OpenapiVisitor = stampit(KindVisitor, SpecificationVisitor, { | ||
methods: { | ||
scalar(scalarNode: YamlScalar) { | ||
const openapiElement = new this.namespace.elements.Openapi(scalarNode.content); | ||
this.element = this.maybeAddSourceMap(scalarNode, openapiElement); | ||
return BREAK; | ||
}, | ||
}, | ||
}); | ||
|
||
export default OpenapiVisitor; |
6 changes: 6 additions & 0 deletions
6
...m-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/EmailVisitor.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,6 @@ | ||
import stampit from 'stampit'; | ||
import { KindVisitor } from '../../generics'; | ||
|
||
const EmailVisitor = stampit(KindVisitor); | ||
|
||
export default EmailVisitor; |
7 changes: 7 additions & 0 deletions
7
...om-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/NameVisitor.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,7 @@ | ||
import stampit from 'stampit'; | ||
|
||
import { KindVisitor } from '../../generics'; | ||
|
||
const NameVisitor = stampit(KindVisitor); | ||
|
||
export default NameVisitor; |
7 changes: 7 additions & 0 deletions
7
...dom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/UrlVisitor.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,7 @@ | ||
import stampit from 'stampit'; | ||
|
||
import { KindVisitor } from '../../generics'; | ||
|
||
const UrlVisitor = stampit(KindVisitor); | ||
|
||
export default UrlVisitor; |
16 changes: 16 additions & 0 deletions
16
...s/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/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,16 @@ | ||
import stampit from 'stampit'; | ||
import { always } from 'ramda'; | ||
|
||
import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; | ||
import { KindVisitor } from '../../generics'; | ||
|
||
const ContactVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { | ||
props: { | ||
specPath: always(['document', 'objects', 'Contact']), | ||
}, | ||
init() { | ||
this.element = new this.namespace.elements.Contact(); | ||
}, | ||
}); | ||
|
||
export default ContactVisitor; |
16 changes: 16 additions & 0 deletions
16
.../packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/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,16 @@ | ||
import stampit from 'stampit'; | ||
import { always } from 'ramda'; | ||
|
||
import { KindVisitor } from '../generics'; | ||
import FixedFieldsYamlMappingVisitor from '../generics/FixedFieldsYamlMappingVisitor'; | ||
|
||
const OpenApi3_1Visitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { | ||
props: { | ||
specPath: always(['document', 'objects', 'OpenApi']), | ||
}, | ||
init() { | ||
this.element = new this.namespace.elements.OpenApi3_1(); | ||
}, | ||
}); | ||
|
||
export default OpenApi3_1Visitor; |
7 changes: 7 additions & 0 deletions
7
...arser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/DescriptionVisitor.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,7 @@ | ||
import stampit from 'stampit'; | ||
|
||
import { KindVisitor } from '../../generics'; | ||
|
||
const DescriptionVisitor = stampit(KindVisitor); | ||
|
||
export default DescriptionVisitor; |
7 changes: 7 additions & 0 deletions
7
...om-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/SummaryVisitor.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,7 @@ | ||
import stampit from 'stampit'; | ||
|
||
import { KindVisitor } from '../../generics'; | ||
|
||
const SummaryVisitor = stampit(KindVisitor); | ||
|
||
export default SummaryVisitor; |
Oops, something went wrong.