Skip to content

Commit

Permalink
Squashed 'JSON-Schema-Test-Suite/' changes from bf0360f4..9fc880bf
Browse files Browse the repository at this point in the history
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
54f3784a Merge pull request #731 from MeastroZI/main
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
ff29264c Merge pull request #741 from harrel56/chore/tabs-to-spaces
9f39cf73 use spaces instead of tabs
2f3b5f7a Corrected replaced unevaluated with additoinalProperties
40bcb8b3 Corrected replaced unevaluated with additoinalProperties
fa9224d7 Merge pull request #732 from MeastroZI/main2
83bedd5c Changing descriptions
49f73429 fixing tests
e6d6a081 adding more test cases
7e6c9be6 changing descriptions
959aca92 shifting test
605d7d78 Update propertyDependencies.json : test must be tests
deb82824 test for dependentSchema and propertyDependencies with unevaluatedProperties and additionalProperties
ea485124 Merge branch 'json-schema-org:main' into main
64a3e7b3 Merge pull request #721 from json-schema-org/gregsdennis/dynamicref-skips-resources
b9f14e64 Fix $schema in new new test
3d5048e8 Merge pull request #733 from Era-cell/main
4ae14268 Add valid first character to avoid Bidi rule violation
2480edba Update additionalProperties.json formatting it
6aa79c0b Update additionalProperties.json formatting it
3e0139a5 Update tests/draft-next/additionalProperties.json
616240b0 Update tests/draft-next/additionalProperties.json
c5f3e4ea Update tests/draft2020-12/propertyNames.json
964efb8e propertyNames doesn't affect additionalProperties, tests exist already for unevaluatedProps
f08b884c Cases go under additional and unevaluated Properties
99864ff6 added tests for propertyNames with additionalProperties/unevaluatedProperties, also with specification property
3b5782b6 Update ref.json : changing $Ids
546b3561 test for $ref with $recursiveAnchor
57617f25 Merge pull request #726 from Era-cell/main
51fc69cd meta data and property names constraints added, additional Items: string
9b169bed specification takes array of objects having section and quote
1362a8cc Pattern for para corrected
340116ec Schema of specification in much structured
003ac021 Test-schema including sub-schema for scpecification
50a20280 adding specification enhancement for additionalProperties
604f5f99 Drop tests of `$id` and `$anchor` that just test values against meta-schema `pattern` for those properties
9cd64ec9 come on man, save all the files
f494440e use unique $id in optional tests, too
468453b0 use unique $id
9ec6d17e fix copy/paste error
b284f423 add tests for $dynamicRef skipping over resources

git-subtree-dir: JSON-Schema-Test-Suite
git-subtree-split: 9fc880bfb6d8ccd093bc82431f17d13681ffae8e
  • Loading branch information
davishmcclurg committed May 29, 2024
1 parent f3f81e3 commit 7035056
Show file tree
Hide file tree
Showing 36 changed files with 869 additions and 755 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/pr-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Check PR Dependencies

on: pull_request

jobs:
check_dependencies:
runs-on: ubuntu-latest
name: Check Dependencies
steps:
- uses: gregsdennis/dependencies-action@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/show_specification_annotations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Show Specification Annotations

on:
pull_request:
paths:
- 'tests/**'

jobs:
annotate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Generate Annotations
run: pip install uritemplate && bin/annotate-specification-links
115 changes: 115 additions & 0 deletions bin/annotate-specification-links
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env python3
"""
Annotate pull requests to the GitHub repository with links to specifications.
"""

from __future__ import annotations

from pathlib import Path
from typing import Any
import json
import re
import sys

from uritemplate import URITemplate


BIN_DIR = Path(__file__).parent
TESTS = BIN_DIR.parent / "tests"
URLS = json.loads(BIN_DIR.joinpath("specification_urls.json").read_text())


def urls(version: str) -> dict[str, URITemplate]:
"""
Retrieve the version-specific URLs for specifications.
"""
for_version = {**URLS["json-schema"][version], **URLS["external"]}
return {k: URITemplate(v) for k, v in for_version.items()}


def annotation(
path: Path,
message: str,
line: int = 1,
level: str = "notice",
**kwargs: Any,
) -> str:
"""
Format a GitHub annotation.
See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
for full syntax.
"""

if kwargs:
additional = "," + ",".join(f"{k}={v}" for k, v in kwargs.items())
else:
additional = ""

relative = path.relative_to(TESTS.parent)
return f"::{level} file={relative},line={line}{additional}::{message}\n"


def line_number_of(path: Path, case: dict[str, Any]) -> int:
"""
Crudely find the line number of a test case.
"""
with path.open() as file:
description = case["description"]
return next(
(i + 1 for i, line in enumerate(file, 1) if description in line),
1,
)


def main():
# Clear annotations which may have been emitted by a previous run.
sys.stdout.write("::remove-matcher owner=me::\n")

for version in TESTS.iterdir():
if version.name in {"draft-next", "latest"}:
continue

version_urls = urls(version.name)

for path in version.rglob("*.json"):
try:
contents = json.loads(path.read_text())
except json.JSONDecodeError as error:
error = annotation(
level="error",
path=path,
line=error.lineno,
col=error.pos + 1,
title=str(error),
)
sys.stdout.write(error)

for test_case in contents:
specifications = test_case.get("specification")
if specifications is not None:
for each in specifications:
quote = each.pop("quote", "")
(kind, section), = each.items()

number = re.search(r"\d+", kind)
spec = "" if number is None else number.group(0)

url = version_urls[kind].expand(
spec=spec,
section=section,
)

message = f"{url}\n\n{quote}" if quote else url
sys.stdout.write(
annotation(
path=path,
line=line_number_of(path, test_case),
title="Specification Link",
message=message,
),
)


if __name__ == "__main__":
main()
34 changes: 34 additions & 0 deletions bin/specification_urls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"json-schema": {
"draft2020-12": {
"core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-{section}",
"validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-{section}"
},
"draft2019-09": {
"core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.{section}",
"validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.{section}"
},
"draft7": {
"core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.{section}",
"validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.{section}"
},
"draft6": {
"core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.{section}",
"validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.{section}"
},
"draft4": {
"core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.{section}",
"validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.{section}"
},
"draft3": {
"core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf"
}
},

"external": {
"ecma262": "https://262.ecma-international.org/{section}",
"perl5": "https://perldoc.perl.org/perlre#{section}",
"rfc": "https://www.rfc-editor.org/rfc/{spec}.txt#{section}",
"iso": "https://www.iso.org/obp/ui"
}
}
63 changes: 63 additions & 0 deletions test-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,69 @@
"type": "array",
"items": { "$ref": "#/$defs/test" },
"minItems": 1
},
"specification":{
"description": "A reference to a specification document which defines the behavior tested by this test case. Typically this should be a JSON Schema specification document, though in cases where the JSON Schema specification points to another RFC it should contain *both* the portion of the JSON Schema specification which indicates what RFC (and section) to follow as *well* as information on where in that specification the behavior is specified.",

"type": "array",
"minItems": 1,
"uniqueItems": true,
"items":{
"properties": {
"core": {
"description": "A section in official JSON Schema core drafts",
"url": "https://json-schema.org/specification-links",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type":"string"
},
"validation": {
"description": "A section in official JSON Schema validation drafts",
"url": "https://json-schema.org/specification-links",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type":"string"
},
"ecma262": {
"description": "A section in official ECMA 262 specification for defining regular expressions",
"url": "https://262.ecma-international.org/",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type":"string"
},
"perl5": {
"description": "A section name in Perl documentation for defining regular expressions",
"url": "https://perldoc.perl.org/perlre",
"type":"string"
},
"quote": {
"description": "Quote describing the test case",
"type":"string"
}
},
"patternProperties": {
"^rfc\\d+$": {
"description": "A section in official RFC for the given rfc number",
"url": "https://www.rfc-editor.org/",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type":"string"
},
"^iso\\d+$": {
"description": "A section in official ISO for the given iso number",
"pattern": "^[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)*$",
"type": "string"
}
},
"additionalProperties": { "type": "string" },
"minProperties": 1,
"propertyNames": {
"oneOf": [
{
"pattern": "^((iso)|(rfc))[0-9]+$"
},
{
"enum": [ "core", "validation", "ecma262", "perl5", "quote" ]
}
]
}
}
}
},
"additionalProperties": false
Expand Down
92 changes: 92 additions & 0 deletions tests/draft-next/additionalProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,97 @@
"valid": true
}
]
},
{
"description": "additionalProperties with propertyNames",
"schema": {
"$schema": "https://json-schema.org/draft/next/schema",
"propertyNames": {
"maxLength": 5
},
"additionalProperties": {
"type": "number"
}
},
"tests": [
{
"description": "Valid against both keywords",
"data": { "apple": 4 },
"valid": true
},
{
"description": "Valid against propertyNames, but not additionalProperties",
"data": { "fig": 2, "pear": "available" },
"valid": false
}
]
},
{
"description": "propertyDependencies with additionalProperties",
"schema": {
"$schema": "https://json-schema.org/draft/next/schema",
"properties" : {"foo2" : {}},
"propertyDependencies": {
"foo" : {},
"foo2": {
"bar": {
"properties": {
"buz": {}
}
}
}
},
"additionalProperties": false
},
"tests": [
{
"description": "additionalProperties doesn't consider propertyDependencies properties" ,
"data": {"foo": ""},
"valid": false
},
{
"description": "additionalProperties can't see buz even when foo2 is present",
"data": {"foo2": "bar", "buz": ""},
"valid": false
},
{
"description": "additionalProperties can't see buz",
"data": {"buz": ""},
"valid": false
}
]
},
{
"description": "dependentSchemas with additionalProperties",
"schema": {
"$schema": "https://json-schema.org/draft/next/schema",
"properties": {"foo2": {}},
"dependentSchemas": {
"foo": {},
"foo2": {
"properties": {
"bar": {}
}
}
},
"additionalProperties": false
},
"tests": [
{
"description": "additionalProperties doesn't consider dependentSchemas",
"data": {"foo": ""},
"valid": false
},
{
"description": "additionalProperties can't see bar",
"data": {"bar": ""},
"valid": false
},
{
"description": "additionalProperties can't see bar even when foo2 is present",
"data": {"foo2": "", "bar": ""},
"valid": false
}
]
}
]
24 changes: 0 additions & 24 deletions tests/draft-next/anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,5 @@
"valid": false
}
]
},
{
"description": "invalid anchors",
"schema": {
"$schema": "https://json-schema.org/draft/next/schema",
"$ref": "https://json-schema.org/draft/next/schema"
},
"tests": [
{
"description": "MUST start with a letter (and not #)",
"data": { "$anchor" : "#foo" },
"valid": false
},
{
"description": "JSON pointers are not valid",
"data": { "$anchor" : "/a/b" },
"valid": false
},
{
"description": "invalid with valid beginning",
"data": { "$anchor" : "foo#something" },
"valid": false
}
]
}
]
Loading

0 comments on commit 7035056

Please sign in to comment.