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

draft2020-12 test cases are not compliant with the specification #750

Closed
mathematikoi opened this issue Jun 19, 2024 · 9 comments
Closed

Comments

@mathematikoi
Copy link

mathematikoi commented Jun 19, 2024

I'm writing a fully-compliant json schema implementation, when running the draft2020-12 test cases it did throw for this reason:

The "$schema" keyword SHOULD be used in the document root schema object, and MAY be used in the root schema objects of embedded schema resources. It MUST NOT appear in non-resource root schema objects. If absent from the document root schema, the resulting behavior is implementation-defined.

tldr; the schemas have the $schema keyword while they are not resource schemas!

would be happy to update the test cases, once this is confirmed to be a non-compliance issue!

@gregsdennis
Copy link
Member

The document root for the tests is not a schema, so that passage does not apply to it. This part applies:

MAY be used in the root schema objects of embedded schema resources

The $schema keywords are in the schema resource roots.


the schemas have the $keyword while they are not resource schemas

They are schema resources because they declare $id. This is the defining feature of a schema resource.

@gregsdennis
Copy link
Member

You may also want to review #586 and related issues.

@mathematikoi
Copy link
Author

mathematikoi commented Jun 20, 2024

fixed typo in original comment

tldr; the schemas have the $schema keyword while they are not resource schemas!

thanks for the pr reference.

They are schema resources because they declare $id. This is the defining feature of a schema resource.

they don't declare $id actually, e.g.:

"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {"foo": {}, "bar": {}},
"patternProperties": { "^v": {} },
"additionalProperties": false
},

@gregsdennis
Copy link
Member

Point taken. They are intended as part of the test suite to be schema resources. Take that at face value.

I do know that at some point @karenetheridge wanted all of the $ids in the tests to be unique, but maybe that didn't mean they all needed $id.

@mathematikoi
Copy link
Author

i see, for now this inspired me to adding turning off specific rules of the spec to our implementation, i will need to think more about the rationale for this constraint!

Screenshot 2024-06-20 at 01 28 41

@gregsdennis
Copy link
Member

It's not in violation of the spec, though, because the document is not a schema. The test suite defines the content of the schema property inside the test as a schema. Therefore, the schema is embedded in another document and $schema is permitted at the schema root.

You shouldn't need to change anything in your implementation to run through the test suite.

It sounds to me like you need to allow for schemas embedded in other non-schema documents.

@mathematikoi
Copy link
Author

mathematikoi commented Jun 20, 2024

the implementation supports that, im disabling enforcing this part of the spec (in bold)

The "$schema" keyword SHOULD be used in the document root schema object, and MAY be used in the root schema objects of embedded schema resources. It MUST NOT appear in non-resource root schema objects. If absent from the document root schema, the resulting behavior is implementation-defined.

the implementation panics when it sees $schema in a non-resource schema!

@gregsdennis
Copy link
Member

gregsdennis commented Jun 20, 2024

I'm saying that those are resource root schemas because the test file format says that the data contained at that location in the file is a schema and Core Section 4.3.5 says:

The root schema is the schema that comprises the entire JSON document in question. The root schema is always a schema resource, where the URI is determined as described in section 9.1.1.

It's a resource because it's the root of the schema. It's just that in this case, the schema is embedded in another document (which means it's not the root of the document, and that's okay).

@mathematikoi
Copy link
Author

totally clears it for me! tysm, i appreciate the specification links :D

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

No branches or pull requests

2 participants