-
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 PathItem Object (#3307)
Refs #3097
- Loading branch information
Showing
16 changed files
with
410 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { | ||
StringElement, | ||
ObjectElement, | ||
ArrayElement, | ||
Attributes, | ||
Meta, | ||
} from '@swagger-api/apidom-core'; | ||
|
||
import OperationElement from './Operation'; | ||
|
||
class PathItem extends ObjectElement { | ||
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'pathItem'; | ||
} | ||
|
||
get $ref(): StringElement | undefined { | ||
return this.get('$ref'); | ||
} | ||
|
||
set $ref($ref: StringElement | undefined) { | ||
this.set('$ref', $ref); | ||
} | ||
|
||
get GET(): OperationElement { | ||
return this.get('get'); | ||
} | ||
|
||
set GET(operation: OperationElement | undefined) { | ||
this.set('GET', operation); | ||
} | ||
|
||
get PUT(): OperationElement { | ||
return this.get('put'); | ||
} | ||
|
||
set PUT(operation: OperationElement | undefined) { | ||
this.set('PUT', operation); | ||
} | ||
|
||
get POST(): OperationElement { | ||
return this.get('post'); | ||
} | ||
|
||
set POST(operation: OperationElement | undefined) { | ||
this.set('POST', operation); | ||
} | ||
|
||
get DELETE(): OperationElement { | ||
return this.get('delete'); | ||
} | ||
|
||
set DELETE(operation: OperationElement | undefined) { | ||
this.set('DELETE', operation); | ||
} | ||
|
||
get OPTIONS(): OperationElement { | ||
return this.get('options'); | ||
} | ||
|
||
set OPTIONS(operation: OperationElement | undefined) { | ||
this.set('OPTIONS', operation); | ||
} | ||
|
||
get HEAD(): OperationElement { | ||
return this.get('head'); | ||
} | ||
|
||
set HEAD(operation: OperationElement | undefined) { | ||
this.set('HEAD', operation); | ||
} | ||
|
||
get PATCH(): OperationElement { | ||
return this.get('patch'); | ||
} | ||
|
||
set PATCH(operation: OperationElement | undefined) { | ||
this.set('PATCH', operation); | ||
} | ||
|
||
get parameters(): ArrayElement { | ||
return this.get('parameters'); | ||
} | ||
|
||
set parameters(parameters: ArrayElement | undefined) { | ||
this.set('parameters', parameters); | ||
} | ||
} | ||
|
||
export default PathItem; |
13 changes: 13 additions & 0 deletions
13
packages/apidom-ns-openapi-2/src/elements/nces/PathItemParameters.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,13 @@ | ||
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class PathItemParameters extends ArrayElement { | ||
static primaryClass = 'path-item-parameters'; | ||
|
||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.classes.push(PathItemParameters.primaryClass); | ||
this.classes.push('parameters'); | ||
} | ||
} | ||
|
||
export default PathItemParameters; |
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
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
17 changes: 17 additions & 0 deletions
17
packages/apidom-ns-openapi-2/src/refractor/visitors/open-api-2/path-item/$RefVisitor.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 { StringElement, BREAK, cloneDeep } from '@swagger-api/apidom-core'; | ||
|
||
import FallbackVisitor from '../../FallbackVisitor'; | ||
|
||
const $RefVisitor = stampit(FallbackVisitor, { | ||
methods: { | ||
StringElement(stringElement: StringElement) { | ||
this.element = cloneDeep(stringElement); | ||
this.element.classes.push('reference-value'); | ||
|
||
return BREAK; | ||
}, | ||
}, | ||
}); | ||
|
||
export default $RefVisitor; |
36 changes: 36 additions & 0 deletions
36
...ages/apidom-ns-openapi-2/src/refractor/visitors/open-api-2/path-item/ParametersVisitor.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,36 @@ | ||
import stampit from 'stampit'; | ||
import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core'; | ||
|
||
import { isReferenceLikeElement } from '../../../predicates'; | ||
import { isReferenceElement } from '../../../../predicates'; | ||
import PathItemParametersElement from '../../../../elements/nces/PathItemParameters'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
import SpecificationVisitor from '../../SpecificationVisitor'; | ||
|
||
const ParametersVisitor = stampit(SpecificationVisitor, FallbackVisitor, { | ||
init() { | ||
this.element = new PathItemParametersElement(); | ||
}, | ||
methods: { | ||
ArrayElement(arrayElement: ArrayElement) { | ||
arrayElement.forEach((item: Element): void => { | ||
const specPath = isReferenceLikeElement(item) | ||
? ['document', 'objects', 'Reference'] | ||
: ['document', 'objects', 'Parameter']; | ||
const element = this.toRefractedElement(specPath, item); | ||
|
||
if (isReferenceElement(element)) { | ||
element.setMetaProperty('referenced-element', 'parameter'); | ||
} | ||
|
||
this.element.push(element); | ||
}); | ||
|
||
this.copyMetaAndAttributes(arrayElement, this.element); | ||
|
||
return BREAK; | ||
}, | ||
}, | ||
}); | ||
|
||
export default ParametersVisitor; |
48 changes: 48 additions & 0 deletions
48
packages/apidom-ns-openapi-2/src/refractor/visitors/open-api-2/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import stampit from 'stampit'; | ||
import { always } from 'ramda'; | ||
import { | ||
StringElement, | ||
ObjectElement, | ||
isStringElement, | ||
cloneDeep, | ||
toValue, | ||
} from '@swagger-api/apidom-core'; | ||
|
||
import PathItemElement from '../../../../elements/PathItem'; | ||
import OperationElement from '../../../../elements/Operation'; | ||
import { isOperationElement } from '../../../../predicates'; | ||
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
|
||
const PathItemVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { | ||
props: { | ||
specPath: always(['document', 'objects', 'PathItem']), | ||
}, | ||
init() { | ||
this.element = new PathItemElement(); | ||
}, | ||
methods: { | ||
ObjectElement(objectElement: ObjectElement) { | ||
// @ts-ignore | ||
const result = FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); | ||
|
||
// decorate Operation elements with HTTP method | ||
this.element | ||
.filter(isOperationElement) | ||
.forEach((operationElement: OperationElement, httpMethodElementCI: StringElement) => { | ||
const httpMethodElementCS = cloneDeep(httpMethodElementCI); | ||
httpMethodElementCS.content = toValue(httpMethodElementCS).toUpperCase(); | ||
operationElement.setMetaProperty('http-method', httpMethodElementCS); | ||
}); | ||
|
||
// mark this PathItemElement with reference metadata | ||
if (isStringElement(this.element.$ref)) { | ||
this.element.classes.push('reference-element'); | ||
} | ||
|
||
return result; | ||
}, | ||
}, | ||
}); | ||
|
||
export default PathItemVisitor; |
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
Oops, something went wrong.