scjson 0.2.0__tar.gz → 0.2.2__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. {scjson-0.2.0/scjson.egg-info → scjson-0.2.2}/PKG-INFO +1 -1
  2. {scjson-0.2.0 → scjson-0.2.2}/pyproject.toml +1 -1
  3. {scjson-0.2.0 → scjson-0.2.2}/scjson/cli.py +3 -2
  4. {scjson-0.2.0 → scjson-0.2.2}/scjson/jinja_gen.py +25 -2
  5. {scjson-0.2.0 → scjson-0.2.2/scjson.egg-info}/PKG-INFO +1 -1
  6. {scjson-0.2.0 → scjson-0.2.2}/LEGAL.md +0 -0
  7. {scjson-0.2.0 → scjson-0.2.2}/LICENSE +0 -0
  8. {scjson-0.2.0 → scjson-0.2.2}/MANIFEST.in +0 -0
  9. {scjson-0.2.0 → scjson-0.2.2}/README.md +0 -0
  10. {scjson-0.2.0 → scjson-0.2.2}/scjson/CaseStyle.py +0 -0
  11. {scjson-0.2.0 → scjson-0.2.2}/scjson/SCXMLDocumentHandler.py +0 -0
  12. {scjson-0.2.0 → scjson-0.2.2}/scjson/__init__.py +0 -0
  13. {scjson-0.2.0 → scjson-0.2.2}/scjson/__main__.py +0 -0
  14. {scjson-0.2.0 → scjson-0.2.2}/scjson/dataclasses/__init__.py +0 -0
  15. {scjson-0.2.0 → scjson-0.2.2}/scjson/dataclasses/generated.py +0 -0
  16. {scjson-0.2.0 → scjson-0.2.2}/scjson/dataclasses_strict/__init__.py +0 -0
  17. {scjson-0.2.0 → scjson-0.2.2}/scjson/dataclasses_strict/generated.py +0 -0
  18. {scjson-0.2.0 → scjson-0.2.2}/scjson/pydantic/__init__.py +0 -0
  19. {scjson-0.2.0 → scjson-0.2.2}/scjson/pydantic/generated.py +0 -0
  20. {scjson-0.2.0 → scjson-0.2.2}/scjson/pydantic_strict/__init__.py +0 -0
  21. {scjson-0.2.0 → scjson-0.2.2}/scjson/pydantic_strict/generated.py +0 -0
  22. {scjson-0.2.0 → scjson-0.2.2}/scjson.egg-info/SOURCES.txt +0 -0
  23. {scjson-0.2.0 → scjson-0.2.2}/scjson.egg-info/dependency_links.txt +0 -0
  24. {scjson-0.2.0 → scjson-0.2.2}/scjson.egg-info/entry_points.txt +0 -0
  25. {scjson-0.2.0 → scjson-0.2.2}/scjson.egg-info/requires.txt +0 -0
  26. {scjson-0.2.0 → scjson-0.2.2}/scjson.egg-info/top_level.txt +0 -0
  27. {scjson-0.2.0 → scjson-0.2.2}/setup.cfg +0 -0
  28. {scjson-0.2.0 → scjson-0.2.2}/tests/__pycache__/test_cli.cpython-310-pytest-8.4.1.pyc +0 -0
  29. {scjson-0.2.0 → scjson-0.2.2}/tests/test_cli.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scjson
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A JSON-based serialization of SCXML (State Chart XML) for modern tooling, interoperability, and education.
5
5
  Author-email: Ira Abbott <ira@mycloud.blue>
6
6
  License: BSD-1-Clause
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "scjson"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "A JSON-based serialization of SCXML (State Chart XML) for modern tooling, interoperability, and education."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.8"
@@ -188,11 +188,12 @@ def validate(path: Path, recursive: bool):
188
188
  @click.option("--output", "-o", type=click.Path(path_type=Path), help="Output file base.")
189
189
  def typescript(output: Path | None):
190
190
  """Create typescrupt Type files for scjson."""
191
- print(f"Convert Scjson tyoe for typescript - Path: {output}")
191
+ print(f"Convert Scjson type for typescript - Path: {output}")
192
192
  Gen = JinjaGenPydantic(output=output)
193
193
  base_dir = os.path.abspath(output)
194
194
  interfaces = Gen.interfaces
195
- schema = Gen.schemas
195
+ schemas = Gen.schemas
196
+ all_arrays = Gen.all_arrays
196
197
  os.makedirs(base_dir, exist_ok=True)
197
198
  is_runtime = True
198
199
  file_name = "scjsonProps.ts"
@@ -3,6 +3,7 @@ import os
3
3
  from pathlib import Path
4
4
  import importlib
5
5
  import inspect
6
+ from typing import List
6
7
  from enum import Enum
7
8
  from pydantic import BaseModel
8
9
  from jinja2 import Environment, select_autoescape, FileSystemLoader
@@ -35,7 +36,7 @@ class JinjaGenPydantic(object):
35
36
  self.objekts = {}
36
37
  self.schema = {}
37
38
  self.array_types = []
38
- self.env = Environment(loader=FileSystemLoader(my_path),
39
+ self.env = Environment(loader=FileSystemLoader(self.template_path),
39
40
  autoescape=select_autoescape([]),
40
41
  trim_blocks=True,
41
42
  extensions=["jinja2.ext.do"] # This enables {% do %}
@@ -50,6 +51,7 @@ class JinjaGenPydantic(object):
50
51
  self.env.globals.update(str=str)
51
52
  self.env.globals.update( get_field_default=JinjaGenPydantic._get_default_value,
52
53
  get_field_type=JinjaGenPydantic._get_field_type,
54
+ get_schema_types=JinjaGenPydantic._get_schema_types,
53
55
  list_join=JinjaGenPydantic._list_join,
54
56
  is_field_enum=JinjaGenPydantic._is_field_enum,
55
57
  )
@@ -166,6 +168,28 @@ class JinjaGenPydantic(object):
166
168
  # None -> null, integer -> number, else ->
167
169
  return ret_val
168
170
 
171
+ def _get_schema_types(schema: dict, name: str = "") -> List[str]:
172
+ """Template helper to return the reference type from teh schema."""
173
+ t_list = [f'{name}'] if name else []
174
+ for _, prop in schema['properties'].items():
175
+ if "type" in prop:
176
+ if prop["type"].find('$ref') == 0:
177
+ t_list.append(f'{prop["$ref"].split("/")[-1]}[]')
178
+ elif prop["type"] == "array" and "items" in prop:
179
+ if type(prop["items"]) == dict and '$ref' in prop["items"]:
180
+ t_list.append(JinjaGenPydantic._get_field_type(prop["items"])[:-5] + '[]')
181
+ elif "anyOf" in prop:
182
+ for option in prop["anyOf"]:
183
+ if "$ref" in option:
184
+ t_name = f'{option["$ref"].split("/")[-1]}'
185
+ if 'enum' not in schema['$defs'][t_name]:
186
+ t_list.append(t_name)
187
+ elif '$ref' in prop:
188
+ t_name = f'{prop["$ref"].split("/")[-1]}'
189
+ if 'enum' not in schema['$defs'][t_name]:
190
+ t_list.append(t_name)
191
+ return set(t_list)
192
+
169
193
  def _is_field_enum(prop: dict | str, schema: dict) -> bool:
170
194
  "Templat helper function to "
171
195
  ret_val = False
@@ -192,7 +216,6 @@ class JinjaGenPydantic(object):
192
216
  ret_val.append(sep.join(join_list))
193
217
  return ("\n" + indent * " " + sep).join(ret_val)
194
218
 
195
-
196
219
  def _check_props(self, objekt, name) -> bool:
197
220
  """Check for missing props and update from references."""
198
221
  is_ok = True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scjson
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A JSON-based serialization of SCXML (State Chart XML) for modern tooling, interoperability, and education.
5
5
  Author-email: Ira Abbott <ira@mycloud.blue>
6
6
  License: BSD-1-Clause
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