Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
encoding/openapi: dedup conjuncts and disjuncts
Browse files Browse the repository at this point in the history
Change-Id: I8cb02a2341495c2063bf6796fb61486dd539a881
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9263
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed Apr 2, 2021
1 parent 96e84eb commit a1903ca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions encoding/openapi/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,21 @@ func (b *builder) value(v cue.Value, f typeFunc) (isRef bool) {

func appendSplit(a []cue.Value, splitBy cue.Op, v cue.Value) []cue.Value {
op, args := v.Expr()
// dedup elements.
k := 1
outer:
for i := 1; i < len(args); i++ {
for j := 0; j < k; j++ {
if args[i].Subsume(args[j], cue.Raw()) == nil &&
args[j].Subsume(args[i], cue.Raw()) == nil {
continue outer
}
}
args[k] = args[i]
k++
}
args = args[:k]

if op == cue.NoOp && len(args) == 1 {
// TODO: this is to deal with default value removal. This may change
// whe we completely separate default values from values.
Expand Down
1 change: 1 addition & 0 deletions encoding/openapi/testdata/oneof-resolve.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@
"type": "integer"
},
"T": {
"description": "This should be dedupped.",
"type": "object",
"properties": {
"shared": {
Expand Down
7 changes: 7 additions & 0 deletions encoding/openapi/testdata/oneof.cue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ $version: "v1alpha1"
shared2: int
}

// This should be dedupped.
#T: {} | {
count: int
} | {
amount: int
}

#MyInt: int

#Foo: {
Expand Down
1 change: 1 addition & 0 deletions encoding/openapi/testdata/oneof.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
"type": "integer"
},
"T": {
"description": "This should be dedupped.",
"type": "object",
"properties": {
"shared": {
Expand Down

0 comments on commit a1903ca

Please sign in to comment.