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

Tests for propertyNames with additionalProperties/unevaluatedProperties #733

Merged
merged 8 commits into from
Apr 14, 2024

Conversation

Era-cell
Copy link
Contributor

@Era-cell Era-cell commented Apr 11, 2024

Addressing the issue: 305. Also inculded "specification" property,
I have added it such a way that property names cover pattern and length constraints too.
Please review my PR

@Era-cell Era-cell requested a review from a team as a code owner April 11, 2024 09:47
Copy link
Member

@gregsdennis gregsdennis left a comment

Choose a reason for hiding this comment

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

As I described in #732, were testing additionalProperties and unevaluatedProperties here, not propertyNames. These tests need to be moved to the appropriate files.

@@ -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 👍

@@ -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

@Era-cell Era-cell 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

@Era-cell Era-cell 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

@Era-cell Era-cell 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...

]
},
{
"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.

@Era-cell
Copy link
Contributor Author

Era-cell commented Apr 11, 2024

As I described in #732, were testing additionalProperties and unevaluatedProperties here, not propertyNames. These tests need to be moved to the appropriate files.

H.. Actually

As I described in #732, were testing additionalProperties and unevaluatedProperties here, not propertyNames. These tests need to be moved to the appropriate files.

Huh.. this PR is related to a different issue than issue #626. The issue #305 description says:

  • Verify that "propertyNames" and "additionalProperties"/"unevaluatedProperties" don't interact.
  • This has come up as a question a few times. propertyNames doesn't interact with other keywords.
    I feel this issue wants to address more on properttyNames rather than additionalProperties and unevaluatedProperties. So, can you please confirm on that...

@MeastroZI
Copy link
Contributor

MeastroZI commented Apr 11, 2024

@Era-cell, propertyNames is functioning as expected, but there is change in the behavior of additionalProperties and unevaluatedProperties for propertyNames. So because of that tests related to these properties should be included in the additionalProperties and unevaluatedProperties files.

@gregsdennis
Copy link
Member

but there is change in the behavior of additionalProperties and unevaluatedProperties for propertyNames.

No. There is no change in behavior. The tests are to verify that.

Copy link
Member

@gregsdennis gregsdennis left a comment

Choose a reason for hiding this comment

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

These look good. Please add them to 2019 and "next".

@Era-cell
Copy link
Contributor Author

These look good. Please add them to 2019 and "next".

I saw just now, that the tests are present already for unevaluatedProperties from 2019 - draft-next, already. So, I have considered to add tests only for additionalProperties

@MeastroZI
Copy link
Contributor

but the spec could be misread that propertyNames defines properties that additionalProperties would then skip. That's what the issue is about.

So for this schema

{"propertyNames": {
    "maxLength": 5
  },
  "additionalProperties": false
}

Should the data { apple: "apple" } be considered valid or not? because It appears we don't have tests for this specific case also.

@gregsdennis
Copy link
Member

Correct, { "apple": "apple" } is an invalid instance for that schema.

We do have that test with the latest update: see line 175 in the first file.

@gregsdennis gregsdennis requested a review from a team April 13, 2024 00:49
Copy link
Member

@gregsdennis gregsdennis left a comment

Choose a reason for hiding this comment

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

Asked for another pair of eyes.

Copy link
Member

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

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

lgtm, but needs a little code style cleanup. I left suggestions inline.

tests/draft-next/additionalProperties.json Outdated Show resolved Hide resolved
tests/draft-next/additionalProperties.json Outdated Show resolved Hide resolved
tests/draft2020-12/propertyNames.json Outdated Show resolved Hide resolved
Era-cell and others added 3 commits April 13, 2024 13:53
Co-authored-by: Jason Desrosiers <jdesrosi@gmail.com>
Co-authored-by: Jason Desrosiers <jdesrosi@gmail.com>
Co-authored-by: Jason Desrosiers <jdesrosi@gmail.com>
@Era-cell
Copy link
Contributor Author

Era-cell commented Apr 13, 2024

I have updated the changes, and Thank you

@gregsdennis gregsdennis merged commit 3d5048e into json-schema-org:main Apr 14, 2024
1 check passed
"valid": true
},
{
"description": "Valid against propertyNames, but not unevaluatedProperties",
Copy link
Contributor

Choose a reason for hiding this comment

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

this says unevaluatedProperties, should say additionalProperties I think.
same for the other two.

Copy link
Contributor Author

@Era-cell Era-cell Apr 17, 2024

Choose a reason for hiding this comment

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

Yeah! let me just correct it and raise the pull request again.
I will have to be more careful... Thank you

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

Successfully merging this pull request may close these issues.

None yet

5 participants