Page 1 of 1
anyOf and Capitalized Properties
Posted: Fri Jan 20, 2023 12:26 am
by michaelgrudgings
When we convert an xsd into a draft 2020-12 JSON our lead Object is being wrapped in an anyOf keyword with a capitalized property, even when we deselect the "Preserve xsd Case" option?
This: <xsd:element name="Transmission" type="bem:Transmission"/>
Converts to this:
{
"$schema": "
http://json-schema.org/draft/2020-12/schema",
"title": "xxxxx",
"description": "1.0.2023.01.10.DEV",
"
anyOf": [
{
"type": "object",
"properties": {
"
Transmission": {"$ref": "#/$defs/Transmission"}
}
}
],
And we need this to convert without the anyOf keyword, and with a "properties" in lower case?
{
"$schema": "
http://json-schema.org/draft/2020-12/schema",
"title": "xxxxx",
"description": "2.0.2023.01.11.DEV",
"type": "object",
"properties": {
"
transmission": {"$ref": "#/$defs/Transmission"}
"$ref": "#/$defs/Transmission"
}
},
Re: anyOf and Capitalized Properties
Posted: Fri Jan 20, 2023 1:35 pm
by florin_nica
Hi Michael,
Thank you very much for the feedback.
If you don't select the Preserve case of names from the XSD option, the default JAXB naming algorithm will be applied when converting. For example, "some.nAMe" is changed to "SomeNAMe", and "Some_oth3r_name" is changed to "SomeOth3RName". Unfortunately, there is no other way to control the capitalization of properties. A solution would be to rename the properties of the resulting JSON Schema in Design mode, by using the Rename Component in... action on right-click.
Regarding the usage of "anyOf" keyword, it might actually be redundant if you have a single property in the resulting JSON schema, as it is in your example. On the other hand, it might be absolutely necessary to wrap the properties into "anyOf", if there is more than one. I added an internal issue for further analysis in this regard, because I am not sure how the structure of the JSON schema would be affected by removing this wrapping. Also, I would highly appreciate if you could provide a sample JSON Schema with more properties (converted from XSD), that would fit your needs.
Best regards,
Florin
Re: anyOf and Capitalized Properties
Posted: Mon Jan 23, 2023 5:40 pm
by michaelgrudgings
From what I am reading here these keywords are used to combine multiple schemas, but are optional. We don't have any instances in our schema that require that level of complexity. Therefore the entire schema does not need to be wrapped in anyOf to function in my scenario.
"Essentially each can contain a number of schemas, each schema is validated against the instance value."
"The AllOf, AnyOf, OneOf nodes are all optional, and a schema can contain any combination of them."
https://www.liquid-technologies.com/Ref ... XXXOf.html
Re: anyOf and Capitalized Properties
Posted: Thu Jan 26, 2023 6:31 pm
by florin_nica
Hi Michael,
I have analyzed the reported problem a little more, and it turned out that the "anyOf" wrapping is not necessary in this scenario, as you pointed out. Feel free to download and install the latest version of the XSD to JSON Schema add-on (25.0.1), that no longer makes this wrapping.
Thank you again for the feedback!
Regards,
Florin