jsonix-schema-compiler
jsonix-schema-compiler copied to clipboard
Why does a simple element in xsd result in an object in the json schema?
Example:
`<xsd:element name="MobileAppVer" nillable="true" minOccurs="0" type="xsd:string"/>`
Gives the following. Why is "type" an object and not just the value type:
`"mobileAppVer":{
"title":"mobileAppVer",
"allOf":[
{
"type":"object",
"properties":{
"name":{
"$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/QName"
},
"value":{
"$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/string"
}
},
"elementName":{
"localPart":"MobileAppVer",
"namespaceURI":""
}
}
],
"propertyType":"elementRef",
"elementName":{
"localPart":"MobileAppVer",
"namespaceURI":""
}
},`
And for an xsd with no target namespace why is the localPart & namespaceURI needed?
Because of the nillable="true". The underlying schema compiler, XJC uses an "element reference" property instead of an "element" property in this case.
You can either remove nillable="true" from the schema or use the jaxb2-simplify-plugin to "simplify" this property as element property. If you need support with this, please commit a (simples possible) test project under https://github.com/highsource/jsonix-support and I'll help you with bindings/configs to make this property simple.
And for an xsd with no target namespace why is the localPart & namespaceURI needed?
Depends what you are referring to. Jsonix Schema Compiler generates Jsonix Mappings and JSON Schema.
JSON Schema is experimental. It contains a few properties which are not standard JSON Schema properties (like elementName). So since it's not standard, not evaluated by the JSON Schema processors anyway and just added for reference/info/debug purposes, I'm just ouputting it as is.
In the Jsonix Mappings you get string if namespace matches the default namespace and an object with local name and namespace URI if it does not match. So if you have such a structure in the Jsonix Mappingsm, check your defaultElementNamespace.
Default element namespace is calculated based on the most popular namespace of your elements.
Thanks - I changed to nillable="false" and now I get:
"isDeleted":{ "title":"isDeleted", "allOf":[ { "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/boolean" } ], "propertyType":"element", "elementName":{ "localPart":"IsDeleted", "namespaceURI":"" } },
This is much closer to what I need. Two issues:
-
The property name has been given a lower-case starting letter. I need the original case preserved and all my properties start with upper-case. Is that something that can be changed or made an option?
-
When the allOf array contains a single item, is it possible to flatten it so type: $ref:... appears instead?
With 1) and 2) fixed the output would be:
"IsDeleted":{ "title":"IsDeleted", "type": { "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/boolean" }, "propertyType":"element", "elementName":{ "localPart":"IsDeleted", "namespaceURI":"" } },
-
Would be nice but is not supported at the moment. I use property names as generated by XJC. File an issue, but I can't promise the implementation too soon.
-
No, you can't combine
$refwith other things, see:
http://stackoverflow.com/questions/29841175/is-it-allowed-to-combine-ref-with-other-keywords-in-json-schema