JSON Schema Wrapping enums in allOF keyword.

This should cover W3C XML Schema, Relax NG and DTD related problems.
michaelgrudgings
Posts: 7
Joined: Mon Sep 12, 2022 7:58 pm

JSON Schema Wrapping enums in allOF keyword.

Post by michaelgrudgings »

Why does Oxygen XML wrap all my enums in an allOf keyword? It is causing issues when we exchange data on a transactional level?
The thing that’s different in the json schema is that every enum is wrapped in an “allOf”, like this:

TransmissionType:
allOf:
- type: string
- enum:
- ActivesOnly
- ChangesOnly
- FullFile

So when we generate our classes using the standard openAPI library, it gives us some odd output.

From what I understand in openAPI 3.x “oneOf”, “anyOf”, “allOf” provide ways of expressing complex schemas in which you can specify that one, any, or all of a list of types (sub schemas) can be included at some specific point (https://swagger.io/docs/specification/d ... allof-not/). I can’t find any examples in which these are wrapped around a single enum, though. Enums are typically expressed as (https://swagger.io/docs/specification/d ... els/enums/):

Example:
"EmploymentIncome": {
"type": "object",
"properties": {
"IncomeTypeCode": {"$ref": "#/components/schemas/IncomeType"},
"IncomeAmount": {"type": "number"},
"IncomeModeCode": {
"allOf": [
{"type": "string"},
{
"enum": [
"Hourly",
"Annual",
"Monthly12PerYear",
"BiWeekly26PerYear",
"SemiMonthly24PerYear",
"SemiMonthly21PerYear",
"Weekly52PerYear",
"Weekly48PerYear",
"Quarterly",
"SemiAnnual",
"9thly",
"10thly"
]
}
]
},
"IncomeEffectiveDate": {
"type": "string",
"format": "date"
}
}
},
Michael J Grudgings
Business Architect
florin_nica
Posts: 32
Joined: Wed Sep 09, 2020 3:17 pm

Re: JSON Schema Wrapping enums in allOF keyword.

Post by florin_nica »

Hi Michael,

Thank you very much for the feedback.

Indeed, wrapping enums into "allOf" seems kind of redundant, so I adjusted the XSD to JSON Schema converter tool a little. Your example
would now look like this:

Code: Select all

"IncomeModeCode": {
	"type": "string",
	"enum": [
		"Hourly",
		"Annual",
        ...
        ]
}
This improvement will be available starting with version 24.1.1 of the XSD to JSON Schema add-on. It's release is scheduled for next month,
and you will get a notification.

Regards,
Florin
florin_nica
Posts: 32
Joined: Wed Sep 09, 2020 3:17 pm

Re: JSON Schema Wrapping enums in allOF keyword.

Post by florin_nica »

Hi Michael,

Just wanted to let you know that version 25 of Oxygen XML Editor has just been released, as well as version 24.1.1 of XSD to JSON Schema add-on. This includes the improvement that you requested.

Best regards,
Florin
Post Reply