Open solonovamax opened 1 day ago
can you share some real life use cases where this feature would be needed?
can you share some real life use cases where this feature would be needed?
I'm trying to make a schema that matches a fabric.mod.json
file.
A couple of examples from it:
mixins
field which is an array of elements that are either String
s or an object with a config
key and an optional environment
key, the string being equivalent to just specifying the config
.license
field which is either an array String
s or a String
. the string being equivalent to specifying a single element array.icon
field which is either a String
or an object of String
-> String
. for the first case, the icon is used at all resolutions, in the second case the resolution of the icon is specified in the key.authors
/contributors
field which is an array of either String
s or an object with a name
key and an optional contact
key, the string being equivalent to just specifying the name
entrypoints
field which is an object of String
-> array of String
or an object with a value
and an optional adapter
key, the string being equivalent to just specifying the value
.I don't have any control over this schema, and am just generating some json according to this schema and want to validate it.
My serialization code can be found here if that would help: SerialFabricModJson.kt. This should be able to parse all valid fabric.mod.json
files and fail on any invalid one.
Also, I sent a message in the kotlinlang's kotest slack channel, if you'd like to discuss this further there in a platform more suitable for Q&A
Basically just JSON Schema's
anyOf
and/oroneOf
This feature is similar, although not identical, to #2980. (in certain cases #2980 is a replacement for this, although it does not fit all cases)
an example syntax would look like this:
in order to do this, it would either be necessary to add an additional
JsonSchemaElement
called something likeJsonCompositeElement
, which composes multiple elements (imo the less desirable choice) or to change theJsonSchema.JsonObjectBuilder.properties
field from aMutableMap<String, JsonSchemaElement>
to aMutableMap<String, Matcher<JsonSchemaElement>>
(imo the better choice)