-
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.
refactor(converter): allow plugins to perform mutable operations (#3812)
This change will make plugins creation much simpler. ApiDOM is deep cloned before the plugins touch it. That way from outside, the converter still remains immutable, but the plugins work in mutable way.
- Loading branch information
Showing
4 changed files
with
31 additions
and
27 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
5 changes: 5 additions & 0 deletions
5
.../apidom-converter/src/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/.eslintrc
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,5 @@ | ||
{ | ||
"rules": { | ||
"no-param-reassign": 0 | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...onverter/src/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/openapi-version.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
33 changes: 17 additions & 16 deletions
33
...pidom-converter/src/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/webhooks.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 |
---|---|---|
@@ -1,30 +1,31 @@ | ||
import { OpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1'; | ||
import { AnnotationElement, cloneShallow } from '@swagger-api/apidom-core'; | ||
import { AnnotationElement } from '@swagger-api/apidom-core'; | ||
|
||
type WebhooksRefractorPluginOptions = { | ||
annotations: AnnotationElement[]; | ||
}; | ||
|
||
const webhooksRefractorPlugin = | ||
({ annotations }: WebhooksRefractorPluginOptions) => | ||
() => ({ | ||
visitor: { | ||
OpenApi3_1Element(element: OpenApi3_1Element) { | ||
if (!element.hasKey('webhooks')) return undefined; | ||
() => { | ||
const annotation = new AnnotationElement( | ||
'Webhooks are not supported in OpenAPI 3.0.3. They will be removed from the converted document.', | ||
{ classes: ['warning'] }, | ||
{ code: 'webhooks' }, | ||
); | ||
|
||
const copy = cloneShallow(element); | ||
const annotation = new AnnotationElement( | ||
'Webhooks are not supported in OpenAPI 3.0.3. They will be removed from the converted document.', | ||
{ classes: ['warning'] }, | ||
{ code: 'webhooks' }, | ||
); | ||
return { | ||
visitor: { | ||
OpenApi3_1Element(element: OpenApi3_1Element) { | ||
if (!element.hasKey('webhooks')) return undefined; | ||
|
||
annotations.push(annotation); | ||
copy.remove('webhooks'); | ||
annotations.push(annotation); | ||
element.remove('webhooks'); | ||
|
||
return copy; | ||
return undefined; | ||
}, | ||
}, | ||
}, | ||
}); | ||
}; | ||
}; | ||
|
||
export default webhooksRefractorPlugin; |