forked from lpessoa/check-jsonschemas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(230): add validations to json-schemas in some forms
- Draft7Validator - Draft6Validator - Draft4Validator - Draft3Validator - Draft201909Validator - Draft202012Validator
- Loading branch information
1 parent
09a514e
commit 6066663
Showing
20 changed files
with
888 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
covdefaults | ||
coverage | ||
pytest | ||
pytest | ||
jsonschema |
This file contains 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,3 @@ | ||
pytest~=8.2.0 | ||
setuptools~=68.2.0 | ||
jsonschema~=4.22.0 |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import pytest | ||
from pre_commit_hooks.check_json_schemas import main | ||
|
||
|
||
def test_valid_schemas(valid_set_of_files): | ||
for arg in valid_set_of_files: | ||
print(f': [test_valid_schemas] assert if {arg} is a valid schema-file') | ||
assert main([arg]) == 0 | ||
|
||
|
||
def test_all_valid_schema_files(valid_set_of_files): | ||
print(f': [test_all_valid_schema_files] assert if all schema-files are valid') | ||
args = valid_set_of_files | ||
assert main(args) == 0 | ||
|
||
|
||
def test_invalid_schemas(invalid_set_of_files): | ||
for arg in invalid_set_of_files: | ||
print(f': [test_invalid_schemas] assert if {arg} is a invalid schema-file') | ||
assert main([arg]) == 1 | ||
|
||
|
||
def test_all_invalid_schemas(invalid_set_of_files): | ||
print(f': [test_all_invalid_schemas] assert if all schema-files are invalid') | ||
args = invalid_set_of_files | ||
assert main(args) == 1 | ||
|
This file contains 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 |
---|---|---|
@@ -1,23 +1,26 @@ | ||
import pytest | ||
|
||
@pytest.fixture | ||
def build_content(tmp_path): | ||
def inner(contents): | ||
files = [] | ||
count = 0 | ||
for content in contents: | ||
f = tmp_path/ str(count) | ||
f.write_text(content) | ||
files.append(str(f)) | ||
count = count + 1 | ||
return files | ||
return inner | ||
|
||
@pytest.fixture | ||
def valid_set_of_files(build_content): | ||
return build_content(["""{"format": "date-time"}""", """{"format": "date"}"""]) | ||
def valid_set_of_files(): | ||
return [ | ||
"fixtures/valid-schemas/draft-03.json", | ||
"fixtures/valid-schemas/draft-04.json", | ||
"fixtures/valid-schemas/draft-06.json", | ||
"fixtures/valid-schemas/draft-07.json", | ||
"fixtures/valid-schemas/draft-201909.json", | ||
"fixtures/valid-schemas/draft-202012.json", | ||
] | ||
|
||
|
||
@pytest.fixture | ||
def invalid_set_of_files(build_content): | ||
return build_content(["""{"format": "invalid="}"""]) | ||
def invalid_set_of_files(): | ||
return [ | ||
"fixtures/invalid-schemas/without-schema-entry.json", | ||
"fixtures/invalid-schemas/draft-03.json", | ||
"fixtures/invalid-schemas/draft-04.json", | ||
"fixtures/invalid-schemas/draft-06.json", | ||
"fixtures/invalid-schemas/draft-07.json", | ||
"fixtures/invalid-schemas/draft-201909.json", | ||
"fixtures/invalid-schemas/draft-202012.json", | ||
] |
This file contains 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,14 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-03/schema#", | ||
"id": "http://jsonschema.net", | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"id": "http://jsonschema.net/title", | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"title" | ||
] | ||
} |
This file contains 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,12 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"id": "http://jsonschema.net", | ||
"type": "any", | ||
"properties": { | ||
"title": { | ||
"id": "http://jsonschema.net/title", | ||
"type": "string", | ||
"required": true | ||
} | ||
} | ||
} |
This file contains 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,12 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-06/schema#", | ||
"id": "http://jsonschema.net", | ||
"type": "any", | ||
"properties": { | ||
"title": { | ||
"id": "http://jsonschema.net/title", | ||
"type": "string", | ||
"required": true | ||
} | ||
} | ||
} |
This file contains 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,12 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"id": "http://jsonschema.net", | ||
"type": "any", | ||
"properties": { | ||
"title": { | ||
"id": "http://jsonschema.net/title", | ||
"type": "string", | ||
"required": true | ||
} | ||
} | ||
} |
This file contains 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,12 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2019-09/schema", | ||
"id": "http://jsonschema.net", | ||
"type": "any", | ||
"properties": { | ||
"title": { | ||
"id": "http://jsonschema.net/title", | ||
"type": "string", | ||
"required": true | ||
} | ||
} | ||
} |
This file contains 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,27 @@ | ||
{ | ||
"$id": "https://jsoneditoronline.org/friends.schema.json", | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"title": "Friends", | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "The friend's name." | ||
}, | ||
"age": { | ||
"description": "Age in years which must be equal to or greater than zero.", | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"email": { | ||
"type": "string", | ||
"format": "email", | ||
"description": "Optional email address of the friend.", | ||
"required": true | ||
} | ||
}, | ||
"required": ["name", "age"] | ||
} | ||
} |
This file contains 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,13 @@ | ||
{ | ||
"id": "http://jsonschema.net", | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"id": "http://jsonschema.net/title", | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"title" | ||
] | ||
} |
Oops, something went wrong.