Skip to content

Incorrect integer comparison as per JSON Schema spec #864

@TomWright

Description

@TomWright

It seems as though this json schema validator doesn't correctly handle float-like integer values.

See this example test case:

@Test
    fun int1() = runTest {
        val schema = """{
  "title": "foo",
  "type": "object",
  "required": ["x"],
  "properties": {
    "x": {
      "type": "integer"
    }
  }
}"""
        val a = "{\"x\": 1}"
        val b = "{\"x\": 1.0}"

        val ra = validationSchema.validate(schema, a)
        val rb = validationSchema.validate(schema, b)

        println(ra)
        // ValidateResult(messages=[], errors=[])
        println(rb)
        // ValidateResult(messages=[$.x: number found, integer expected], errors=[ValidationError(code=1029, type=null, path=$.x, arguments=[number, integer], message=Invalid value. Must be a integer)])
    }

We have a slight wrapper around networknt but this uses com.networknt.schema.JsonSchema.Set<ValidationMessage> validate(JsonNode node) under the hood.

As per the JSON schema spec, both of these test cases should return zero errors, see https://json-schema.org/understanding-json-schema/reference/numeric.html#id4.

The code above was run using com.networknt:json-schema-validator:1.0.73.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions