-
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 Responses and Response
Refs #1
- Loading branch information
Showing
9 changed files
with
141 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
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
43 changes: 43 additions & 0 deletions
43
...ser-adapter-openapi3-1-yaml/src/parser/visitors/generics/MixedFieldsYamlMappingVisitor.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,43 @@ | ||
import stampit from 'stampit'; | ||
import { noop } from 'ramda-adjunct'; | ||
import { YamlMapping } from 'apidom-ast'; | ||
|
||
import { BREAK, visit } from '..'; | ||
import FixedFieldsYamlMappingVisitor from './FixedFieldsYamlMappingVisitor'; | ||
import PatternedFieldsYamlMappingVisitor from './PatternedFieldsYamlMappingVisitor'; | ||
import SpecificationVisitor from '../SpecificationVisitor'; | ||
|
||
const MixedFieldsYamlMappingVisitor = stampit(SpecificationVisitor, { | ||
props: { | ||
specPathFixedFields: noop, | ||
specPathPatternedFields: noop, | ||
}, | ||
methods: { | ||
mapping(mappingNode: YamlMapping) { | ||
const fixedFieldsVisitor = FixedFieldsYamlMappingVisitor({ | ||
...this.retrievePassingOptions(), | ||
ignoredFields: this.ignoredFields, | ||
canSupportSpecificationExtensions: this.canSupportSpecificationExtensions, | ||
element: this.element, | ||
specPath: this.specPathFixedFields, | ||
}); | ||
|
||
visit(mappingNode, fixedFieldsVisitor); | ||
|
||
const patternedFieldsVisitor = PatternedFieldsYamlMappingVisitor({ | ||
...this.retrievePassingOptions(), | ||
ignoredFields: this.ignoredFields, | ||
canSupportSpecificationExtensions: this.canSupportSpecificationExtensions, | ||
element: this.element, | ||
fieldPatternPredicate: this.fieldPatternPredicate, | ||
specPath: this.specPathPatternedFields, | ||
}); | ||
|
||
visit(mappingNode, patternedFieldsVisitor); | ||
|
||
return BREAK; | ||
}, | ||
}, | ||
}); | ||
|
||
export default MixedFieldsYamlMappingVisitor; |
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
16 changes: 16 additions & 0 deletions
16
.../apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/response/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 ResponseVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { | ||
props: { | ||
specPath: always(['document', 'objects', 'Response']), | ||
}, | ||
init() { | ||
this.element = new this.namespace.elements.Response(); | ||
}, | ||
}); | ||
|
||
export default ResponseVisitor; |
17 changes: 17 additions & 0 deletions
17
...rser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/responses/DefaultVisitor.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,17 @@ | ||
import stampit from 'stampit'; | ||
import { T as stubTrue } from 'ramda'; | ||
|
||
import { isReferenceObject, isResponseObject } from '../../../predicates'; | ||
import AlternatingVisitor from '../../generics/AlternatingVisitor'; | ||
|
||
const DefaultVisitor = stampit(AlternatingVisitor, { | ||
props: { | ||
alternator: [ | ||
{ predicate: isReferenceObject({}), specPath: ['document', 'objects', 'Reference'] }, | ||
{ predicate: isResponseObject({}), specPath: ['document', 'objects', 'Response'] }, | ||
{ predicate: stubTrue, specPath: ['kind'] }, | ||
], | ||
}, | ||
}); | ||
|
||
export default DefaultVisitor; |
28 changes: 28 additions & 0 deletions
28
...apidom-parser-adapter-openapi3-1-yaml/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import stampit from 'stampit'; | ||
import { test, always } from 'ramda'; | ||
|
||
import { isReferenceObject, isResponseObject } from '../../../predicates'; | ||
import MixedFieldsYamlMappingVisitor from '../../generics/MixedFieldsYamlMappingVisitor'; | ||
import { KindVisitor } from '../../generics'; | ||
|
||
const ResponsesVisitor = stampit(KindVisitor, MixedFieldsYamlMappingVisitor, { | ||
props: { | ||
specPathFixedFields: always(['document', 'objects', 'Responses']), | ||
specPathPatternedFields: (node: unknown) => { | ||
/* eslint-disable no-nested-ternary */ | ||
return isReferenceObject({}, node) | ||
? ['document', 'objects', 'Reference'] | ||
: isResponseObject({}, node) | ||
? ['document', 'objects', 'Response'] | ||
: ['kind']; | ||
/* eslint-enable */ | ||
}, | ||
fieldPatternPredicate: test(/^\d{3}$/), | ||
canSupportSpecificationExtensions: true, | ||
}, | ||
init() { | ||
this.element = new this.namespace.elements.Responses(); | ||
}, | ||
}); | ||
|
||
export default ResponsesVisitor; |