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

strictProperties #193

Closed
ghost opened this issue May 20, 2016 · 8 comments
Closed

strictProperties #193

ghost opened this issue May 20, 2016 · 8 comments

Comments

@ghost
Copy link

ghost commented May 20, 2016

it would be great to add strictProperties support
https://github.com/fge/json-schema-validator/wiki/v5:-strictProperties

@epoberezkin
Copy link
Member

I am not sure I understand what problem this keyword solves that is not already solved by existing keywords.

@ghost
Copy link
Author

ghost commented May 22, 2016

because additionnalProperties only apply to properties declared at the same level.

In the following exemple, if my schema is a mix between 2 schema (part of each), i have no way currently to restrict to properties i require. The only way would be stictProperties.

{
    "$schema": "http://json-schema.org/schema#",
    "id": "http://xy.com/schema/schemaC.json",
    "allOf": [{
        "$ref": "schemaA.json"
    }, {
        "$ref": "schemaB.json"
    }, {
        "required": [
            "propA1",
            "propA3",
            "propA4",
            "propA7",
            "propB2",
            "propB4",
            "propB5"
        ],
        "strictProperties": true
    }]
}

With "stricProperties" : true i can not have a additionnal property not visible in "required". If "propA2" or "propC1" is in my object, validation will fail.

@epoberezkin
Copy link
Member

epoberezkin commented May 23, 2016

I see nothing in the proposal that would suggest it is the case.
I generally disagree with the idea of having keywords that have wider effects than the schema they are used in - there are quite a few edge cases that make it both unexpected and difficult to implement.

@epoberezkin
Copy link
Member

According to the proposal, this schema:

{
  "required": [
    "propA1",
    "propA3",
    "propB2",
    "propB4",
  ],
  "strictProperties": true
}

is equivalent to:

{
  "properties": {
    "propA1": {},
    "propA3": {},
    "propB2": {},
    "propB4": {}
  },
  "required": [
    "propA1",
    "propA3",
    "propB2",
    "propB4",
  ],
  "additionalProperties": false
}

So it is just a syntax sugar that can be added with macro keyword definition. Can be added to ajv-keywords I think

@ghost
Copy link
Author

ghost commented Jun 28, 2016

it is not equivalent.
"has no other properties than the ones defined in properties, patternPropertyGroups and required."

that means if i use a shema with external properties using $ref and i use required in the parent shema with "strictProperties" it will require and only accept properties in "required" property. With external properties, the property "additionalProperties" will not work as i would like.

@epoberezkin
Copy link
Member

What do you mean by "external properties"? In any case strictProperties should be only affected by properties and other keywords in the same schema object, it can't take into account properties in other objects.

@epoberezkin
Copy link
Member

Closing the issue. I will not be implementing any keywords with global visibility until they are added to the standard. And I am strongly against it, I think keywords should only have local visibility.

I haven't been presented with a single use-case for properties that cannot be expressed using existing JSON-schema vocabulary. I like the idea of $merge/$patch keywords though, extending the schema is indeed not supported and it is needed to extend meta-schemas, for example.

If you are interested in strictProperties keyword with local visibility, we can add it to ajv-keywords as I suggested (I already wrote the code, just need to add test cases...)

@epoberezkin
Copy link
Member

See $merge and $patch keywords.

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

No branches or pull requests

2 participants
@epoberezkin and others