---
cases:
  - note: json_match_schema/success
    modules:
      - |
        package test

        document := {"id": 5}
        schema := {
          "properties": {
            "id": {
              "type": "integer"
            }
          },
          "required": ["id"]
        }
        p := json.match_schema(document, schema)
    query: data.test.p = x
    want_result:
      - x: [true, []]
  - note: json_match_schema/success string document
    modules:
      - |
        package test

        document := `{"id": 5}`
        schema := {
          "properties": {
            "id": {
              "type": "integer"
            }
          },
          "required": ["id"]
        }
        p := json.match_schema(document, schema)
    query: data.test.p = x
    want_result:
      - x: [true, []]
  - note: json_match_schema/success string schema
    modules:
      - |
        package test

        document := {"id": 5}
        schema := `{
          "properties": {
            "id": {
              "type": "integer"
            }
          },
          "required": ["id"]
        }`
        p := json.match_schema(document, schema)
    query: data.test.p = x
    want_result:
      - x: [true, []]
  - note: json_match_schema/invalid document
    modules:
      - |
        package test

        document := {"id": "foo"}
        schema := {
          "properties": {
            "id": {
              "type": "integer"
            }
          },
          "required": ["id"]
        }
        p := json.match_schema(document, schema)
    query: data.test.p = x
    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
    modules:
      - |
        package test

        document := {"id": "foo"}
        schema := {
          "properties": {
            "id": {
              "type": "unknown"
            }
          },
          "required": ["id"]
        }
        p := json.match_schema(document, schema)
    query: data.test.p = x
    strict_error: true
    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]"
    want_error_code: eval_builtin_error
