Skip to content

Commit

Permalink
Also create a strict version of the schema
Browse files Browse the repository at this point in the history
  • Loading branch information
b-wils committed Feb 27, 2024
1 parent 889313a commit c167c88
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
docs/lottie.schema.json
docs/lottie-strict.schema.json
site/
__pycache__

Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SOURCE_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
OUTPUT_DIR ?= $(CURDIR)/site

.SUFFIXES:
.PHONY: all install_dependencies docs docs_serve lottie.schema.json validate validate_links
.PHONY: all install_dependencies docs docs_serve lottie.schema.json lottie-strict.schema.json validate validate_links


all: docs
Expand All @@ -19,21 +19,31 @@ $(SOURCE_DIR)/docs/lottie.schema.json: $(wildcard $(SOURCE_DIR)/schema/**/*.json
$(SOURCE_DIR)/docs/lottie.schema.json: $(SOURCE_DIR)/tools/schema-merge.py
$(SOURCE_DIR)/tools/schema-merge.py

lottie-strict.schema.json:$(SOURCE_DIR)/docs/lottie-strict.schema.json

$(SOURCE_DIR)/docs/lottie-strict.schema.json: $(wildcard $(SOURCE_DIR)/schema/**/*.json)
$(SOURCE_DIR)/docs/lottie-strict.schema.json: $(SOURCE_DIR)/tools/schema-merge.py
$(SOURCE_DIR)/tools/schema-merge.py --output $(SOURCE_DIR)/docs/lottie-strict.schema.json --strict

docs:$(OUTPUT_DIR)/index.html

$(OUTPUT_DIR)/index.html:$(wildcard $(SOURCE_DIR)/docs/**/*)
$(OUTPUT_DIR)/index.html:$(SOURCE_DIR)/docs/lottie.schema.json
$(OUTPUT_DIR)/index.html:$(SOURCE_DIR)/docs/lottie-strict.schema.json
$(OUTPUT_DIR)/index.html:$(SOURCE_DIR)/tools/lottie_markdown.py
$(MKDOCS) build -f $(SOURCE_DIR)/mkdocs.yml -d $(OUTPUT_DIR)

docs_serve:$(SOURCE_DIR)/docs/lottie.schema.json
docs_serve:$(SOURCE_DIR)/docs/lottie-strict.schema.json
$(MKDOCS) serve -f $(SOURCE_DIR)/mkdocs.yml

install_dependencies:
$(PIP) install -r $(SOURCE_DIR)/tools/requirements.txt

validate: $(SOURCE_DIR)/docs/lottie.schema.json
validate: $(SOURCE_DIR)/docs/lottie-strict.schema.json
$(SOURCE_DIR)/tools/schema-validate.py
$(SOURCE_DIR)/tools/schema-validate.py --schema $(SOURCE_DIR)/docs/lottie-strict.schema.json


validate_full:$(OUTPUT_DIR)/index.html
Expand Down
3 changes: 3 additions & 0 deletions docs/specs/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ values to jump to the relevant section.

If you want you can also view the [raw schema file](../lottie.schema.json).

There is also a [strict schema file](../lottie-strict.schema.json)
that disallows properties not covered in the specification.

{json_file}
6 changes: 6 additions & 0 deletions tools/schema-merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def join_parts(
print(file_item)
raise
file_schema.pop("$schema", None)
if strict and 'type' in file_schema and file_schema['type'] == "object":
file_schema["unevaluatedProperties"] = False
dir_schema[file_item.stem] = file_schema
defs[subdir.name] = dir_schema

Expand Down Expand Up @@ -52,11 +54,15 @@ def join_parts(
default=root / "docs" / "lottie.schema.json",
help="Output file name"
)
parser.add_argument('--strict', dest='strict', action='store_true')
parser.add_argument('--not-strict', dest='strict', action='store_false')
parser.set_defaults(strict=False)

args = parser.parse_args()
input_dir: pathlib.Path = args.input.resolve()
output_path: pathlib.Path = args.output
root_path: pathlib.Path = (input_dir / args.root).resolve()
strict = args.strict

with open(root_path) as file:
json_data = json.load(file)
Expand Down

0 comments on commit c167c88

Please sign in to comment.