-
-
Notifications
You must be signed in to change notification settings - Fork 220
Add annotation tests from @hyperjump/json-schema #770
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
jdesrosiers
merged 8 commits into
json-schema-org:main
from
jdesrosiers:annotation-tests
May 7, 2025
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0aef5f8
Add annotation tests
jdesrosiers 55b9fad
Add automation to check that annotation tests are valid
jdesrosiers 3426e76
Updates based on feedback from Karen
jdesrosiers 9f90e2d
Updates based on feedback from Juan
jdesrosiers 2779c99
Make order of assertion properties consistent
jdesrosiers 35ccff6
Remove tests that assert a keyword doesn't emit annotations
jdesrosiers 265103e
Update content tests to only apply to string instances
jdesrosiers ec05504
Change "expected" to an object with schema locations
jdesrosiers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Validate annotation tests | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "annotations/**" | ||
|
||
jobs: | ||
annotate: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Deno | ||
uses: denoland/setup-deno@v2 | ||
with: | ||
deno-version: "2.x" | ||
|
||
- name: Validate annotation tests | ||
run: deno --node-modules-dir=auto --allow-read --no-prompt bin/annotation-tests.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Annotations Tests Suite | ||
|
||
The Annotations Test Suite tests which annotations should appear (or not appear) | ||
on which values of an instance. These tests are agnostic of any output format. | ||
Similar to the validation tests, they only test the end result and don't include | ||
details like mapping the annotation back to the schema location that contributed | ||
it. This Test Suite leaves those details to be tested by output format tests. | ||
|
||
## Supported Dialects | ||
|
||
Although the concept of annotations didn't appear in the spec until 2019-09, the | ||
concept is compatible with every version of JSON Schema. Test Cases in this Test | ||
Suite are designed to be compatible with as many releases of JSON Schema as | ||
possible. They do not include `$schema` or `$id`/`id` keywords so that | ||
implementations can run the same Test Suite for each dialect they support. | ||
|
||
Since this Test Suite can be used for a variety of dialects, there are a couple | ||
of options that can be used by Test Runners to filter out Test Cases that don't | ||
apply to the dialect under test. | ||
|
||
## Test Case Components | ||
|
||
### description | ||
|
||
A short description of what behavior the Test Case is covering. | ||
|
||
### compatibility | ||
|
||
The `compatibility` option allows you to set which dialects the Test Case is | ||
compatible with. Test Runners can use this value to filter out Test Cases that | ||
don't apply the to dialect currently under test. Dialects are indicated by the | ||
number corresponding to their release. Date-based releases use just the year. | ||
|
||
If this option isn't present, it means the Test Case is compatible with any | ||
dialect. | ||
|
||
If this option is present with a number, the number indicates the minimum | ||
release the Test Case is compatible with. This example indicates that the Test | ||
Case is compatible with draft-07 and up. | ||
|
||
**Example**: `"compatibility": "7"` | ||
|
||
You can use a `<=` operator to indicate that the Test Case is compatible with | ||
releases less then or equal to the given release. This example indicates that | ||
the Test Case is compatible with 2019-09 and under. | ||
|
||
**Example**: `"compatibility": "<=2019"` | ||
|
||
You can use comma-separated values to indicate multiple constraints if needed. | ||
This example indicates that the Test Case is compatible with releases between | ||
draft-06 and 2019-09. | ||
|
||
**Example**: `"compatibility": "6,<=2019"` | ||
|
||
For convenience, you can use the `=` operator to indicate a Test Case is only | ||
compatible with a single release. This example indicates that the Test Case is | ||
compatible only with 2020-12. | ||
|
||
**Example**: `"compatibility": "=2020"` | ||
|
||
### schema | ||
|
||
The schema that will serve as the subject for the tests. Whenever possible, this | ||
schema shouldn't include `$schema` or `id`/`$id` because Test Cases should be | ||
designed to work with as many releases as possible. | ||
|
||
### externalSchemas | ||
|
||
This allows you to define additional schemas that `schema` makes references to. | ||
The value is an object where the keys are retrieval URIs and values are schemas. | ||
Most external schemas aren't self identifying (using `id`/`$id`) and rely on the | ||
retrieval URI for identification. This is done to increase the number of | ||
dialects that the test is compatible with. Because `id` changed to `$id` in | ||
draft-06, if you use `$id`, the test becomes incompatible with draft-03/4 and in | ||
most cases, that's not necessary. | ||
|
||
### tests | ||
|
||
A collection of Tests to run to verify the Test Case. | ||
|
||
## Test Components | ||
|
||
### instance | ||
|
||
The JSON instance to be annotated. | ||
|
||
### assertions | ||
|
||
A collection of assertions that must be true for the test to pass. | ||
|
||
## Assertions Components | ||
|
||
### location | ||
|
||
The instance location. | ||
|
||
### keyword | ||
|
||
The annotating keyword. | ||
|
||
### expected | ||
|
||
An array of `keyword` annotations expected on the instance at `location`. | ||
`expected` is an array because there's always a chance that an annotation is | ||
applied multiple times to any given instance location. Test runners can consider | ||
this an unordered list, but as a convention for this Test Suite, the `expected` | ||
array should be sorted such that the most recently encountered value for an | ||
annotation given top-down evaluation of the schema comes before previously | ||
encountered values. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
|
||
"type": "object", | ||
"properties": { | ||
"location": { | ||
"markdownDescription": "The instance location.", | ||
"type": "string", | ||
"format": "json-pointer" | ||
}, | ||
"keyword": { | ||
"markdownDescription": "The annotation keyword.", | ||
"type": "string" | ||
}, | ||
"expected": { | ||
"markdownDescription": "An array of `keyword` annotations expected on the instance at `location`.", | ||
"type": "array" | ||
} | ||
}, | ||
"required": ["location", "keyword", "expected"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
|
||
"type": "object", | ||
"properties": { | ||
"description": { | ||
"markdownDescription": "A short description of what behavior the Test Case is covering.", | ||
"type": "string" | ||
}, | ||
"compatibility": { | ||
"markdownDescription": "Set which dialects the Test Case is compatible with. Examples:\n- `\"7\"` -- draft-07 and above\n- `\"<=2019\"` -- 2019-09 and previous\n- `\"6,<=2019\"` -- Between draft-06 and 2019-09\n- `\"=2020\"` -- 2020-12 only", | ||
"type": "string", | ||
"pattern": "^(<=|=)?([123467]|2019|2020)(,(<=|=)?([123467]|2019|2020))*$" | ||
}, | ||
"schema": { | ||
"markdownDescription": "This schema shouldn't include `$schema` or `id`/`$id` unless necesary for the test because Test Cases should be designed to work with as many releases as possible.", | ||
"type": ["boolean", "object"] | ||
}, | ||
"externalSchemas": { | ||
"markdownDescription": "The keys are retrieval URIs and values are schemas.", | ||
"type": "object", | ||
"patternProperties": { | ||
"": { | ||
"type": ["boolean", "object"] | ||
} | ||
}, | ||
"propertyNames": { | ||
"format": "uri" | ||
} | ||
}, | ||
"tests": { | ||
"markdownDescription": "A collection of Tests to run to verify the Test Case.", | ||
"type": "array", | ||
"items": { "$ref": "./test.schema.json" } | ||
} | ||
}, | ||
"required": ["description", "schema", "tests"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
|
||
"type": "object", | ||
"properties": { | ||
"description": { | ||
"type": "string" | ||
}, | ||
"suite": { | ||
"type": "array", | ||
"items": { "$ref": "./test-case.schema.json" } | ||
} | ||
}, | ||
"required": ["description", "suite"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
|
||
"type": "object", | ||
"properties": { | ||
"instance": { | ||
"markdownDescription": "The JSON instance to be annotated." | ||
}, | ||
"assertions": { | ||
"markdownDescription": "A collection of assertions that must be true for the test to pass.", | ||
"type": "array", | ||
"items": { "$ref": "./assertion.schema.json" } | ||
} | ||
}, | ||
"required": ["instance", "assertions"] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.