exec cue def jsonschema: schema.json -p schema -l '#Person:'
cmp stdout expect-stdout

# With openOnlyWhenExplicit tag
exec cue def jsonschema+openOnlyWhenExplicit: schema.json -p schema -l '#Person:'
cmp stdout expect-openonlywhenexplicit-stdout

# auto mode
exec cue def schema.json -p schema -l '#Person:'
cmp stdout expect-stdout

exec cue def jsonschema: bad.json

# The default strictness modes should apply even when
# we haven't explicitly specifed the jsonschema file type.
! exec cue def jsonschema+strictFeatures: bad.json
cmp stderr expect-stderr-strict-features

exec cue def jsonschema: bad.json

! exec cue def jsonschema+strict: bad.json
cmp stderr expect-stderr-strict

# With only strict features, it should error only for the
# unimplemented feature and not for the unknown keyword.
! exec cue def jsonschema+strictFeatures: bad.json
cmp stderr expect-stderr-strict-features

! exec cue export data.yaml schema.json
cmp stderr expect-stderr2

! exec cue vet data.yaml schema.json
cmp stderr expect-stderr3

-- expect-stdout --
// Person

package schema

import "strings"

#Person: {
	@jsonschema(schema="http://json-schema.org/draft-07/schema#")
	@jsonschema(id="https://example.com/person.schema.json")

	// The person's first name.
	firstName?: string

	// The person's last name.
	lastName?: strings.MinRunes(1)

	// Age in years which must be equal to or greater than zero.
	age?: uint
	...
}
-- expect-openonlywhenexplicit-stdout --
// Person

package schema

import "strings"

#Person: {
	@jsonschema(schema="http://json-schema.org/draft-07/schema#")
	@jsonschema(id="https://example.com/person.schema.json")

	// The person's first name.
	firstName?: string

	// The person's last name.
	lastName?: strings.MinRunes(1)

	// Age in years which must be equal to or greater than zero.
	age?: uint
}
-- schema.json --
{
  "$id": "https://example.com/person.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name.",
      "minLength": 1
    },
    "age": {
      "description": "Age in years which must be equal to or greater than zero.",
      "type": "integer",
      "minimum": 0
    }
  }
}

-- bad.json --
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "number",
  "$dynamicAnchor": "bar",
  "foo": true
}
-- expect-stderr-strict --
keyword "$dynamicAnchor" not yet implemented:
    ./bad.json:4:4
unknown keyword "foo":
    ./bad.json:5:4
-- expect-stderr-strict-features --
keyword "$dynamicAnchor" not yet implemented:
    ./bad.json:4:4
-- data.yaml --
age: twenty

-- expect-stderr2 --
age: conflicting values "twenty" and int (mismatched types string and int):
    ./data.yaml:1:6
    ./schema.json:18:8
-- expect-stderr3 --
age: conflicting values "twenty" and int (mismatched types string and int):
    ./data.yaml:1:6
    ./schema.json:18:8
-- cue.mod/module.cue --
module: "mod.test/config"
language: version: "v0.9.0"
