Coverage for schemas / __init__.py: 0%
24 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-22 07:15 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-22 07:15 +0000
1import json
2import pathlib
3from importlib.resources import files
5from formkit_ninja import schemas as schema_path
6from formkit_ninja.formkit_schema import FormKitNode
9class Schemas:
10 def __init__(self):
11 # All json files
12 schema_files: list[pathlib.Path] = list(files(schema_path).glob("*.json"))
13 # Name of the schema: path
14 schemas = {path_.name[:-5]: path_ for path_ in schema_files}
15 self.schemas = schemas
17 def list_schemas(self) -> list[str]:
18 return self.schemas.keys()
20 def as_text(self, schema: str):
21 return self.schemas[schema].read_text()
23 def as_json(self, schema: str) -> dict:
24 return json.loads(self.as_text(schema))
26 def as_dict(self, schema: str):
27 return json.dumps(self.as_json(schema))
29 def import_all(self):
30 from formkit_ninja.models import FormKitSchemaNode
32 for schema in self.schemas.keys():
33 node: FormKitNode = FormKitNode.parse_obj(self.as_json(schema))
34 parsed_node = node.__root__
35 list(FormKitSchemaNode.from_pydantic(parsed_node))[0]