-
Notifications
You must be signed in to change notification settings - Fork 170
openapi: ExpandReferences causes malformed "oneOf" result #504
Comments
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% compatible with json-schema, since there is no Cue json-schema encoder yet... |
Closing this as it appears it's not a bug. Will update a workaround if we find one. |
@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. |
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 |
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 `oneOf`... But are you sure that explains this particular output?
In both json-schema and openapi, `oneOf` means “one of the schemas in this array must match”. So for example this cue input:
`{a: string} | {b: string}`
should produce this output:
`{“oneOf”: [{“properties”: {“a”: {“type”: “string”}}}, {“properties”: {“b”: {“type”: “string”}}}]}
And indeed that is the output with `ExpandReferences:true`.
But try the same input with `ExpandReferences:false` and you’ll see a very different output which doesn’t seem to match the input.
Something like this:
```
{
“properties”: {
“a”: {“type”: “string”},
“b”: {“type”: “string”}
},
“oneOf”: [ {
“required”: [“a”]
}, {
“required”: [“b”]
}
}
```
Is this really a correct translation of the cue input above? If so, I don’t understand it.
Thank you for your help!
… On Sep 6, 2020, at 9:21 PM, Johan Euphrosine ***@***.***> wrote:
So this is not a bug after all. However it's a shame that OpenAPI is not 100% compatible with json-schema
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
The OpenAPI Schema Object is a JSON Schema vocabulary which extends JSON Schema Core and Validation vocabularies. As such any keyword available for those vocabularies is by definition available in OpenAPI, and will work the exact same way.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#schema-object
The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is a superset of the JSON Schema Specification Draft 2019-09.
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
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
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! |
This issue has been migrated to cue-lang/cue#504. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
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: