-
Notifications
You must be signed in to change notification settings - Fork 14
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 Operation Object (#3305)
Refs #3097
- Loading branch information
Showing
24 changed files
with
547 additions
and
1 deletion.
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,103 @@ | ||
import { | ||
ObjectElement, | ||
ArrayElement, | ||
BooleanElement, | ||
StringElement, | ||
Attributes, | ||
Meta, | ||
} from '@swagger-api/apidom-core'; | ||
|
||
import ExternalDocumentationElement from './ExternalDocumentation'; | ||
import ResponsesElement from './Responses'; | ||
|
||
class Operation extends ObjectElement { | ||
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'operation'; | ||
} | ||
|
||
get tags(): ArrayElement | undefined { | ||
return this.get('tags'); | ||
} | ||
|
||
set tags(tags: ArrayElement | undefined) { | ||
this.set('tags', tags); | ||
} | ||
|
||
get summary(): StringElement | undefined { | ||
return this.get('summary'); | ||
} | ||
|
||
set summary(description: StringElement | undefined) { | ||
this.set('summary', description); | ||
} | ||
|
||
get description(): StringElement | undefined { | ||
return this.get('description'); | ||
} | ||
|
||
set description(description: StringElement | undefined) { | ||
this.set('description', description); | ||
} | ||
|
||
set externalDocs(externalDocs: ExternalDocumentationElement | undefined) { | ||
this.set('externalDocs', externalDocs); | ||
} | ||
|
||
get externalDocs(): ExternalDocumentationElement | undefined { | ||
return this.get('externalDocs'); | ||
} | ||
|
||
get operationId(): StringElement | undefined { | ||
return this.get('operationId'); | ||
} | ||
|
||
set operationId(operationId: StringElement | undefined) { | ||
this.set('operationId', operationId); | ||
} | ||
|
||
get parameters(): ArrayElement | undefined { | ||
return this.get('parameters'); | ||
} | ||
|
||
set parameters(parameters: ArrayElement | undefined) { | ||
this.set('parameters', parameters); | ||
} | ||
|
||
get responses(): ResponsesElement | undefined { | ||
return this.get('responses'); | ||
} | ||
|
||
set responses(responses: ResponsesElement | undefined) { | ||
this.set('responses', responses); | ||
} | ||
|
||
get schemes(): ArrayElement | undefined { | ||
return this.get('schemes'); | ||
} | ||
|
||
set schemes(schemes: ArrayElement | undefined) { | ||
this.set('schemes', schemes); | ||
} | ||
|
||
get deprecated(): BooleanElement { | ||
if (this.hasKey('deprecated')) { | ||
return this.get('deprecated'); | ||
} | ||
return new BooleanElement(false); | ||
} | ||
|
||
set deprecated(deprecated: BooleanElement) { | ||
this.set('deprecated', deprecated); | ||
} | ||
|
||
get security(): ArrayElement | undefined { | ||
return this.get('security'); | ||
} | ||
|
||
set security(security: ArrayElement | undefined) { | ||
this.set('security', security); | ||
} | ||
} | ||
|
||
export default Operation; |
12 changes: 12 additions & 0 deletions
12
packages/apidom-ns-openapi-2/src/elements/nces/OperationConsumes.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,12 @@ | ||
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class OperationConsumes extends ArrayElement { | ||
static primaryClass = 'operation-consumes'; | ||
|
||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.classes.push(OperationConsumes.primaryClass); | ||
} | ||
} | ||
|
||
export default OperationConsumes; |
13 changes: 13 additions & 0 deletions
13
packages/apidom-ns-openapi-2/src/elements/nces/OperationParameters.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 OperationParameters extends ArrayElement { | ||
static primaryClass = 'operation-parameters'; | ||
|
||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.classes.push(OperationParameters.primaryClass); | ||
this.classes.push('parameters'); | ||
} | ||
} | ||
|
||
export default OperationParameters; |
12 changes: 12 additions & 0 deletions
12
packages/apidom-ns-openapi-2/src/elements/nces/OperationProduces.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,12 @@ | ||
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class OperationProduces extends ArrayElement { | ||
static primaryClass = 'operation-produces'; | ||
|
||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.classes.push(OperationProduces.primaryClass); | ||
} | ||
} | ||
|
||
export default OperationProduces; |
12 changes: 12 additions & 0 deletions
12
packages/apidom-ns-openapi-2/src/elements/nces/OperationSchemes.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,12 @@ | ||
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class OperationSchemes extends ArrayElement { | ||
static primaryClass = 'operation-schemes'; | ||
|
||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.classes.push(OperationSchemes.primaryClass); | ||
} | ||
} | ||
|
||
export default OperationSchemes; |
13 changes: 13 additions & 0 deletions
13
packages/apidom-ns-openapi-2/src/elements/nces/OperationSecurity.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 OperationSecurity extends ArrayElement { | ||
static primaryClass = 'operation-security'; | ||
|
||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.classes.push(OperationSecurity.primaryClass); | ||
this.classes.push('security'); | ||
} | ||
} | ||
|
||
export default OperationSecurity; |
12 changes: 12 additions & 0 deletions
12
packages/apidom-ns-openapi-2/src/elements/nces/OperationTags.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,12 @@ | ||
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class OperationTags extends ArrayElement { | ||
static primaryClass = 'operation-tags'; | ||
|
||
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.classes.push(OperationTags.primaryClass); | ||
} | ||
} | ||
|
||
export default OperationTags; |
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
20 changes: 20 additions & 0 deletions
20
packages/apidom-ns-openapi-2/src/refractor/visitors/open-api-2/operation/ConsumesVisitor.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,20 @@ | ||
import stampit from 'stampit'; | ||
import { ArrayElement, BREAK, cloneDeep } from '@swagger-api/apidom-core'; | ||
|
||
import OperationConsumesElement from '../../../../elements/nces/OperationConsumes'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
|
||
const ConsumesVisitor = stampit(FallbackVisitor, { | ||
init() { | ||
this.element = new OperationConsumesElement(); | ||
}, | ||
methods: { | ||
ArrayElement(arrayElement: ArrayElement) { | ||
this.element = this.element.concat(cloneDeep(arrayElement)); | ||
|
||
return BREAK; | ||
}, | ||
}, | ||
}); | ||
|
||
export default ConsumesVisitor; |
36 changes: 36 additions & 0 deletions
36
...ages/apidom-ns-openapi-2/src/refractor/visitors/open-api-2/operation/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 OperationParametersElement from '../../../../elements/nces/OperationParameters'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
import SpecificationVisitor from '../../SpecificationVisitor'; | ||
|
||
const ParametersVisitor = stampit(SpecificationVisitor, FallbackVisitor, { | ||
init() { | ||
this.element = new OperationParametersElement(); | ||
}, | ||
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; |
Oops, something went wrong.