-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why not support refs in union mapping? #10
Comments
It's not just that it has to be of the properties form. It also needs to not re-define the discriminator property. And it's valid for a definition to itself be a ref, so you'd have to have the validator recursively follow the refs and then perform the discriminator check. This makes it harder to implement the spec. More significantly, refs in properties form don't work well with code generation. At a high level: you can't just "drop-in" ref'd schemas in a mapping, because mapping schemas implicitly have the discriminator property. For most languages, the natural way to implement a discriminator "mapping" type can't be done independently of the "parent" discriminator. For instance, in Java, the discriminator schema becomes an abstract class, and each mapping is a concrete implementation of that class. Whereas with "normal" properties form schemas, like |
Thank you! Not sure I understand the "recursive validation" part though. For example, in Java when generating a type for union member (inherited from the base union class) one needs to have the properties form to get all its members. Isn't getting this form from inline definition or from the ref is basically the same thing? Refs inside the properties form of a union mapping are allowed, so the recursive expansion of types is already there. To give more details on why not having refs in union mappings could be a problem - for example, what if I want to reference one of the union-member types "inside" another union-member? Something like this: {
"discriminator": "kind",
"mapping": {
"aBigReusableType": {
"properties": {
"a": { "type": "string" },
"b": { "type": "string" },
"andManyMore": { "type": "string" }
}
},
"anotherTypeThatWantsToReferenceBigReusableOne": {
"properties": {
"nestedBigOne": {"ref": "aBigReusableType????howToDoThis????"}
}
}
}
} Since there is no way to use refs in union mapping, I cannot "extract" a "aBigReusableType" type to definitions and then reference it inside of another union type. Could this be handled using interfaces though? E.g. to have |
Hi, @AlexSugak so how did you get around this issue? I don't know Java so I'm not sure I understand why this limitation exists. but I'd still like to know how you got around this. |
Hi @MrBrN197! We worked around this by simplifying the schema a bit and allowing for definitions duplication in few places. Still, it would be nice to have resuable definitions in unions. |
I see. thanks that won't be possible for me. |
Hi!
I get it (I think so) why members of the discriminated union's mapping must be of
propertiesForm
. But why can't it be arefForm
pointing to apropertiesForm
? E.g. something like this is not allowed, while I think it is fine to have such schema:I understand that changing this would require a new RFC but I was just wondering about the reasoning behind such limitation.
The text was updated successfully, but these errors were encountered: