-
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 support for additional fields to Operation (#88)
- externalDocs - parameters - requestBody - servers Refs #66
- Loading branch information
Showing
20 changed files
with
248 additions
and
5 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
apidom/packages/apidom-ns-openapi3-1/src/elements/Callback.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,10 @@ | ||
import { Attributes, Meta, ObjectElement } from 'minim'; | ||
|
||
class Callback extends ObjectElement { | ||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'callback'; | ||
} | ||
} | ||
|
||
export default Callback; |
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
apidom/packages/apidom-ns-openapi3-1/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 { Attributes, Meta, ObjectElement, StringElement } from 'minim'; | ||
|
||
class ExternalDocumentation extends ObjectElement { | ||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'externalDocumentation'; | ||
} | ||
|
||
get description(): StringElement { | ||
return this.get('description'); | ||
} | ||
|
||
set description(description: StringElement) { | ||
this.set('description', description); | ||
} | ||
|
||
get url(): StringElement { | ||
return this.get('url'); | ||
} | ||
|
||
set url(url: StringElement) { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { Attributes, BooleanElement, Meta, ObjectElement, StringElement } from 'minim'; | ||
import ParameterElement from './Parameter'; | ||
import ReferenceElement from './Reference'; | ||
import ServerElement from './Server'; | ||
|
||
class Operation extends ObjectElement { | ||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
|
@@ -59,6 +60,14 @@ class Operation extends ObjectElement { | |
this.set('parameters', parameters); | ||
} | ||
|
||
get servers(): ServerElement[] { | ||
return this.get('severs'); | ||
} | ||
|
||
set servers(servers: ServerElement[]) { | ||
this.set('servers', servers); | ||
} | ||
|
||
// TODO([email protected]): need to implement the rest of the fileds | ||
} | ||
|
||
|
10 changes: 10 additions & 0 deletions
10
apidom/packages/apidom-ns-openapi3-1/src/elements/RequestBody.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,10 @@ | ||
import { Attributes, Meta, ObjectElement } from 'minim'; | ||
|
||
class RequestBody extends ObjectElement { | ||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'requestBody'; | ||
} | ||
} | ||
|
||
export default RequestBody; |
10 changes: 10 additions & 0 deletions
10
apidom/packages/apidom-ns-openapi3-1/src/elements/Responses.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,10 @@ | ||
import { Attributes, Meta, ObjectElement } from 'minim'; | ||
|
||
class Responses extends ObjectElement { | ||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'responses'; | ||
} | ||
} | ||
|
||
export default Responses; |
10 changes: 10 additions & 0 deletions
10
apidom/packages/apidom-ns-openapi3-1/src/elements/SecurityRequirement.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,10 @@ | ||
import { Attributes, Meta, ObjectElement } from 'minim'; | ||
|
||
class SecurityRequirement extends ObjectElement { | ||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'securityRequirement'; | ||
} | ||
} | ||
|
||
export default SecurityRequirement; |
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
29 changes: 29 additions & 0 deletions
29
.../apidom-parser-adapter-openapi3-1-json/src/parser/visitors/generics/AlternatingVisitor.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,29 @@ | ||
import stampit from 'stampit'; | ||
import { ifElse, always, Pred } from 'ramda'; | ||
import { dispatch, stubUndefined } from 'ramda-adjunct'; | ||
|
||
import { BREAK } from '..'; | ||
import SpecificationVisitor from '../SpecificationVisitor'; | ||
|
||
const AlternatingVisitor = stampit(SpecificationVisitor, { | ||
props: { | ||
alternator: [], | ||
}, | ||
methods: { | ||
object(jsonObject) { | ||
const functions = this.alternator.map( | ||
({ predicate, specPath }: { predicate: Pred; specPath: string[] }) => | ||
ifElse(predicate, always(specPath), stubUndefined), | ||
); | ||
const specPath = dispatch(functions)(jsonObject); | ||
|
||
this.element = this.nodeToElement(specPath, jsonObject); | ||
|
||
this.maybeAddSourceMap(jsonObject, this.element); | ||
|
||
return BREAK; | ||
}, | ||
}, | ||
}); | ||
|
||
export default AlternatingVisitor; |
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 |
---|---|---|
|
@@ -6,15 +6,17 @@ import { isParameterObject, isReferenceObject } from '../../predicates'; | |
const ParametersVisitor = stampit(SpecificationVisitor, { | ||
init() { | ||
this.element = new this.namespace.elements.Array(); | ||
this.element.classes.push('parameters'); | ||
}, | ||
methods: { | ||
array(arrayNode) { | ||
this.maybeAddSourceMap(arrayNode, this.element); | ||
}, | ||
object(objectNode) { | ||
if (isParameterObject({}, objectNode)) { | ||
// TODO([email protected]): replace with real Parameter Object implementation | ||
this.element.content.push(new this.namespace.elements.Object()); | ||
this.element.content.push(new this.namespace.elements.Parameter()); | ||
} else if (isReferenceObject({}, objectNode)) { | ||
// TODO([email protected]): replace with real Reference Object implementation | ||
this.element.content.push(new this.namespace.elements.Object()); | ||
this.element.content.push(new this.namespace.elements.Reference()); | ||
} | ||
}, | ||
}, | ||
|
6 changes: 6 additions & 0 deletions
6
...api3-1-json/src/parser/visitors/open-api-3-1/external-documentation/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,6 @@ | ||
import stampit from 'stampit'; | ||
import JsonStringVisitor from '../../generics/JsonStringVisitor'; | ||
|
||
const DescriptionVisitor = stampit(JsonStringVisitor); | ||
|
||
export default DescriptionVisitor; |
6 changes: 6 additions & 0 deletions
6
...ter-openapi3-1-json/src/parser/visitors/open-api-3-1/external-documentation/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,6 @@ | ||
import stampit from 'stampit'; | ||
import JsonStringVisitor from '../../generics/JsonStringVisitor'; | ||
|
||
const UrlVisitor = stampit(JsonStringVisitor); | ||
|
||
export default UrlVisitor; |
14 changes: 14 additions & 0 deletions
14
...-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import stampit from 'stampit'; | ||
|
||
import FixedFieldsJsonObjectVisitor from '../../generics/FixedFieldsJsonObjectVisitor'; | ||
|
||
const ExternalDocumentationVisitor = stampit(FixedFieldsJsonObjectVisitor, { | ||
props: { | ||
specPath: ['document', 'objects', 'ExternalDocumentation'], | ||
}, | ||
init() { | ||
this.element = new this.namespace.elements.ExternalDocumentation(); | ||
}, | ||
}); | ||
|
||
export default ExternalDocumentationVisitor; |
15 changes: 15 additions & 0 deletions
15
...-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/operation/RequestBodyVisitor.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,15 @@ | ||
import stampit from 'stampit'; | ||
|
||
import { isRequestBodyObject, isReferenceObject } from '../../../predicates'; | ||
import AlternatingVisitor from '../../generics/AlternatingVisitor'; | ||
|
||
const RequestBodyVisitor = stampit(AlternatingVisitor, { | ||
props: { | ||
alternator: [ | ||
{ predicate: isRequestBodyObject({}), specPath: ['document', 'objects', 'RequestBody'] }, | ||
{ predicate: isReferenceObject({}), specPath: ['document', 'objects', 'Reference'] }, | ||
], | ||
}, | ||
}); | ||
|
||
export default RequestBodyVisitor; |
14 changes: 14 additions & 0 deletions
14
...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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import stampit from 'stampit'; | ||
|
||
import FixedFieldsJsonObjectVisitor from '../../generics/FixedFieldsJsonObjectVisitor'; | ||
|
||
const ReferenceVisitor = stampit(FixedFieldsJsonObjectVisitor, { | ||
props: { | ||
specPath: ['document', 'objects', 'Reference'], | ||
}, | ||
init() { | ||
this.element = new this.namespace.elements.Reference(); | ||
}, | ||
}); | ||
|
||
export default ReferenceVisitor; |
14 changes: 14 additions & 0 deletions
14
...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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import stampit from 'stampit'; | ||
|
||
import FixedFieldsJsonObjectVisitor from '../../generics/FixedFieldsJsonObjectVisitor'; | ||
|
||
const RequestBodyVisitor = stampit(FixedFieldsJsonObjectVisitor, { | ||
props: { | ||
specPath: ['document', 'objects', 'RequestBody'], | ||
}, | ||
init() { | ||
this.element = new this.namespace.elements.RequestBody(); | ||
}, | ||
}); | ||
|
||
export default RequestBodyVisitor; |
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