From c167c887d4dbb5774a478e6b4b1173027724bd0b Mon Sep 17 00:00:00 2001 From: Brandon Wilson Date: Tue, 27 Feb 2024 15:06:19 -0500 Subject: [PATCH] Also create a strict version of the schema --- .gitignore | 1 + Makefile | 12 +++++++++++- docs/specs/schema.md | 3 +++ tools/schema-merge.py | 6 ++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 754a1fb..71712c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ docs/lottie.schema.json +docs/lottie-strict.schema.json site/ __pycache__ diff --git a/Makefile b/Makefile index 476b44b..3da3cc0 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/docs/specs/schema.md b/docs/specs/schema.md index 8c59837..94a9ff4 100644 --- a/docs/specs/schema.md +++ b/docs/specs/schema.md @@ -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} diff --git a/tools/schema-merge.py b/tools/schema-merge.py index b44a813..c993b44 100755 --- a/tools/schema-merge.py +++ b/tools/schema-merge.py @@ -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 @@ -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)