Skip to content

Commit

Permalink
encoding/openapi: add test cases for non-empty lists
Browse files Browse the repository at this point in the history
An upcoming change to the CUE API to make lists consistent with structs
for concreteness exposed a reliance of encoding/openapi on the current
inconsistency. It also showed that despite there being logic in
encoding/openapi for dealing with non-empty lists, that logic isn't
tested anyway.

Add a couple of test cases so that the behavior change in the upcoming
CL will be clear.

Note that the results here are not actually valid in OpenAPI 3.0, which
does not support the form of `items` generated here (see #3480).

For #3481

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: Ib477e11388715482d48c8101d67a47c8efc69f60
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202243
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
rogpeppe committed Oct 8, 2024
1 parent 4ae206d commit 655236e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions encoding/openapi/testdata/array.cue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import "list"
baz?: list.UniqueItems()

qux?: list.MinItems(1) & list.MaxItems(3)

closedConcreteList?: [1, 2, 3]
openConcreteList?: [1, 2, 3, ...]
}

#Arrays: {
Expand Down
65 changes: 65 additions & 0 deletions encoding/openapi/testdata/array.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,71 @@
"type": "array",
"minItems": 1,
"maxItems": 3
},
"closedConcreteList": {
"type": "array",
"items": [
{
"type": "integer",
"enum": [
1
]
},
{
"type": "integer",
"enum": [
2
]
},
{
"type": "integer",
"enum": [
3
]
}
],
"enum": [
[
1,
2,
3
]
],
"default": [
1,
2,
3
]
},
"openConcreteList": {
"type": "array",
"minItems": 3,
"items": [
{
"type": "integer",
"enum": [
1
]
},
{
"type": "integer",
"enum": [
2
]
},
{
"type": "integer",
"enum": [
3
]
}
],
"default": [
1,
2,
3
],
"additionalItems": {}
}
}
},
Expand Down

0 comments on commit 655236e

Please sign in to comment.