Skip to content

Tests for propertyNames with additionalProperties/unevaluatedProperties #733

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 8 commits into from
Apr 14, 2024
58 changes: 58 additions & 0 deletions tests/draft2020-12/propertyNames.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{
"description": "propertyNames validation",
"specification": [ { "core": "10.3.2.4" } ],
Copy link
Member

Choose a reason for hiding this comment

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

If we haven't finalized these additions (the discussion for which is elsewhere), we should hold off adding them here. Please remove until that discussion had come to a final decision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, cool with that 👍

"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": {"maxLength": 3}
Expand Down Expand Up @@ -46,6 +47,7 @@
},
{
"description": "propertyNames with boolean schema true",
"specification": [ { "core": "10.3.2.4", "quote": "The value of \"propertyNames\" MUST be a valid JSON Schema." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": true
Expand All @@ -65,6 +67,7 @@
},
{
"description": "propertyNames with boolean schema false",
"specification": [ { "core": "10.3.2.4", "quote": "The value of \"propertyNames\" MUST be a valid JSON Schema." } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"propertyNames": false
Expand All @@ -81,5 +84,60 @@
"valid": true
}
]
},
{
"description": "propertyNames with additionalProperties",
Copy link
Member

Choose a reason for hiding this comment

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

These test cases aren't actually testing whether additional properties are allowed.

Copy link
Contributor Author

@suprith-hub suprith-hub Apr 11, 2024

Choose a reason for hiding this comment

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

This test is to actually check if additionalProperties affect propertyNames.. so can you please recheck according to the requirement of the issue #305 @gregsdennis

Copy link
Contributor

Choose a reason for hiding this comment

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

"In this test case, the validation of data fails. For example:

{
            "description": "property name is invalid",
            "data": { "watermelon": 6 },
            "valid": false
}

This failure occurs due to the exceeded property length in the validation of propertyName, rather than due to unevaluated properties. Therefore, this test does not actually determine whether additional properties are allowed or not."

Copy link
Contributor Author

@suprith-hub suprith-hub Apr 11, 2024

Choose a reason for hiding this comment

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

So, "propertyNames doesn't interact with other keywords." addressed in #305 this issue. This statement means that these test cases I have written should be included under additional/unevaluated Properties and not propertyNames??

Copy link
Member

@gregsdennis gregsdennis Apr 11, 2024

Choose a reason for hiding this comment

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

This test is to actually check if additionalProperties affect propertyNames

No, that's backward. There's no reason additionalProperties would influence propertyNames, but the spec could be misread that propertyNames defines properties that additionalProperties would then skip. That's what the issue is about.

For example, your first test case with "apple" should be invalid because the property isn't allowed.

The tests are about additionalProperties.

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, we should be checking whether propertyNames affect adiditionalProperties. Got it, I feel we can go both the way on the tests if its ok.

Copy link
Member

Choose a reason for hiding this comment

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

I feel we can go both the way on the tests if its ok.

There's no need. There's nothing in the spec that suggests additionalProperties could affect propertyNames. We don't have tests that ensure maxLength and items are independent because nothing implies that they're connected.

Copy link
Contributor Author

@suprith-hub suprith-hub Apr 12, 2024

Choose a reason for hiding this comment

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

I see. I get it! so tests are written when the information in ambiguous, especially in spec..

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that and explicit requirements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool cool! Can you review the latest changes...

"specification": [ { "core": "10.3.2.4" }, { "core": "10.3.2.3", "quote": "The validation of propertyNames remains unaffected by the presence or absence of additionalProperties. \"propertyNames\" are validated independently, regardless of other sibling keywords" } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties":{
"type": "number"
},
"propertyNames": {
"maxLength": 5
}
},
"tests": [
{
"description": "property names with the given pattern are valid",
"data": {"apple": 4},
"valid": true
},
{
"description": "property name is invalid",
"data": { "watermelon": 6 },
"valid": false
}
]
},
{
"description": "propertyNames with unevaluatedProperties",
Copy link
Member

Choose a reason for hiding this comment

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

These aren't testing whether unevaluated properties are allowed.

"specification": [ { "core": "10.3.2.4" }, { "core":"11.3", "quote": "The validation of propertyNames remains unaffected by the presence or absence of unevaluatedProperties. \"propertyNames\" are validated independently, regardless of other sibling keywords" } ],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties":{
"banana":{
"const": "available"
}
},
"unevaluatedProperties":{
"type": "number"
},
"propertyNames": {
"pattern": "^[a-b]"
}
},
"tests": [
{
"description": "property names with the given pattern are valid",
"data": { "banana": "available", "apple": 4 },
"valid": true
},
{
"description": "property name chickoo is invalid",
"data": { "banana": "available", "chickoo": 10 },
"valid": false
}
]
}
]
Loading