-
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): add fixed and mixed fields generic visitors
Closes #91
- Loading branch information
Showing
19 changed files
with
134 additions
and
74 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
58 changes: 4 additions & 54 deletions
58
...pidom-parser-adapter-openapi3-1-json/src/parser/visitors/generics/MapJsonObjectVisitor.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
24 changes: 24 additions & 0 deletions
24
...rser-adapter-openapi3-1-json/src/parser/visitors/generics/MixedFieldsJsonObjectVisitor.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,24 @@ | ||
import stampit from 'stampit'; | ||
|
||
import { BREAK } from '..'; | ||
import FixedFieldsJsonObjectVisitor from './FixedFieldsJsonObjectVisitor'; | ||
import PatternedFieldsJsonObjectVisitor from './PatternedFieldsJsonObjectVisitor'; | ||
|
||
const MixedFieldsJsonObjectVisitor = stampit( | ||
FixedFieldsJsonObjectVisitor, | ||
PatternedFieldsJsonObjectVisitor, | ||
{ | ||
methods: { | ||
object(objectNode) { | ||
// @ts-ignore | ||
FixedFieldsJsonObjectVisitor.compose.methods.object.call(this, objectNode); | ||
// @ts-ignore | ||
PatternedFieldsJsonObjectVisitor.compose.methods.object.call(this, objectNode); | ||
|
||
return BREAK; | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
export default MixedFieldsJsonObjectVisitor; |
64 changes: 64 additions & 0 deletions
64
...-adapter-openapi3-1-json/src/parser/visitors/generics/PatternedFieldsJsonObjectVisitor.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,64 @@ | ||
import stampit from 'stampit'; | ||
import { F as stubFalse } from 'ramda'; | ||
import { noop } from 'ramda-adjunct'; | ||
|
||
import SpecificationVisitor from '../SpecificationVisitor'; | ||
import { isOpenApiExtension } from '../../predicates'; | ||
import { visit, BREAK } from '..'; | ||
|
||
const PatternedFieldsJsonObjectVisitor = stampit(SpecificationVisitor, { | ||
props: { | ||
fieldPatternPredicate: stubFalse, | ||
specPath: noop, | ||
ignoredFields: [], | ||
canSupportSpecificationExtensions: false, | ||
}, | ||
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: { | ||
object(objectNode) { | ||
objectNode.properties.forEach((propertyNode: any) => { | ||
const keyName = propertyNode.key.value; | ||
|
||
if (this.canSupportSpecificationExtensions && isOpenApiExtension({}, propertyNode)) { | ||
const visitor = this.retrieveVisitorInstance(['document', 'extension']); | ||
visit(propertyNode, visitor); | ||
this.element.content.push(visitor.element); | ||
} else if (!this.ignoredFields.includes(keyName) && this.fieldPatternPredicate(keyName)) { | ||
const specPath = this.specPath(propertyNode.value); | ||
const visitor = this.retrieveVisitorInstance(specPath); | ||
const keyElement = new this.namespace.elements.String(keyName); | ||
const { MemberElement } = this.namespace.elements.Element.prototype; | ||
|
||
visit(propertyNode, visitor); | ||
|
||
const memberElement = this.maybeAddSourceMap( | ||
propertyNode, | ||
new MemberElement( | ||
this.maybeAddSourceMap(propertyNode.key, keyElement), | ||
visitor.element, | ||
), | ||
); | ||
|
||
this.element.content.push(memberElement); | ||
} | ||
}); | ||
|
||
this.maybeAddSourceMap(objectNode, this.element); | ||
|
||
return BREAK; | ||
}, | ||
}, | ||
}); | ||
|
||
export default PatternedFieldsJsonObjectVisitor; |
3 changes: 2 additions & 1 deletion
3
.../apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/callback/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
4 changes: 3 additions & 1 deletion
4
...pidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/components/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
3 changes: 2 additions & 1 deletion
3
...s/apidom-parser-adapter-openapi3-1-json/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
3 changes: 2 additions & 1 deletion
3
...-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/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
4 changes: 3 additions & 1 deletion
4
.../packages/apidom-parser-adapter-openapi3-1-json/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
3 changes: 2 additions & 1 deletion
3
...ages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/info/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
3 changes: 2 additions & 1 deletion
3
...s/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/license/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
3 changes: 2 additions & 1 deletion
3
...apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/operation/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
3 changes: 2 additions & 1 deletion
3
...apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/path-item/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
3 changes: 2 additions & 1 deletion
3
...apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/reference/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
3 changes: 2 additions & 1 deletion
3
...dom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/request-body/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
9 changes: 6 additions & 3 deletions
9
...apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/responses/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
3 changes: 2 additions & 1 deletion
3
...-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/server-variable/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
3 changes: 2 additions & 1 deletion
3
...es/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/server/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