-
Notifications
You must be signed in to change notification settings - Fork 298
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
openapi: ExpandReferences causes malformed "oneOf" result #504
Comments
Original reply by @shykes in cuelang/cue#504 (comment) After investigating this, it appears that this is a correct implementation of the OpenAPI spec. The confusion is caused by slight incompatibilities between the json-schema spec and the "extended superset of json-schema" which OpenAPI uses. One of the incompatibilities is the From the OpenAPI spec:
Source: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#schema-object So this is not a bug after all. However it's a shame that OpenAPI is not 100%!c(MISSING)ompatible with json-schema, since there is no Cue json-schema encoder yet... |
Original reply by @samalba in cuelang/cue#504 (comment) Closing this as it appears it's not a bug. Will update a workaround if we find one. |
Original reply by @shykes in cuelang/cue#504 (comment) Actually I may have spoken too soon. Even though the OpenAPI spec does alter the meaning of |
Original reply by @mpvl in cuelang/cue#504 (comment) @shykes : I'm curious why you think that both renderings are incorrect. AFAICT they are both correct. The main issue is that for historical reasons ExpandReferences is overloaded to do two things: expand references and rearrange fields in structural form. CRDs (in K8s) puts additional restrictions on OpenAPI, namely that they need to be in structural normal form. This seems to be a good idea in general. The converter uses this form when possible, which happened to coincide with ExternalRefs. But these should probably be two separate options. It is not always possible to generate the structural form, but when it is, it should be equivalent to the more straightforward translation. |
Original reply by @proppy in cuelang/cue#504 (comment)
Note that OpenAPI 3.1 will fix those discrepancies and align OpenAPI schema object with the JSON Schema 2019-09 spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#properties
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#schema-object
This is all thanks to the hard work of @philsturgeon :) You can read more about it on his blog: https://apisyouwonthate.com/blog/openapi-v31-and-json-schema-2019-09 |
Original reply by @shykes in cuelang/cue#504 (comment) Johan, first of all I am very happy to see you involved in Cue! I understand that OpenAPI object schema and json-schema are not exactly the same, and that includes the definition of In both json-schema and openapi,
should produce this output: `{“oneOf”: [{“properties”: {“a”: {“type”: “string”}}}, {“properties”: {“b”: {“type”: “string”}}}]} And indeed that is the output with But try the same input with Something like this:
Is this really a correct translation of the cue input above? If so, I don’t understand it. Thank you for your help!
|
Original reply by @proppy in cuelang/cue#504 (comment)
So am I !
Sorry for the confusion, I was just trying to point out that "not exactly the same" will away with
Yes, this confused me at first too, but according to the spec:
those two schemas (a):
and (b)
would be equivalent. Take the instance:
For (a), it would validate only the first
causing (a) to validate. And for (b), it would validate the
as well as only the first
causing the (b) to also validate. And now take this other instance:
For (a), it would validate both
causing (a) to not validate (per And for (b) it would validate:
But also validate both
causing the (b) to not validate (per So while this does sounds like an semantic abuse (saying either "a" and "b" are defined and required, and saying "a" and "b" are both defined but either one is required do sounds like different things) in practice the way Hope that helps! |
Originally opened by @samalba in cuelang/cue#504
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest release?
I was able to reproduce on the latest commit on master: commit id c6ade67
What did you do?
What did you expect to see?
Same output in both cases.
What did you see instead?
When
ExpandReferences
is true, theoneOf
does not include the properties, they are separated instead.The text was updated successfully, but these errors were encountered: