Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem due to empty required (against v4 spec) #21

Open
amitu opened this issue May 30, 2017 · 2 comments
Open

problem due to empty required (against v4 spec) #21

amitu opened this issue May 30, 2017 · 2 comments

Comments

@amitu
Copy link
Contributor

amitu commented May 30, 2017

I am using golang:gojsonschema and python:jsonschema. They both only support v4 of the json-schema.

V4 required field says:

The value of this keyword MUST be an array. This array MUST have at
least one element. Elements of this array MUST be strings, and MUST
be unique.

We are currently generating schema like this:

{
    "type": "object",
    "properties": {
        "pincode": {
            "type": "integer",
            "minimum": 100000,
            "maximum": 99999999
        },
        "query": {
            "type": "string",
            "maxLength": 1000
        }
    },
    "required": []
}

When no field is required. This is not accepted by those libraries.

Ideally I would have been creating pull requests against those libraries (and I will be, when time permits), but I think leaving an empty required field is "bug". I mean it is allowed by latest specs:

The value of this keyword MUST be an array. Elements of this array,
if any, MUST be strings, and MUST be unique.

An object instance is valid against this keyword if every item in the
array is the name of a property in the instance.

Omitting this keyword has the same behavior as an empty array.

I think it would be pragmatic to drop the required field if it is empty. We should accept it in input, but drop it in output. But that breaks idempotency across the roundtrip.

So, what do you think?

@jwoudenberg
Copy link
Contributor

Seems a valid reason to drop idempotency in the round trip. We can alter the test a bit to compare 'simplified' versions of the schema, 'simplified' meaning we remove empty required arrays if they exist.

@amitu
Copy link
Contributor Author

amitu commented Jun 2, 2017

Not sure when would I get time to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants