Comments (6)
+1 for a first pass implementation to this (have wrapped xsd2json in my own xs:choice implementation, but it'd be good to get one from source). Great work btw - this utility propelled me about 4 weeks forward on some work I'm doing
from xsd2json.
The xs:choice
has not been implemented yet. I am currently thinking about an appropriate JSON Schema translation. It is not trivial :disappointed: Consider the following small XSD snippet:
<xs:sequence>
<xs:element name="owl" type="xs:string" />
<xs:choice>
<xs:element name="cat" type="xs:string" />
<xs:element name="dog" type="xs:string" />
<xs:element name="wolf" type="xs:string" />
</xs:choice>
</xs:sequence>
A possible direct translation would be:
{
"type": "object",
"properties": {
"owl": {
"type": "string"
},
"cat": {
"type": "string"
},
"dog": {
"type": "string"
},
"wolf": {
"type": "string"
}
},
"oneOf": [
{
"required": [ "cat" ]
},
{
"required": [ "dog" ]
},
{
"required": [ "wolf" ]
}
]
}
But what if we change one of the minOccurs
to 0
? This is perfectly valid in XML Schema and in some cases even useful:
<xs:sequence>
<xs:element name="owl" type="xs:string" />
<xs:choice>
<xs:element name="cat" type="xs:string" />
<xs:element name="dog" type="xs:string" minOccurs="0" />
<xs:element name="wolf" type="xs:string" />
</xs:choice>
</xs:sequence>
If we change the JSON Schema accordingly, the following is the result:
{
"type": "object",
"properties": {
"owl": {
"type": "string"
},
"cat": {
"type": "string"
},
"dog": {
"type": "string"
},
"wolf": {
"type": "string"
}
},
"oneOf": [
{
"required": [ "cat" ]
},
{
},
{
"required": [ "wolf" ]
}
]
}
But this is not the same as the given XML Schema! Although the object containing only a owl
property will pass the validation, the following does not:
{
"owl": "a",
"cat": "b",
}
The same applies for modelling the oneOf
with sub-schemas of the form { "properties": { "cat": {} } }
instead of { "required": [ "cat" ] }
, since the empty schema matches all objects and we can not use "additionalProperties": false
in the sub-schemas.
So we have to first think of an appropriate representation of these XML Schemas.
from xsd2json.
Following my understanding of XML schema, putting minOccurs="0" within a "choice " is an (legal) over-definition since each choice item has an implicit minOccurs="0" allowing it not to be chosen.
My answer for this case would be to support the "choice" element, which is a basic feature of XSD but ignoring minOccurs="0" in this context.
from xsd2json.
@fnogatz is there an update on this issue? would appreciate a basic implementation with the first suggestion above.
from xsd2json.
have wrapped xsd2json in my own xs:choice implementation
Is this anywhere available? It might be a good inspiration for native xsd2json support.
from xsd2json.
<xs:sequence>
<xs:element name="owl" type="xs:string" />
<xs:choice>
<xs:element name="cat" type="xs:string" />
<xs:element name="dog" type="xs:string" minOccurs="0" />
<xs:element name="wolf" type="xs:string" />
</xs:choice>
</xs:sequence>
could be translated to:
type: object
properties:
owl:
type: string
required: [owl]
oneOf:
- properties:
cat:
type: string
required: [cat]
- properties:
dog:
type: string
- properties:
wolf:
type: string
required: [wolf]
from xsd2json.
Related Issues (20)
- An in-range update of commander is breaking the build 🚨 HOT 2
- stack_limit HOT 5
- An in-range update of tap is breaking the build 🚨 HOT 2
- "Please run npm first" as CLI output HOT 3
- An in-range update of tap is breaking the build 🚨 HOT 2
- Size of file being used HOT 2
- Error: spawn swipl ENOENT HOT 2
- An in-range update of standard is breaking the build 🚨 HOT 2
- ERROR: -g user:main: Syntax error: Operator expected HOT 7
- xsd2json produces empty output or hangs HOT 5
- Error Running xsd2json - SyntaxError: missing ) after argument list HOT 1
- Migrate to latest draft of JSON Schema
- Error when attempting to use xsd2json HOT 3
- Version 10 of node.js has been released HOT 1
- Only got empty object result HOT 2
- Unable to use either the cli or programatically on MacOS HOT 3
- Referenced xsd files to be on corresponding jsonschema files
- ddex standard convertion not working HOT 1
- An in-range update of tap is breaking the build 🚨 HOT 2
- An in-range update of ajv is breaking the build 🚨 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xsd2json.