Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(converter): add convenient toolbox utils (#3816)
- Loading branch information
Showing
4 changed files
with
39 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
36 changes: 36 additions & 0 deletions
36
packages/apidom-converter/src/strategies/openapi-3-1-to-openapi-3-0-3/toolbox.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 { Element, Meta, Attributes, AnnotationElement } from '@swagger-api/apidom-core'; | ||
import { createToolbox as createToolboxOpenAPI31 } from '@swagger-api/apidom-ns-openapi-3-1'; | ||
|
||
const createToolbox = () => { | ||
const openAPI31Toolbox = createToolboxOpenAPI31(); | ||
|
||
const copySourceMap = <T extends Element, U extends Element>(from: T, to: U): void => { | ||
if (openAPI31Toolbox.predicates.hasElementSourceMap(from)) { | ||
to.meta.set('sourceMap', from.meta.get('sourceMap')); | ||
} | ||
}; | ||
|
||
const createAnnotation = (content?: string, meta?: Meta, attributes?: Attributes) => { | ||
return new AnnotationElement(content, meta, attributes); | ||
}; | ||
createAnnotation.fromElement = <T extends Element>( | ||
element: T, | ||
content?: string, | ||
meta?: Meta, | ||
attributes?: Attributes, | ||
) => { | ||
const annotation = createAnnotation(content, meta, attributes); | ||
copySourceMap(element, annotation); | ||
return annotation; | ||
}; | ||
|
||
return { | ||
...openAPI31Toolbox, | ||
copySourceMap, | ||
createAnnotation, | ||
}; | ||
}; | ||
|
||
export type Toolbox = ReturnType<typeof createToolbox>; | ||
|
||
export default createToolbox; |
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