-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Can optional properties be made required when "allOf" and "discriminator" are used? #1870
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
Comments
I also faced with this question. Could somebody clarify? |
@jeff9finger and @kh0ma , the presence of a It works the same way here. The What You can think of I hope that helps. |
@jeff9finger , BTW, it looks like your example is using OpenAPI v2.0. I'm just highlighting that because discriminators are defined a bit differently in OpenAPI 3.0, to allow for mapping of discriminator values to arbitrary schema names or references. |
@tedepstein Thanks this does explain things. One of my additional questions is around code generation tools. I am assuming the most of the popular code generation tools would generate this correctly. I would assume so, because the " |
@jeff9finger, I think most code generators should get the inheritance hierarchy right, with or without the The OpenAPI specification doesn't put any restrictions on what code generators can or can't do. And it's quite possible that you'll see different code generators handling these things in very different ways. |
That is what I would expect. Thanks |
swagger-api/swagger-editor#1212 seem to imply that the following is legal in Open API v2 and v3.
(This is a little different than the example in the git issue because the one there is not technically correct)
But I am wondering if anyone knows whether adding a discriminator into the mix changes the behavior.
#1428 provides a lot of good information, but does not seem to explain this particular scenario - FooBar declares a property in the "required" list that exists in one of the other objects.
Is the above spec valid? Would it set "optional1" as required in FooBar and not required in Bar?
Thanks for any clarification.
The text was updated successfully, but these errors were encountered: