-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat: add support for discriminator #5012
base: main
Are you sure you want to change the base?
Conversation
SchemaA: { properties: { c: { type: 'string' } } }, | ||
SchemaB: { properties: { c: { type: 'integer' } } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might not fully understand this test, but I think it should be:
SchemaA: { properties: { c: { type: 'string' } } }, | |
SchemaB: { properties: { c: { type: 'integer' } } } | |
SchemaA: { properties: { discriminatingProperty: { type: 'string' }, c: { type: 'string' } } }, | |
SchemaB: { properties: { discriminatingProperty: { type: 'string' }, c: { type: 'integer' } } } |
The discriminator has to be a property of all schemas.
It is important that all the models mentioned below anyOf or oneOf contain the property that the discriminator specifies.
Don't ask me why this redundancy is necessary, IDK 😄
I guess it would also be possible for it to have different types, e.g. a string in SchemaA
and a number in SchemaB
.
Unfortunately, after checking again, the Azure spec seems to simply use this discriminator incorrectly. If you look at it in the swagger editor you can see that it is simply ignored and the type of the messages
array is incorrect 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, they fixed this in the preview 2024-08-01, ... but stopped using the discriminator 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh damn, good catch. I read this multiple times yesterday, but still ignored it ;)
Unfortunately that makes things quite a bit more complicated, but let's see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, it doesn't make it more complicated. types should still work as expected.
Co-authored-by: Deeksha Sinha <[email protected]>
5 cases with Would it be ok to:
With that:
I would expect the version 2024-08-01 should have been released or soon in the future, by checking the name. |
This provides an initial implementation for the discriminating properties of OpenAPI specs: https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/
According to the documentation this can only happen on
oneOf
andanyOf
schemas and there can either be an explicit mapping or it is implicitly derived from the referenced schema names.Of course, the Azure OpenAPI spec does not use
oneOf
buttype: object
.Also, the Azure OpenAPI spec has a circular reference like:
This would result in something like this:
To solve this I added a post parsing sanitization step that checks explicitly for oneOf schemas with discriminator mapping and child schemas with allof mapping for circular refs.
TODO: