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

test when $dynamicRef references a boolean schema #701

Merged
merged 1 commit into from
Dec 10, 2023
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
30 changes: 30 additions & 0 deletions tests/draft-next/dynamicRef.json
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,35 @@
"valid": false
}
]
},
{
"description": "$dynamicRef points to a boolean schema",
"schema": {
"$schema": "https://json-schema.org/draft/next/schema",
"$defs": {
"true": true,
"false": false
},
"properties": {
"true": {
"$dynamicRef": "#/$defs/true"
},
"false": {
"$dynamicRef": "#/$defs/false"
}
}
},
"tests": [
{
"description": "follow $dynamicRef to a true schema",
"data": { "true": 1 },
"valid": true
},
{
"description": "follow $dynamicRef to a false schema",
"data": { "false": 1 },
Copy link
Member

Choose a reason for hiding this comment

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

This branch of the test seems "uninteresting" / unrelated to this test case -- I assume it fails both before and after whatever bugfix you made. It seems more likely to be interesting/relevant if you put it behind a dynamic ref itself? i.e. #/$defs/true and #/$defs/false and fail when you hit false via the dynamicRef.

Copy link
Member Author

Choose a reason for hiding this comment

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

The intent is to show a way to a 'valid' state. Otherwise, a naive interpretation of the test should be that this input should always cause a validation failure. Do you have a suggestion for a better way to provide a valid data input?

Copy link
Member

Choose a reason for hiding this comment

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

The intent is to show a way to a 'valid' state.

(I was commenting on the invalid branch, which fails simply because it's equivalent to {"properties": {"foo": false}})

What I was trying to suggest instead above (albeit I don't know whether it exercises your specific bug you were targeting, but it seems like it should be the same) was to use this schema:

{
            "$defs": {
                "true": true,
                "false": false
            },
            "properties": {
                "true": {
                    "$dynamicRef": "#/$defs/true"
                },
                "false": { "$dynamicRef": "#/$defs/false" }
            }
        }

and to then have the two instances (and outcomes) be exactly the ones you have now I think.

"valid": false
}
]
}
]
30 changes: 30 additions & 0 deletions tests/draft2020-12/dynamicRef.json
Original file line number Diff line number Diff line change
Expand Up @@ -726,5 +726,35 @@
"valid": false
}
]
},
{
"description": "$dynamicRef points to a boolean schema",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
"true": true,
"false": false
},
"properties": {
"true": {
"$dynamicRef": "#/$defs/true"
},
"false": {
"$dynamicRef": "#/$defs/false"
}
}
},
"tests": [
{
"description": "follow $dynamicRef to a true schema",
"data": { "true": 1 },
"valid": true
},
{
"description": "follow $dynamicRef to a false schema",
"data": { "false": 1 },
"valid": false
}
]
}
]