Skip to content

Commit

Permalink
encoding/jsonschema: add test cases for nested values
Browse files Browse the repository at this point in the history
The current `state.value` logic looks wrong: it sets the `allowedTypes`
value recursively when it encounters a structured value such
as an array or an object even though only the top level
of the value should influence the allowed types.

As it happens, the fact that `usedTypes` is set at the same
time hides this error, and it _seems_ that no other
test fails as a result. However, upcoming changes will reveal
this shortcoming, so we add a couple of test cases to
show the fix.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I85173a321d3578094fc96f5b56ed6269c496c18c
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199399
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
rogpeppe committed Aug 13, 2024
1 parent 7ca1a14 commit 0bd8619
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions encoding/jsonschema/testdata/constarray.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- type.json --
{
"type": "array",
"const": [
1
]
}

-- out/decode/cue --
[1]
10 changes: 10 additions & 0 deletions encoding/jsonschema/testdata/constobj.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

-- type.json --
{
"type": "object",
"const": {"a": 1}
}

-- out/decode/cue --
a: 1
...

0 comments on commit 0bd8619

Please sign in to comment.