---
cases:
  - note: json_match_schema/success
    query: data.test.p = x
    modules:
      - |
        package test

        document := {"id": 5}

        schema := {
        	"properties": {"id": {"type": "integer"}},
        	"required": ["id"],
        }

        p := json.match_schema(document, schema)
    want_result:
      - x:
          - true
          - []
  - note: json_match_schema/success string document
    query: data.test.p = x
    modules:
      - |
        package test

        document := `{"id": 5}`

        schema := {
        	"properties": {"id": {"type": "integer"}},
        	"required": ["id"],
        }

        p := json.match_schema(document, schema)
    want_result:
      - x:
          - true
          - []
  - note: json_match_schema/success string schema
    query: data.test.p = x
    modules:
      - |
        package test

        document := {"id": 5}

        schema := `{
          "properties": {
            "id": {
              "type": "integer"
            }
          },
          "required": ["id"]
        }`

        p := json.match_schema(document, schema)
    want_result:
      - x:
          - true
          - []
  - note: json_match_schema/invalid document
    query: data.test.p = x
    modules:
      - |
        package test

        document := {"id": "foo"}

        schema := {
        	"properties": {"id": {"type": "integer"}},
        	"required": ["id"],
        }

        p := json.match_schema(document, schema)
    want_result:
      - x:
          - false
          - - desc: "Invalid type. Expected: integer, given: string"
              error: "id: Invalid type. Expected: integer, given: string"
              field: id
              type: invalid_type
  - note: json_match_schema/invalid schema
    query: data.test.p = x
    modules:
      - |
        package test

        document := {"id": "foo"}

        schema := {
        	"properties": {"id": {"type": "unknown"}},
        	"required": ["id"],
        }

        p := json.match_schema(document, schema)
    want_error_code: eval_builtin_error
    want_error: "json.match_schema: has a primitive type that is NOT VALID -- given: /unknown/ Expected valid values are:[array boolean integer number null object string]"
    strict_error: true
