Skip to content

Commit

Permalink
Validate version in URI matches version field
Browse files Browse the repository at this point in the history
  • Loading branch information
b-wils committed Jul 12, 2024
1 parent 08486c9 commit 03b66f8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tools/schema-validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import pathlib
import argparse
import math

from schema_tools.schema import SchemaPath, Schema
import lottie_markdown
Expand All @@ -25,6 +26,7 @@ def __init__(self):

def validate(self, schema_root):
self.root = Schema(schema_root, None)
self.check_version(self.root)
self.collect_defs(self.root / "$defs")
self.validate_recursive(self.root)
for unused in (self.expected_refs - self.valid_refs):
Expand Down Expand Up @@ -67,6 +69,18 @@ def collect_defs(self, schema):
else:
self.collect_defs(child)

def check_version(self, schema: Schema):
versionNumber = schema["$version"]

majorVersion = math.floor(versionNumber / 10000)
minorVersion = math.floor((versionNumber % 10000) / 100)
patchVersion = versionNumber % 100

versionString = f'{majorVersion}.{minorVersion}.{patchVersion}'

if versionString not in schema["$id"]:
self.error(schema, "Mismatched URI version - expected: %s" % versionString)

def check_links(self, html_path: pathlib.Path):
checked = set()
file_cache = {}
Expand Down

0 comments on commit 03b66f8

Please sign in to comment.