-
Notifications
You must be signed in to change notification settings - Fork 302
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 incorrect oneOf definition when used with required #2686
Comments
This is one of the situations where the current "encoding" of one-ofs fails/is just plain wrong. Whilst #943 will address this with a builtin, we could consider switching our notion of one-of "encoding" to be something like the following:
https://tip.cuelang.org/play/?id=GmmKjdTk_h9#cue@export@json contains a variation of that. |
Yup that would work. The error message would not the best in term of UX, but in term of functionality that would fix the issue. |
Absolutely. A builtin would facilitate a much more precise error message. |
ISTM there are a few of issues going on here. For reference, here's a full testscript example that includes the source OpenAPI spec that wasn't included above:
This currently fails:
Specific issues:
There's another issue: in the above example, additional fields are allowed, but if we explicitly try to disallow them (by specifying
Result:
Even without an explicit new builtin for this purpose, the above should work: it should probably produce something like the following definition for
|
I'm not 100% on the detail but I think this is an artefact of OpenAPI's usage of JSON Schema. I have a vague recollection of @mpvl telling me that this "encoding" within CUE is deliberate, because OpenAPI is intentionally "open". |
FWIW I looked for any indication of this kind of difference and was unable to find one. To the best of my knowledge, OpenAPI's JSON Schema is exactly the same as regular JSON Schema. Here's some evidence of that: https://apisyouwonthate.com/blog/openapi-v3-1-and-json-schema/ |
Very related to this I've just raised #3165 to capture discussion on how oneofs could/should be encoded in CUE. That new issue provides a JSON Schema example, but I don't think the question of how we encode oneofs is specific to JSON Schema necessarily. Protocol Buffers also has the concept - quite how the semantics and implementation lines up I'm not 100% sure. On the basis OpenAPI uses an extended subset of JSON Schema, I'm tempted to close this issue and move discussion of how we should encode oneofs (perhaps generally) into #3165, consolidating this and a number of other issues. Please do say though if I'm holding things wrong and we need to keep this open for OpenAPI-specific reasons. If we do, we need to evolve the conversation in #3165 in any case to make clear how specific encodings might carry with them specific oneof-semantics/details. |
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest stable release?
Yes
What did you do?
What did you expect to see?
or something akin.
What did you see instead?
which fails to vet correct values like
(incomplete)
The text was updated successfully, but these errors were encountered: