Skip to content

Commit

Permalink
encoding/jsonschema: add test for date-time format
Browse files Browse the repository at this point in the history
The "date-time" format is supposed to be recognized but is not.
This errant behavior will be fixed in a subequent CL.

This error is only recognized in strict-keyword mode,
which is always enabled when jsonschema is invoked
via OpenAPI, so also make sure that that mode is
enabled when openAPI mode is enabled in the jsonschema
tests, avoiding the need to add an extra `#strictKeywords`
tag to openapi tests in encoding/jsonschema.

For #3454.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I429c4c013481837d4f72d94367329ce010c55604
Dispatch-Trailer: {"type":"trybot","CL":1201351,"patchset":3,"ref":"refs/changes/51/1201351/3","targetBranch":"master"}
  • Loading branch information
rogpeppe authored and cueckoo committed Sep 17, 2024
1 parent ffdf382 commit f161f8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion encoding/jsonschema/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestDecode(t *testing.T) {
// OpenAPI doesn't have a JSON Schema URI so it gets a special case.
cfg.DefaultVersion = jsonschema.VersionOpenAPI
cfg.Root = "#/components/schemas/"
cfg.StrictKeywords = true // OpenAPI always uses strict keywords
cfg.Map = func(p token.Pos, a []string) ([]ast.Label, error) {
// Just for testing: does not validate the path.
return []ast.Label{ast.NewIdent("#" + a[len(a)-1])}, nil
Expand All @@ -90,7 +91,7 @@ func TestDecode(t *testing.T) {
}
}
cfg.Strict = t.HasTag("strict")
cfg.StrictKeywords = t.HasTag("strictKeywords")
cfg.StrictKeywords = cfg.StrictKeywords || t.HasTag("strictKeywords")
cfg.StrictFeatures = t.HasTag("strictFeatures")

ctx := t.CueContext()
Expand Down
13 changes: 13 additions & 0 deletions encoding/jsonschema/testdata/txtar/openapi_date-time.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version: openapi

-- schema.yaml --
components:
schemas:
DateTime:
type: string
format: date-time

-- out/decode/extract --
ERROR:
unknown format "date-time":
schema.yaml:5:9

0 comments on commit f161f8a

Please sign in to comment.