encoding/openapi: more accurate handling of disjunctions
Instead of assumingt that the input is from Protobuf,
now actually compute the logic for the "not(anyOf(...))"
elements.
Basically, each element in a disjunction subsumed by
the other elements. All instances of an element need
to be excluded by a "not(anyOf(...))" pattern. For
Protobuf, this means there is exactly one for each
oneOf.
This chance is also no longer preexpands values based
on the node count heuristic. This generally gives
better and more consistent output for Protobuf.
An additional optimization based on unification
eliminates impossible disjuncts to compensate for the
fact that this simplifcation is no longer done by
CUE itself.
Change-Id: I665f529cee24ad084eb0a6d83a373b2392f67e3e
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5344
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/openapi/testdata/oneof.cue b/encoding/openapi/testdata/oneof.cue
index a7aad07..6fa37d4 100644
--- a/encoding/openapi/testdata/oneof.cue
+++ b/encoding/openapi/testdata/oneof.cue
@@ -1,13 +1,57 @@
-MyString :: {} | {
+T :: {
+ shared: int
+}
+T :: {} | {
exact: string
} | {
regex: string
}
+T :: {} | {
+ count: int
+} | {
+ amount: int
+}
+T :: {
+ shared2: int
+}
MyInt :: int
Foo: {
- include: MyString
- exclude: [...MyString]
+ include: T
+ exclude: [...T]
count: MyInt
}
+
+Incompatible :: {
+ shared: int
+} | {
+ shared: int
+ extra1: int
+} | {
+ shared: int
+ extra2: int
+}
+
+WithMap :: {
+ shared: [string]: int
+} | {
+ shared: [string]: int
+ extra: int
+} | {
+ shared: string // incompatible
+ extra: int
+}
+
+Embed :: {
+ a?: int
+
+ close({}) |
+ close({b: int}) |
+ close({c: int})
+
+ // TODO: maybe support builtin to write this as
+ // oneof({},
+ // {b: int},
+ // {c: int})
+}