Skip to content

adding specification enhancement for additionalProperties 2020-12 #726

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

Merged
merged 6 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions test-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,69 @@
"type": "array",
"items": { "$ref": "#/$defs/test" },
"minItems": 1
},
"specification":{
"description": "A reference to a specification document which defines the behavior tested by this test case. Typically this should be a JSON Schema specification document, though in cases where the JSON Schema specification points to another RFC it should contain *both* the portion of the JSON Schema specification which indicates what RFC (and section) to follow as *well* as information on where in that specification the behavior is specified.",

"type": "array",
"minItems": 1,
"uniqueItems": true,
"items":{
"properties": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all the values here will be (should be) strings, so probably you can/should use propertyNames here (probably with a oneOf + enum + pattern).

"core": {
"description": "A section in official JSON Schema core drafts",
"url": "https://json-schema.org/specification-links",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type":"string"
},
"validation": {
"description": "A section in official JSON Schema validation drafts",
"url": "https://json-schema.org/specification-links",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type":"string"
},
"ecma262": {
"description": "A section in official ECMA 262 specification for defining regular expressions",
"url": "https://262.ecma-international.org/",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type":"string"
},
"perl5": {
"description": "A section name in Perl documentation for defining regular expressions",
"url": "https://perldoc.perl.org/perlre",
"type":"string"
},
"quote": {
"description": "Quote describing the test case",
"type":"string"
}
},
"patternProperties": {
"^rfc\\d+$": {
"description": "A section in official RFC for the given rfc number",
"url": "https://www.rfc-editor.org/",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type":"string"
},
"^iso\\d+$": {
"description": "A section in official ISO for the given iso number",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type": "string"
}
},
"additionalProperties": { "type": "string" },
"minProperties": 1,
"propertyNames": {
"oneOf": [
{
"pattern": "^((iso)|(rfc))[0-9]+$"
},
{
"enum": [ "core", "validation", "ecma262", "perl5", "quote" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering we need this enum and that IIRC propertyNames doesn't affect unevaluatedProperties (meaning we can't use that instead of the additionalProperties above) my suggestion (to use propertyNames was probably bad, but whatever, we can evolve the schema later if need be. Thanks for putting this in.

}
]
}
}
}
},
"additionalProperties": false
Expand Down
10 changes: 8 additions & 2 deletions tests/draft2020-12/additionalProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"description":
"additionalProperties being false does not allow other properties",
"specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema. Boolean \"false\" forbids everything." } ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good follow up (to this ticket, perhaps even before we go much further) would be to make CI annotate pull requests with links to the section.

It'd be a lot easier to check whether this was correct if something were annotating the review with a link to this section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, for each version of the draft, we should add different "baseURI's" right which should append and check whether the the redirection to the section is failing or not?
And Ci script should be written separately for that.. I am new to this, may take time. But i'll do it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably custom logic for each specification which knows what the right URL is given what we have put in the corresponding field, yes, which the simplest version is just "a base URI".

But exactly right. Some CI script for that, which annotates PRs, and warns for broken links.

Can you perhaps immediately open an issue at least so we don't forget about it? Then yeah if you give it a shot that'd be amazing.

"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {"foo": {}, "bar": {}},
Expand Down Expand Up @@ -43,6 +44,7 @@
},
{
"description": "non-ASCII pattern with additionalProperties",
"specification": [ { "core":"10.3.2.3"} ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"patternProperties": {"^á": {}},
Expand All @@ -63,6 +65,7 @@
},
{
"description": "additionalProperties with schema",
"specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {"foo": {}, "bar": {}},
Expand All @@ -87,8 +90,8 @@
]
},
{
"description":
"additionalProperties can exist by itself",
"description": "additionalProperties can exist by itself",
"specification": [ { "core":"10.3.2.3", "quote": "With no other applicator applying to object instances. This validates all the instance values irrespective of their property names" } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": {"type": "boolean"}
Expand All @@ -108,6 +111,7 @@
},
{
"description": "additionalProperties are allowed by default",
"specification": [ { "core":"10.3.2.3", "quote": "Omitting this keyword has the same assertion behavior as an empty schema." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {"foo": {}, "bar": {}}
Expand All @@ -122,6 +126,7 @@
},
{
"description": "additionalProperties does not look in applicators",
"specification":[ { "core": "10.2", "quote": "Subschemas of applicator keywords evaluate the instance completely independently such that the results of one such subschema MUST NOT impact the results of sibling subschemas." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"allOf": [
Expand All @@ -139,6 +144,7 @@
},
{
"description": "additionalProperties with null valued instance properties",
"specification": [ { "core":"10.3.2.3" } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": {
Expand Down
Loading