anyOf and Capitalized Properties

Questions about XML that are not covered by the other forums should go here.
michaelgrudgings
Posts: 7
Joined: Mon Sep 12, 2022 7:58 pm

anyOf and Capitalized Properties

Post 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"
}
},
Michael J Grudgings
Business Architect
florin_nica
Posts: 32
Joined: Wed Sep 09, 2020 3:17 pm

Re: anyOf and Capitalized Properties

Post 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
michaelgrudgings
Posts: 7
Joined: Mon Sep 12, 2022 7:58 pm

Re: anyOf and Capitalized Properties

Post 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
Last edited by michaelgrudgings on Mon Jan 23, 2023 5:41 pm, edited 1 time in total.
Michael J Grudgings
Business Architect
florin_nica
Posts: 32
Joined: Wed Sep 09, 2020 3:17 pm

Re: anyOf and Capitalized Properties

Post 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
Post Reply