json-schema-utils 0.8.2__tar.gz → 0.8.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/PKG-INFO +1 -1
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/json_schema_utils.egg-info/PKG-INFO +1 -1
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/jsutils/convert.py +15 -3
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/jsutils/scripts.py +33 -4
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/pyproject.toml +1 -1
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/.gitignore +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/LICENSE +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/MANIFEST.in +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/Makefile +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/README.md +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/json_schema_utils.egg-info/SOURCES.txt +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/json_schema_utils.egg-info/dependency_links.txt +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/json_schema_utils.egg-info/entry_points.txt +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/json_schema_utils.egg-info/requires.txt +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/json_schema_utils.egg-info/top_level.txt +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/jsutils/__init__.py +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/jsutils/inline.py +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/jsutils/recurse.py +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/jsutils/schemas.py +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/jsutils/simplify.py +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/jsutils/stats.py +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/jsutils/utils.py +0 -0
- {json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/setup.cfg +0 -0
|
@@ -10,6 +10,18 @@ type JsonPath = list[str|int]
|
|
|
10
10
|
log = logging.getLogger("convert")
|
|
11
11
|
# log.setLevel(logging.DEBUG)
|
|
12
12
|
|
|
13
|
+
def tname(v) -> str:
|
|
14
|
+
return (
|
|
15
|
+
"null" if v is None else
|
|
16
|
+
"bool" if isinstance(v, bool) else
|
|
17
|
+
"int" if isinstance(v, int) else
|
|
18
|
+
"number" if isinstance(v, float) else
|
|
19
|
+
"string" if isinstance(v, str) else
|
|
20
|
+
"array" if isinstance(v, list) else
|
|
21
|
+
"object" if isinstance(v, dict) else
|
|
22
|
+
"UNKNOWN"
|
|
23
|
+
)
|
|
24
|
+
|
|
13
25
|
#
|
|
14
26
|
# BEST EFFORT SCHEMA TO MODEL CONVERSION
|
|
15
27
|
#
|
|
@@ -820,15 +832,15 @@ def schema2model(schema, path: JsonPath = [],
|
|
|
820
832
|
if "minProperties" in schema and "maxProperties" in schema and \
|
|
821
833
|
schema["minProperties"] == schema["maxProperties"]:
|
|
822
834
|
ival = schema["maxProperties"]
|
|
823
|
-
assert isinstance(ival, int), f"int # props at [{spath}]"
|
|
835
|
+
assert isinstance(ival, int), f"int # props at [{spath}] ({tname(ival)})"
|
|
824
836
|
else:
|
|
825
837
|
if "minProperties" in schema:
|
|
826
838
|
mini = schema["minProperties"]
|
|
827
|
-
assert type(mini) is int, f"int min props at [{spath}]"
|
|
839
|
+
assert type(mini) is int, f"int min props at [{spath}] ({tname(mini)})"
|
|
828
840
|
constraints[">="] = mini
|
|
829
841
|
if "maxProperties" in schema:
|
|
830
842
|
maxi = schema["maxProperties"]
|
|
831
|
-
assert type(maxi) is int, f"int max props at [{spath}]"
|
|
843
|
+
assert type(maxi) is int, f"int max props at [{spath}] ({tname(maxi)})"
|
|
832
844
|
constraints["<="] = maxi
|
|
833
845
|
|
|
834
846
|
if "patternProperties" in schema:
|
|
@@ -10,8 +10,8 @@ from importlib.metadata import version as pkg_version
|
|
|
10
10
|
logging.basicConfig()
|
|
11
11
|
|
|
12
12
|
from .schemas import Schemas
|
|
13
|
-
from .utils import log, JSUError
|
|
14
|
-
from .recurse import hasDirectRef
|
|
13
|
+
from .utils import log, JSUError, JsonSchema
|
|
14
|
+
from .recurse import hasDirectRef, recurseSchema
|
|
15
15
|
from .inline import inlineRefs
|
|
16
16
|
from .simplify import simplifySchema, scopeDefs
|
|
17
17
|
from .stats import json_schema_stats, json_metrics, normalize_ods
|
|
@@ -169,7 +169,7 @@ def jsu_check():
|
|
|
169
169
|
try:
|
|
170
170
|
if args.engine == "jschon":
|
|
171
171
|
import jschon
|
|
172
|
-
jschon.create_catalog(args.
|
|
172
|
+
jschon.create_catalog(args.draft)
|
|
173
173
|
schema = jschon.JSONSchema(jschema)
|
|
174
174
|
|
|
175
175
|
def check(data):
|
|
@@ -342,9 +342,38 @@ ID2MODEL: dict[str, tuple[str, str]] = {
|
|
|
342
342
|
"https://spec.openapis.org/oas/3.1/schema/2022-10-07": (
|
|
343
343
|
f"{JM}/openapi-311.model.json",
|
|
344
344
|
f"{JM}/openapi-311.model.json", # TODO fuzzy
|
|
345
|
+
),
|
|
346
|
+
"sha3:58df1e36909f3f8033f4da3e9a6179f3d3e53c51501d7f14a557e34ecef988e1": (
|
|
347
|
+
f"{JM}/cypress.model.json",
|
|
348
|
+
f"{JM}/cypress.model.json",
|
|
345
349
|
)
|
|
346
350
|
}
|
|
347
351
|
|
|
352
|
+
# generate an id
|
|
353
|
+
def schema2id(schema: JsonSchema) -> str:
|
|
354
|
+
|
|
355
|
+
# copy
|
|
356
|
+
schema = copy.deepcopy(schema)
|
|
357
|
+
|
|
358
|
+
# cleanup non essential stuff
|
|
359
|
+
def nocomment(schema: JsonSchema, _: list[str]) -> bool:
|
|
360
|
+
if isinstance(schema, dict):
|
|
361
|
+
for p in ("$comment", "title", "description", "default",
|
|
362
|
+
"examples", "readOnly", "writeOnly", "deprecated"):
|
|
363
|
+
if p in schema:
|
|
364
|
+
del schema[p]
|
|
365
|
+
return True
|
|
366
|
+
return False
|
|
367
|
+
|
|
368
|
+
recurseSchema(schema, "", flt=nocomment)
|
|
369
|
+
|
|
370
|
+
# hash serialized json
|
|
371
|
+
serial = json.dumps(schema, sort_keys=True)
|
|
372
|
+
shid = "sha3:" + hashlib.sha3_256(serial.encode("UTF-8")).hexdigest()
|
|
373
|
+
|
|
374
|
+
log.info(f"schema id: {shid}")
|
|
375
|
+
return shid
|
|
376
|
+
|
|
348
377
|
# add ~# versions
|
|
349
378
|
for k in list(ID2MODEL.keys()):
|
|
350
379
|
if k.endswith("/schema"):
|
|
@@ -385,7 +414,7 @@ def jsu_model():
|
|
|
385
414
|
if args.id and isinstance(schema, dict):
|
|
386
415
|
sid = (schema["$id"] if "$id" in schema else
|
|
387
416
|
schema["id"] if "id" in schema else
|
|
388
|
-
|
|
417
|
+
schema2id(schema))
|
|
389
418
|
if sid in ID2MODEL:
|
|
390
419
|
log.info(f"using predefined model for {sid}")
|
|
391
420
|
model = f"${ID2MODEL[sid][0 if args.strict else 1]}"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/json_schema_utils.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/json_schema_utils.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{json_schema_utils-0.8.2 → json_schema_utils-0.8.4}/json_schema_utils.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|