Closed ramuklawjju closed 4 months ago
Can you be more specific? What would propertyType
look like? What problem are you trying to solve?
Hello,
We have the same need of using boolean as discriminator. We could change our datastructure to use a string-value instead, but bool would be the most correct fit for our case and we do not want to change our ideal datastructure because of a missing feature in OAS. Until this is possible we will just have to drop using discriminators and tackle the cases discriminators could help us with in code, but it would be great to use OAS for this in the future.
Here is a simplified example of our case:
NewJob:
oneOf:
- $ref: '#/components/schemas/Job'
- $ref: '#/components/schemas/UnmanagedJob'
discriminator:
propertyName: managed
mapping:
true: '#/components/schemas/Job'
false: '#/components/schemas/UnmanagedJob'
{
"managed": true
}
Bad Request: 'managed' should be equal to one of the allowed values: true, false.\n at RequestValidator.discriminatorValidator
NewJob:
oneOf:
- $ref: '#/components/schemas/Job'
- $ref: '#/components/schemas/UnmanagedJob'
discriminator:
propertyName: managed
propertyType: boolean # Could be string, number or boolean. default string
mapping:
true: '#/components/schemas/Job'
false: '#/components/schemas/UnmanagedJob'
mapping:
true: '#/components/schemas/Job'
false: '#/components/schemas/UnmanagedJob'
This part isn't really possible because you can't represent booleans as object properties using the JSON document model -- property names can ONLY be strings.
This part isn't really possible because you can't represent booleans as object properties using the JSON document model -- property names can ONLY be strings.
That's why a feature like propertyType
can help. It gives information about the type of the keys.
+1 for this feature!
I would rather go away of this and push any schema related feature to json schema rather than continue in forking json schema behaviour
then not sure you may be able to play with if then else https://json-schema.org/learn/miscellaneous-examples#conditional-validation-with-if-else
I'm going to close this as Moved to Moonwalk, specifically to:
because this would require a breaking change and generally more than we can do in 3.x. Please feel free to copy any salient points over to that discussion!
For discriminators, there should be a feature like propertyType which will enable us to control discriminators in a better way.