json-schema-to-openapi-schema | little NodeJS package to convert JSON Schema | REST library
kandi X-RAY | json-schema-to-openapi-schema Summary
kandi X-RAY | json-schema-to-openapi-schema Summary
A little NodeJS package to convert JSON Schema to OpenAPI Schema Objects.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Convert all the dependencies of the definition to their type .
- Change the schema types .
- Rewrites JSON .
- Converts a JSON object into its correct type .
- Convert Swagger schema into JsonSchema .
- Rewrites the min and maximum maximum and maximum values
- Validate a type
- Rewrite the constconst
- Change patternProperties to patternProperties .
- Removes the given key from the schema
json-schema-to-openapi-schema Key Features
json-schema-to-openapi-schema Examples and Code Snippets
Community Discussions
Trending Discussions on json-schema-to-openapi-schema
QUESTION
I have some model definition inside a XSD file and I need to reference these models from an OpenApi definition. Manually remodeling is no option since the file is too large, and I need to put it into a build system, so that if the XSD is changed, I can regenerate the models/schemas for OpenApi.
What I tried and what nearly worked is using xsd2json and then converting it with the node module json-schema-to-openapi. However xsd2json
is dropping some of the complexElement
models. For example "$ref": "#/definitions/tns:ContentNode"
is used inside of one model as the child type but there is no definition for ContentNode
in the schema, where when I look into the XSD, there is a complexElement
definition for ContentNode
.
Another approach which I haven't tried yet but seems a bit excessive to me is using xjb to generate Java models from the XSD and then using JacksonSchema to generate the json schema.
Is there any established library or way, to use XSD in OpenApi?
...ANSWER
Answered 2019-May-07 at 09:03The problem you have is that you are applying inference tooling over a multi-step conversion. As you have found, inference tooling is inherently fussy and will not work in all situations. It's kind of like playing Chinese whispers - every step of the chain is potentially lossy, so what you get out the other end may be garbled.
Based on the alternative approach you suggest, I would suggest a similar solution:
OpenAPI is, rather obviously, an API definition standard. It should be possible for you to take a code first approach, composing your API operations in code and exposing the types generated from XJB. Then you can use Apiee and its annotations to generate the OpenAPI definition. This assumes you are using JAX-RS for your API.
This is still a two-step process, but one with a higher chance of success. The benefit here is that your first step, inferring your XSD types into java types, will hopefully have very little (if any) impact on the code which defines your API operations. Although there will still be a manual step (updating the models) the OpenAPI definition will update automatically once the code has been rebuilt.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install json-schema-to-openapi-schema
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page