json-schema-utils 0.9.9__tar.gz → 0.9.10.dev5__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.
Files changed (29) hide show
  1. {json_schema_utils-0.9.9/json_schema_utils.egg-info → json_schema_utils-0.9.10.dev5}/PKG-INFO +1 -1
  2. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5/json_schema_utils.egg-info}/PKG-INFO +1 -1
  3. json_schema_utils-0.9.10.dev5/jsutils/VERSION +1 -0
  4. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/convert.py +12 -4
  5. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/scripts.py +18 -9
  6. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/simplify.py +16 -1
  7. json_schema_utils-0.9.9/jsutils/VERSION +0 -1
  8. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/.gitignore +0 -0
  9. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/LICENSE +0 -0
  10. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/MANIFEST.in +0 -0
  11. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/README.md +0 -0
  12. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/json_schema_utils.egg-info/SOURCES.txt +0 -0
  13. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/json_schema_utils.egg-info/dependency_links.txt +0 -0
  14. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/json_schema_utils.egg-info/entry_points.txt +0 -0
  15. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/json_schema_utils.egg-info/not-zip-safe +0 -0
  16. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/json_schema_utils.egg-info/requires.txt +0 -0
  17. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/json_schema_utils.egg-info/top_level.txt +0 -0
  18. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/__init__.py +0 -0
  19. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/inline.py +0 -0
  20. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/recurse.py +0 -0
  21. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/resolver.py +0 -0
  22. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/restruct.py +0 -0
  23. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/schemas.py +0 -0
  24. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/stats.py +0 -0
  25. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/types.py +0 -0
  26. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/utils.py +0 -0
  27. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/jsutils/vocab.py +0 -0
  28. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/pyproject.toml +0 -0
  29. {json_schema_utils-0.9.9 → json_schema_utils-0.9.10.dev5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_schema_utils
3
- Version: 0.9.9
3
+ Version: 0.9.10.dev5
4
4
  Summary: JSON Schema Utils
5
5
  Author: Fabien Coelho, Claire Yannou-Medrala
6
6
  License-Expression: CC0-1.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_schema_utils
3
- Version: 0.9.9
3
+ Version: 0.9.10.dev5
4
4
  Summary: JSON Schema Utils
5
5
  Author: Fabien Coelho, Claire Yannou-Medrala
6
6
  License-Expression: CC0-1.0
@@ -0,0 +1 @@
1
+ 0.9.10
@@ -1068,10 +1068,18 @@ def schema2model(
1068
1068
  props = schema["properties"]
1069
1069
  del schema["properties"]
1070
1070
  for s in lof:
1071
- if "properties" in s:
1072
- s["properties"].update(props)
1073
- else:
1071
+ if "properties" not in s:
1074
1072
  s["properties"] = props
1073
+ else:
1074
+ eprops = s["properties"]
1075
+ assert isinstance(eprops, dict)
1076
+ for p, v in props.items():
1077
+ if p not in eprops:
1078
+ eprops[p] = v
1079
+ elif eprops[p] == v:
1080
+ pass
1081
+ else:
1082
+ eprops[p] = {"allOf": [ eprops[p], v]}
1075
1083
  if "additionalProperties" in schema:
1076
1084
  addprop = schema["additionalProperties"]
1077
1085
  del schema["additionalProperties"]
@@ -1314,7 +1322,7 @@ def schema2model(
1314
1322
  else:
1315
1323
  assert False, f"$ref handling not implemented: {ref}"
1316
1324
  else:
1317
- log.info(f"$ref intermixed with other keywords at [{spath}]")
1325
+ log.info(f"keyword $ref intermixed with other keywords at [{spath}]")
1318
1326
  ao = allOfLayer(schema, "$ref")
1319
1327
  model = schema2model(ao, lid or url, path, defs, strict, fix, False, resilient)
1320
1328
  return buildModel(model, {}, defs, sharp, is_root)
@@ -1,4 +1,5 @@
1
1
  import sys
2
+ import os
2
3
  from typing import Any, Callable
3
4
  import copy
4
5
  import json
@@ -37,7 +38,7 @@ def jsu_version(with_backend: bool = False) -> str:
37
38
  from setuptools_git_versioning import get_version
38
39
  version = str(get_version(root=Path(__file__).parent.parent))
39
40
  except Exception as e:
40
- log.warning(f"error while recompuging version: {e}")
41
+ log.debug(f"error while recomputing version: {e}")
41
42
  pass
42
43
  if with_backend:
43
44
  version += " (jmc backend " + json_model.jmc_version() + ")"
@@ -79,6 +80,16 @@ def rm_suffix(s, *suffixes):
79
80
  return s[:-len(suffix)]
80
81
  return s
81
82
 
83
+ def read_schema(arg: str|None):
84
+ """Read JSON Schema from file name."""
85
+ if arg is None or arg == "-":
86
+ return json.load(sys.stdin)
87
+ for suffix in ("", ".json", ".schema.json"):
88
+ file = arg + suffix
89
+ if os.path.exists(file):
90
+ with open(file) as f:
91
+ return json.load(f)
92
+ raise Exception(f"no such schema: {arg}")
82
93
 
83
94
  def jsu_inline(xargs: list[str]|None = None) -> int:
84
95
  """Inline command entry point."""
@@ -105,7 +116,7 @@ def jsu_inline(xargs: list[str]|None = None) -> int:
105
116
 
106
117
  for fn in args.schemas:
107
118
  log.debug(f"considering file: {fn}")
108
- schema = json.load(open(fn) if fn != "-" else sys.stdin)
119
+ schema = read_schema(fn)
109
120
  if isinstance(schema, bool):
110
121
  inlined = schema
111
122
  elif isinstance(schema, dict):
@@ -155,7 +166,7 @@ def jsu_simpler(xargs: list[str]|None = None) -> int:
155
166
 
156
167
  for fn in args.schemas:
157
168
  log.debug(f"considering file: {fn}")
158
- schema = json.load(open(fn) if fn != "-" else sys.stdin)
169
+ schema = read_schema(fn)
159
170
  if args.type:
160
171
  schema = computeTypes(schema)
161
172
  if isinstance(schema, dict):
@@ -201,8 +212,7 @@ def jsu_check(xargs: list[str]|None = None) -> int:
201
212
  log.setLevel(logging.DEBUG if args.debug else logging.WARNING if args.quiet else logging.INFO)
202
213
 
203
214
  try:
204
- with open(args.schema) if args.schema != "-" else sys.stdin as f:
205
- jschema = json.load(f)
215
+ jschema = read_schema(args.schema)
206
216
  except FileNotFoundError as e:
207
217
  if args.debug:
208
218
  log.error(e, exc_info=args.debug)
@@ -380,7 +390,6 @@ def jsu_stats(xargs: list[str]|None = None) -> int:
380
390
 
381
391
  return 1 if oops else 0
382
392
 
383
-
384
393
  def jsu_pretty(xargs: list[str]|None = None):
385
394
 
386
395
  ap = argparse.ArgumentParser(
@@ -399,7 +408,7 @@ def jsu_pretty(xargs: list[str]|None = None):
399
408
 
400
409
  for fn in args.schemas:
401
410
  log.debug(f"considering file: {fn}")
402
- schema = json.load(open(fn) if fn != "-" else sys.stdin)
411
+ schema = read_schema(fn)
403
412
  print(json_dumps(schema, args))
404
413
 
405
414
  return 0
@@ -466,7 +475,7 @@ def jsu_model(xargs: list[str]|None = None) -> int:
466
475
  for fn in args.schemas:
467
476
  log.debug(f"considering: {fn}")
468
477
  try:
469
- schema = json.load(open(fn) if fn != "-" else sys.stdin)
478
+ schema = read_schema(fn)
470
479
  model = schema_to_model(
471
480
  schema, fn,
472
481
  use_id=args.id, strict=args.strict, fix=args.fix,
@@ -584,7 +593,7 @@ def jsu_compile(xargs: list[str]|None = None) -> int:
584
593
  model = None
585
594
 
586
595
  try:
587
- schema = json.load(open(args.schema) if args.schema != "-" else sys.stdin)
596
+ schema = read_schema(args.schema)
588
597
  resolver = Resolver(cache=args.cache, mapping=args.map)
589
598
  model = schema_to_model(
590
599
  schema, args.schema,
@@ -408,6 +408,8 @@ def simplifySchema(
408
408
  for k, v in subs.items():
409
409
  if k in _IGNORABLE:
410
410
  pass
411
+ elif k in ("if", "then", "else", "not", "allOf", "anyOf", "oneOf", "$ref", "$dynamicRef"):
412
+ compat = False
411
413
  elif k in local and v == local[k]:
412
414
  pass
413
415
  elif k in local:
@@ -418,10 +420,12 @@ def simplifySchema(
418
420
  for n in v:
419
421
  if n not in local["required"]:
420
422
  compat = False
423
+ else:
424
+ compat = False
421
425
  else:
422
426
  compat = False
423
427
  if compat:
424
- log.info(f"removing ineffective {kw}")
428
+ log.info(f"removing ineffective {kw} at {lpath}")
425
429
  del local[kw]
426
430
 
427
431
  # if/then/else
@@ -570,6 +574,15 @@ def simplifySchema(
570
574
  log.info(f"removing useless {kw} keyword at {lpath}")
571
575
  del local[kw]
572
576
 
577
+ # boolean propertyNames
578
+ if "propertyNames" in local:
579
+ pn = local["propertyNames"]
580
+ if isinstance(pn, bool):
581
+ log.info(f"removing useless propertyNames boolean schema at {lpath}")
582
+ del local["propertyNames"]
583
+ if not pn: # empty object
584
+ local["maxProperties"] = 0
585
+
573
586
  # simplify propertyNames + additionalProperties to patternProperties
574
587
  if "propertyNames" in local and "additionalProperties" in local and \
575
588
  "properties" not in local and "patternProperties" not in local:
@@ -583,6 +596,8 @@ def simplifySchema(
583
596
  del local["additionalProperties"]
584
597
  assert isinstance(pn["pattern"], str)
585
598
  local["patternProperties"] = { pn["pattern"]: ap }
599
+ # NOTE: ap is merged into pp, we do not want any other props
600
+ local["additionalProperties"] = False
586
601
 
587
602
  # const/enum
588
603
  if "const" in local and "enum" in local:
@@ -1 +0,0 @@
1
- 0.9.9