Skip to content

Commit c329f12

Browse files
committed
tests
Signed-off-by: Clemens Vasters <clemens@vasters.com>
1 parent a3c219e commit c329f12

12 files changed

+3204
-9
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Validate Python Samples
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
validate-samples:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.11.x'
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install pytest
27+
28+
- name: Run tests
29+
run: |
30+
cd samples/py
31+
pytest

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# JSON Structure Primer and Samples
2+
3+
This repository contains a primer and sample implementations for the JSON
4+
Structure specification. The content in this repository is not part of the
5+
official JSON Structure specification, but is provided as a reference for
6+
implementers and users of the specification.
7+
8+
## Primer
9+
10+
The primer provides an introduction to the JSON Structure specification and why
11+
it has been created in the first place. The primer is a good place to start if
12+
you are new to JSON Structure and illustrates many of the concepts using
13+
examples.
14+
15+
[Read the primer](./json-structure-primer.md)
16+
17+
## Presentation
18+
19+
The introductory presentation gives a high-level overview of the JSON
20+
Structure specification and its goals. It is a good starting point for
21+
understanding the motivation behind JSON Structure and its key features.
22+
23+
[View the presentation](./presentations/JSON%20Structure.pdf) (PDF)
24+
[Borrow the presentation content](./presentations/JSON%20Structure.pptx) (PPTX)
25+
26+
## Samples
27+
28+
The samples folder contains sample implementations and associated test suites
29+
targeting the JSON Structure Core specification.
30+
31+
### Python
32+
33+
The [samples/py](./samples/py) folder contains sample Python implementations for
34+
validation of JSON Structure schema documents and JSON documents against JSON
35+
Structure schemas. The Python samples include a command-line tool for schema
36+
validation and a validator for JSON document instances.

json-structure-primer.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,11 @@ the `$uses` attribute to activate the companion specification for the schema
707707
document.
708708

709709
The feature identifiers for the companion specifications are:
710-
- `Altnames`: Alternate names and descriptions for properties and types.
711-
- `Units`: Symbols, scientific units, and currencies for numeric properties.
712-
- `Conditionals`: Conditional composition and validation rules.
713-
- `Imports`: Importing types from other schema documents.
714-
- `Validation`: Validation rules for JSON data.
710+
- `JSONStructureAlternateNames`: Alternate names and descriptions for properties and types.
711+
- `JSONStructureUnits`: Symbols, scientific units, and currencies for numeric properties.
712+
- `JSONStructureImports`: Importing types from other schema documents.
713+
- `JSONStructureValidation`: Validation rules for JSON data.
714+
- `JSONStructureConditionalComposition`: Conditional composition and validation rules.
715715

716716
### 5.1. Example: Using the `altnames` Keyword
717717

@@ -725,7 +725,7 @@ Here is an example of how to use the `altnames` keyword:
725725
```json
726726
{
727727
"$schema": "https://json-structure.github.io/meta/extended/v0/#",
728-
"$uses": ["Altnames"],
728+
"$uses": ["JSONStructureAlternateNames"],
729729
"Person": {
730730
"type": "object",
731731
"altnames": {
@@ -780,7 +780,7 @@ Here is an example of how to use the `altenums` keyword:
780780
```json
781781
{
782782
"$schema": "https://json-structure.github.io/meta/extended/v0/#",
783-
"$uses": ["Altnames"],
783+
"$uses": ["JSONStructureAlternateNames"],
784784
"type": "object",
785785
"name": "Color",
786786
"properties": {
@@ -823,7 +823,7 @@ Here is an example of how to use the `unit` keyword:
823823
```json
824824
{
825825
"$schema": "https://json-structure.github.io/meta/extended/v0/#",
826-
"$uses": ["Units"],
826+
"$uses": ["JSONStructureUnits"],
827827
"type": "object",
828828
"name": "Pressure",
829829
"properties": {
@@ -849,7 +849,7 @@ Here is an example of how to use the `currency` keyword:
849849
```json
850850
{
851851
"$schema": "https://json-structure.github.io/meta/extended/v0/#",
852-
"$uses": ["Units"],
852+
"$uses": ["JSONStructureUnits"],
853853
"type": "object",
854854
"name": "Price",
855855
"properties": {

presentations/JSON Structure.pdf

246 KB
Binary file not shown.

presentations/JSON Structure.pptx

5.18 MB
Binary file not shown.

samples/py/.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Distribution / packaging
7+
dist/
8+
build/
9+
*.egg-info/
10+
11+
# Virtual environments
12+
venv/
13+
env/
14+
.env/
15+
.venv/
16+
17+
# IDE specific files
18+
.idea/
19+
.vscode/
20+
*.swp
21+
*.swo
22+
23+
# Unit test / coverage reports
24+
htmlcov/
25+
.tox/
26+
.coverage
27+
.coverage.*
28+
.cache
29+
coverage.xml
30+
*.cover
31+
32+
# Jupyter Notebook
33+
.ipynb_checkpoints
34+
35+
# Local development settings
36+
.env
37+
.env.local
38+
39+
# Logs
40+
*.log

samples/py/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# JSON Structure Python Samples & Tools
2+
3+
This folder contains sample Python implementations and associated pytest-based
4+
test suites targeting the JSON Structure Core specification.
5+
6+
## Contents
7+
8+
- **json_structure_schema_validator.py**
9+
A command-line tool that validates JSON schemas according to the JSON
10+
Structure specification. It supports all extension specifications when enabled and also allows validating extension metadata schemas that introduce new `$`-prefixed keywords in property names (when enabled via `--metaschema`).
11+
12+
- **json_structure_instance_validator.py**
13+
A validator for JSON document instances against JSON Structure schemas.
14+
It supports all core constructs including abstract types, `$extends`,
15+
`$offers/$uses`, conditional composition, and additional validation addins.
16+
17+
## Test Suites
18+
19+
- **test_json_schema_validator_core.py**
20+
Test cases ensuring full code coverage of the schema validator, verifying
21+
valid and invalid schema cases.
22+
23+
- **test_json_validator_core.py**
24+
Test cases for the instance validator across a variety of JSON types, compound
25+
types, conditional rules, and addin constraints.
26+
27+
- **test_import.py**
28+
A dedicated test for JSON Structure Import support, using temporary files and
29+
an import map to simulate external schema resolution.
30+
31+
## Usage
32+
33+
1. **Schema Validation:**
34+
Run the schema validator via the command line:
35+
```
36+
python json_structure_schema_validator.py [--metaschema] [--allowimport] [--importmap URI=filename ...] <path_to_json_file>
37+
```
38+
- Use `--metaschema` to allow `$` in property names.
39+
- Use `--allowimport` and `--importmap` to enable external imports.
40+
41+
2. **Instance Validation:**
42+
Validate an instance file against a schema by running:
43+
```
44+
python json_structure_instance_validator.py <schema_file> <instance_file>
45+
```
46+
47+
3. **Running Tests:**
48+
Use pytest to run all tests:
49+
```
50+
pytest
51+
```
52+

0 commit comments

Comments
 (0)