Skip to content

json-schema: Generated schema for Range numeric type breaks Draft 4 #6041

Closed
@en-sllupa

Description

@en-sllupa

API Platform version(s) affected: 3.2.7

Description
Generated JSON Schema for Range numbers changed from 3.2.6 to 3.2.7. The array copy previously was:

"position" => ArrayObject {#24994
    storage: array:4 [
    "minimum" => 0
    "exclusiveMinimum" => true
    "externalDocs" => array:1 [
        "url" => "https://schema.org/position"
    ]
    "type" => "integer"
    ]
    flag::STD_PROP_LIST: false
    flag::ARRAY_AS_PROPS: false
    iteratorClass: "ArrayIterator"
}

In 3.2.7 it is now:

"position" => ArrayObject {#5413
    storage: array:3 [
        "exclusiveMinimum" => 0
        "externalDocs" => array:1 [
            "url" => "https://schema.org/position"
        ]
        "type" => "integer"
    ]
    flag::STD_PROP_LIST: false
    flag::ARRAY_AS_PROPS: false
    iteratorClass: "ArrayIterator"
}

They are both right in their own way. Because in JSON-Schema docs under range you can read:

While you can specify both of minimum and exclusiveMinimum or both of maximum and exclusiveMaximum, it doesn't really make sense to do so.

There is also a Draft 4 specific interpretation:

In JSON Schema Draft 4, exclusiveMinimum and exclusiveMaximum work differently. There they are boolean values, that indicate whether minimum and maximum are exclusive of the value. For example:

if exclusiveMinimum is false, x ≥ minimum
if exclusiveMinimum is true, x > minimum.

This was changed to have better keyword independence.

The json-schema validator library used in API Platform only supports Draft 4, so any Range property now breaks schema assertions.

I am not sure if the team considers this a regression or not because I cannot find the reasoning for dropping Draft 4. Depending on this the fix can be different.

How to reproduce

In my case I have a $position property in my API Resource that has a Symfony\Component\Validator\Constraints\Positive attribute. If you have an API test case that validates response json schema, you can see how it fails between 3.2.6 and 3.2.7.

Possible Solution

  • revert the change to drop Draft 4
  • keep the change and open an issue over validator library

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