Skip to content

Commit b46e6d4

Browse files
committed
Squashed 'json/' changes from 54f3784a..4ba013d5
4ba013d5 Merge pull request #747 from santhosh-tekuri/duration aa500e80 Merge pull request #749 from json-schema-org/gregsdennis/json-everything-update eb8ce976 Merge pull request #757 from ajevans99/main dcdae5c0 Merge pull request #758 from sirosen/hostname-format-check-empty-string db21d21b Merge branch 'main' into hostname-format-check-empty-string 3fd78f04 Merge pull request #1 from ajevans99/swift-json-schema 3cada3a9 Update README.md 82a07749 Merge pull request #753 from json-schema-org/ether/fix-draft-locations a66d23d4 move draft-specific files to the dedicated dir for its draft 8ef15501 Merge pull request #751 from big-andy-coates/format_tests_under_format fe1b1392 All format test cases should be under the `format` directory. b1ee90f6 json-everything moved to an org c00a3f94 test: duration format must start with P 9fc880bf Merge pull request #740 from notEthan/format-pattern-control-char cbd48ea5 Simplify test of \a regex character to test directly against `pattern` schema d6f1010a Merge pull request #746 from json-schema-org/annotations 4aec22c1 Revert the changes to additionalProperties.json. 2dc10671 Move the workflow step title. d9ce71ac May as well also show quotes in the annotation. 1b719a84 Pick the line after the description when attaching spec annotations. 08105151 Markdown is apparently not (yet?) supported in annotations. 81645773 Tidy up the specification annotator a bit. 38628b79 Make the spec URLs structure a bit easier for internal use. 4ebbeaf4 Merge branch 'Era-cell/main' e4bd7554 dumbness2 corrected d8ade402 inside run 57c7c869 changed install location 11f8e511 Added installing command in workflow f2766616 template library, url loads changes c2badb12 Merge pull request #734 from OptimumCode/idn-hostname-arabic-indic-mixed dd9599a5 Merge branch 'main' of github.com:json-schema-org/JSON-Schema-Test-Suite 5b393436 add pr dependencies action 3a509007 Clear existin annotations on same PR 23674123 Cases for rfc and iso written separately 0b780b2c Corected yaml format 2b1ffb74 Best practices followed with optimized code e88a2da6 Works for all OS 7b40efe4 Base path for neighbouring file? 564e6957 Walking through all leaf files 7b84fb44 Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-Suite 891d0265 First workflow2 1c175195 regex correction 96f7683a Final correction2 - file names beautufied 5f050a07 Final correction1 77527b63 Stupidity corrected eb8fd760 Branch name specified 540a269b Log2 f29d090a Wrong location sepcification 582e12be logging logs check df3bdecc path corrected c6b937ca Reading all jsons and spec urls added cbdd1755 change day2 79dc92f1 TOKEN ce52852d Python file location changed 3558c2c6 Fake add to tests eecc7b7a Merge branch 'main' of https://github.com/Era-cell/JSON-Schema-Test-Suite 810d148a First workflow2 4eac02c7 First workflow 40bcb8b3 Corrected replaced unevaluated with additoinalProperties 4ae14268 Add valid first character to avoid Bidi rule violation 202d5625 test: hostname format check fails on empty string git-subtree-dir: json git-subtree-split: 4ba013d58e747ecaf48c8bb7cf248cb0d564afbc
1 parent 8fcfc3a commit b46e6d4

40 files changed

+389
-50
lines changed

.github/workflows/pr-dependencies.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Check PR Dependencies
2+
3+
on: pull_request
4+
5+
jobs:
6+
check_dependencies:
7+
runs-on: ubuntu-latest
8+
name: Check Dependencies
9+
steps:
10+
- uses: gregsdennis/dependencies-action@main
11+
env:
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Show Specification Annotations
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'tests/**'
7+
8+
jobs:
9+
annotate:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.x'
19+
20+
- name: Generate Annotations
21+
run: pip install uritemplate && bin/annotate-specification-links

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ Node-specific support is maintained in a [separate repository](https://github.co
293293

294294
### .NET
295295

296-
* [JsonSchema.Net](https://github.com/gregsdennis/json-everything)
296+
* [JsonSchema.Net](https://github.com/json-everything/json-everything)
297297
* [Newtonsoft.Json.Schema](https://github.com/JamesNK/Newtonsoft.Json.Schema)
298298

299299
### Perl
@@ -339,6 +339,7 @@ Node-specific support is maintained in a [separate repository](https://github.co
339339
### Swift
340340

341341
* [JSONSchema](https://github.com/kylef/JSONSchema.swift)
342+
* [swift-json-schema](https://github.com/ajevans99/swift-json-schema)
342343

343344
If you use it as well, please fork and send a pull request adding yourself to
344345
the list :).

bin/annotate-specification-links

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Annotate pull requests to the GitHub repository with links to specifications.
4+
"""
5+
6+
from __future__ import annotations
7+
8+
from pathlib import Path
9+
from typing import Any
10+
import json
11+
import re
12+
import sys
13+
14+
from uritemplate import URITemplate
15+
16+
17+
BIN_DIR = Path(__file__).parent
18+
TESTS = BIN_DIR.parent / "tests"
19+
URLS = json.loads(BIN_DIR.joinpath("specification_urls.json").read_text())
20+
21+
22+
def urls(version: str) -> dict[str, URITemplate]:
23+
"""
24+
Retrieve the version-specific URLs for specifications.
25+
"""
26+
for_version = {**URLS["json-schema"][version], **URLS["external"]}
27+
return {k: URITemplate(v) for k, v in for_version.items()}
28+
29+
30+
def annotation(
31+
path: Path,
32+
message: str,
33+
line: int = 1,
34+
level: str = "notice",
35+
**kwargs: Any,
36+
) -> str:
37+
"""
38+
Format a GitHub annotation.
39+
40+
See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
41+
for full syntax.
42+
"""
43+
44+
if kwargs:
45+
additional = "," + ",".join(f"{k}={v}" for k, v in kwargs.items())
46+
else:
47+
additional = ""
48+
49+
relative = path.relative_to(TESTS.parent)
50+
return f"::{level} file={relative},line={line}{additional}::{message}\n"
51+
52+
53+
def line_number_of(path: Path, case: dict[str, Any]) -> int:
54+
"""
55+
Crudely find the line number of a test case.
56+
"""
57+
with path.open() as file:
58+
description = case["description"]
59+
return next(
60+
(i + 1 for i, line in enumerate(file, 1) if description in line),
61+
1,
62+
)
63+
64+
65+
def main():
66+
# Clear annotations which may have been emitted by a previous run.
67+
sys.stdout.write("::remove-matcher owner=me::\n")
68+
69+
for version in TESTS.iterdir():
70+
if version.name in {"draft-next", "latest"}:
71+
continue
72+
73+
version_urls = urls(version.name)
74+
75+
for path in version.rglob("*.json"):
76+
try:
77+
contents = json.loads(path.read_text())
78+
except json.JSONDecodeError as error:
79+
error = annotation(
80+
level="error",
81+
path=path,
82+
line=error.lineno,
83+
col=error.pos + 1,
84+
title=str(error),
85+
)
86+
sys.stdout.write(error)
87+
88+
for test_case in contents:
89+
specifications = test_case.get("specification")
90+
if specifications is not None:
91+
for each in specifications:
92+
quote = each.pop("quote", "")
93+
(kind, section), = each.items()
94+
95+
number = re.search(r"\d+", kind)
96+
spec = "" if number is None else number.group(0)
97+
98+
url = version_urls[kind].expand(
99+
spec=spec,
100+
section=section,
101+
)
102+
103+
message = f"{url}\n\n{quote}" if quote else url
104+
sys.stdout.write(
105+
annotation(
106+
path=path,
107+
line=line_number_of(path, test_case),
108+
title="Specification Link",
109+
message=message,
110+
),
111+
)
112+
113+
114+
if __name__ == "__main__":
115+
main()

bin/specification_urls.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"json-schema": {
3+
"draft2020-12": {
4+
"core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-{section}",
5+
"validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-{section}"
6+
},
7+
"draft2019-09": {
8+
"core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.{section}",
9+
"validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.{section}"
10+
},
11+
"draft7": {
12+
"core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.{section}",
13+
"validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.{section}"
14+
},
15+
"draft6": {
16+
"core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.{section}",
17+
"validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.{section}"
18+
},
19+
"draft4": {
20+
"core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.{section}",
21+
"validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.{section}"
22+
},
23+
"draft3": {
24+
"core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf"
25+
}
26+
},
27+
28+
"external": {
29+
"ecma262": "https://262.ecma-international.org/{section}",
30+
"perl5": "https://perldoc.perl.org/perlre#{section}",
31+
"rfc": "https://www.rfc-editor.org/rfc/{spec}.txt#{section}",
32+
"iso": "https://www.iso.org/obp/ui"
33+
}
34+
}
File renamed without changes.
File renamed without changes.

remotes/draft4/subSchemas.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"definitions": {
3+
"integer": {
4+
"type": "integer"
5+
},
6+
"refToInteger": {
7+
"$ref": "#/definitions/integer"
8+
}
9+
}
10+
}

remotes/draft6/name.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"definitions": {
3+
"orNull": {
4+
"anyOf": [
5+
{
6+
"type": "null"
7+
},
8+
{
9+
"$ref": "#"
10+
}
11+
]
12+
}
13+
},
14+
"type": "string"
15+
}

remotes/ref-and-definitions.json renamed to remotes/draft6/ref-and-definitions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$id": "http://localhost:1234/ref-and-definitions.json",
2+
"$id": "http://localhost:1234/draft6/ref-and-definitions.json",
33
"definitions": {
44
"inner": {
55
"properties": {

remotes/draft6/subSchemas.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"definitions": {
3+
"integer": {
4+
"type": "integer"
5+
},
6+
"refToInteger": {
7+
"$ref": "#/definitions/integer"
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"definitions": {
3+
"refToInteger": {
4+
"$ref": "#foo"
5+
},
6+
"A": {
7+
"$id": "#foo",
8+
"type": "integer"
9+
}
10+
}
11+
}

remotes/draft7/name.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"definitions": {
3+
"orNull": {
4+
"anyOf": [
5+
{
6+
"type": "null"
7+
},
8+
{
9+
"$ref": "#"
10+
}
11+
]
12+
}
13+
},
14+
"type": "string"
15+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$id": "http://localhost:1234/draft7/ref-and-definitions.json",
3+
"definitions": {
4+
"inner": {
5+
"properties": {
6+
"bar": { "type": "string" }
7+
}
8+
}
9+
},
10+
"allOf": [ { "$ref": "#/definitions/inner" } ]
11+
}

remotes/draft7/subSchemas.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"definitions": {
3+
"integer": {
4+
"type": "integer"
5+
},
6+
"refToInteger": {
7+
"$ref": "#/definitions/integer"
8+
}
9+
}
10+
}

tests/draft-next/optional/ecmascript-regex.json

-14
Original file line numberDiff line numberDiff line change
@@ -405,20 +405,6 @@
405405
}
406406
]
407407
},
408-
{
409-
"description": "\\a is not an ECMA 262 control escape",
410-
"schema": {
411-
"$schema": "https://json-schema.org/draft/next/schema",
412-
"$ref": "https://json-schema.org/draft/next/schema"
413-
},
414-
"tests": [
415-
{
416-
"description": "when used as a pattern",
417-
"data": { "pattern": "\\a" },
418-
"valid": false
419-
}
420-
]
421-
},
422408
{
423409
"description": "pattern with non-ASCII digits",
424410
"schema": {

tests/draft-next/optional/format/duration.json

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
"data": "PT1D",
4747
"valid": false
4848
},
49+
{
50+
"description": "must start with P",
51+
"data": "4DT12H30M5S",
52+
"valid": false
53+
},
4954
{
5055
"description": "no elements present",
5156
"data": "P",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"description": "\\a is not an ECMA 262 control escape",
4+
"schema": {
5+
"$schema": "https://json-schema.org/draft/next/schema",
6+
"format": "regex"
7+
},
8+
"tests": [
9+
{
10+
"description": "when used as a pattern",
11+
"data": "\\a",
12+
"valid": false
13+
}
14+
]
15+
}
16+
]

tests/draft-next/optional/format/hostname.json

+5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@
120120
"description": "single label ending with digit",
121121
"data": "hostnam3",
122122
"valid": true
123+
},
124+
{
125+
"description": "empty string",
126+
"data": "",
127+
"valid": false
123128
}
124129
]
125130
}

tests/draft-next/optional/format/idn-hostname.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
{
258258
"description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits",
259259
"comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8",
260-
"data": "\u0660\u06f0",
260+
"data": "\u0628\u0660\u06f0",
261261
"valid": false
262262
},
263263
{
@@ -326,6 +326,11 @@
326326
"description": "single label ending with digit",
327327
"data": "hostnam3",
328328
"valid": true
329+
},
330+
{
331+
"description": "empty string",
332+
"data": "",
333+
"valid": false
329334
}
330335
]
331336
}

tests/draft2019-09/optional/format/duration.json

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
"data": "PT1D",
4747
"valid": false
4848
},
49+
{
50+
"description": "must start with P",
51+
"data": "4DT12H30M5S",
52+
"valid": false
53+
},
4954
{
5055
"description": "no elements present",
5156
"data": "P",

0 commit comments

Comments
 (0)