This script converts an OData Version 3.0, 4.0, or 4.01 CSDL XML or CSDL JSON ($metadata) document into an OpenAPI 3.0.x JSON document.
It's a pure JavaScript implementation, depending only on odata-csdl, which in turn depends on sax js.
Note: this tool does not support OData 2.0, and it does not produce Swagger 2.0. If you need any of the 2.0 versions, use the XSLT-based tool.
npm install odata-openapiTo install globally type
npm install -g odata-openapiAssuming you installed the script globally, and your XML metadata file is MyMetadata.xml, then
odata-openapi3 MyMetadata.xmlwill create MyMetadata.openapi.json next to it.
Just type
odata-openapi3 -hto get usage hints
Usage: odata-openapi3 <options> <source files>
Options:
--basePath base path (default: /service-root)
-d, --diagram include YUML diagram
-h, --help show this info
--host host (default: localhost)
-p, --pretty pretty-print JSON result
--scheme scheme (default: http)
-t, --target target file (default: source file base name + .openapi3.json)
If you installed the script locally, start it via
node lib/cli.js ...The mapping can be fine-tuned via annotations in the CSDL ($metadata) XML documents.