generated from Hochfrequenz/python_template_repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tox Env to Create JSON Schemas * Use name of schemas instead of lambdas for recursive schemas See fuhrysteve/marshmallow-jsonschema#164 * prettier json schemas
- Loading branch information
Showing
5 changed files
with
248 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
{ | ||
"$ref": "#/definitions/DeepAnwendungshandbuchSchema", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"AhbMetaInformationSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"pruefidentifikator": { | ||
"title": "pruefidentifikator", | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["pruefidentifikator"], | ||
"type": "object" | ||
}, | ||
"DataElementFreeTextSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"ahb_expression": { | ||
"title": "ahb_expression", | ||
"type": "string" | ||
}, | ||
"data_element_id": { | ||
"title": "data_element_id", | ||
"type": "string" | ||
}, | ||
"discriminator": { | ||
"title": "discriminator", | ||
"type": "string" | ||
}, | ||
"entered_input": { | ||
"title": "entered_input", | ||
"type": ["string", "null"] | ||
}, | ||
"value_type": { | ||
"enum": ["TEXT", "DATETIME", "VALUE_POOL"], | ||
"title": "value_type", | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["ahb_expression", "data_element_id", "discriminator"], | ||
"type": "object" | ||
}, | ||
"DataElementValuePoolSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"data_element_id": { | ||
"title": "data_element_id", | ||
"type": "string" | ||
}, | ||
"discriminator": { | ||
"title": "discriminator", | ||
"type": "string" | ||
}, | ||
"value_pool": { | ||
"items": { | ||
"$ref": "#/definitions/ValuePoolEntrySchema", | ||
"type": "object" | ||
}, | ||
"title": "value_pool", | ||
"type": "array" | ||
}, | ||
"value_type": { | ||
"enum": ["TEXT", "DATETIME", "VALUE_POOL"], | ||
"title": "value_type", | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["data_element_id", "discriminator", "value_pool"], | ||
"type": "object" | ||
}, | ||
"DeepAnwendungshandbuchSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"lines": { | ||
"items": { | ||
"$ref": "#/definitions/SegmentGroupSchema", | ||
"type": "object" | ||
}, | ||
"title": "lines", | ||
"type": "array" | ||
}, | ||
"meta": { | ||
"$ref": "#/definitions/AhbMetaInformationSchema", | ||
"type": "object" | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"SegmentGroupSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"ahb_expression": { | ||
"title": "ahb_expression", | ||
"type": "string" | ||
}, | ||
"discriminator": { | ||
"title": "discriminator", | ||
"type": "string" | ||
}, | ||
"segment_groups": { | ||
"items": { | ||
"$ref": "#/definitions/SegmentGroupSchema", | ||
"type": "object" | ||
}, | ||
"title": "segment_groups", | ||
"type": ["array", "null"] | ||
}, | ||
"segments": { | ||
"items": { | ||
"$ref": "#/definitions/SegmentSchema", | ||
"type": "object" | ||
}, | ||
"title": "segments", | ||
"type": ["array", "null"] | ||
} | ||
}, | ||
"required": ["ahb_expression", "discriminator"], | ||
"type": "object" | ||
}, | ||
"SegmentSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"ahb_expression": { | ||
"title": "ahb_expression", | ||
"type": "string" | ||
}, | ||
"data_elements": { | ||
"items": { | ||
"$ref": "#/definitions/_FreeTextOrValuePoolSchema", | ||
"type": "object" | ||
}, | ||
"title": "data_elements", | ||
"type": "array" | ||
}, | ||
"discriminator": { | ||
"title": "discriminator", | ||
"type": "string" | ||
}, | ||
"section_name": { | ||
"title": "section_name", | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["ahb_expression", "discriminator"], | ||
"type": "object" | ||
}, | ||
"ValuePoolEntrySchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"ahb_expression": { | ||
"title": "ahb_expression", | ||
"type": "string" | ||
}, | ||
"meaning": { | ||
"title": "meaning", | ||
"type": "string" | ||
}, | ||
"qualifier": { | ||
"title": "qualifier", | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["ahb_expression", "meaning", "qualifier"], | ||
"type": "object" | ||
}, | ||
"_FreeTextOrValuePoolSchema": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"free_text": { | ||
"$ref": "#/definitions/DataElementFreeTextSchema", | ||
"type": "object" | ||
}, | ||
"value_pool": { | ||
"$ref": "#/definitions/DataElementValuePoolSchema", | ||
"type": "object" | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## 🐁 JSON Schemas | ||
|
||
This directory contains [JSON Schema Draft v7](https://json-schema.org/specification-links.html#draft-7) compatible JSON | ||
Schemas. You may use these schemas | ||
to [autogenerate classes in the language of your choice](https://json-schema.org/implementations.html#code-generation). | ||
This is thought to reduce manual efforts and allow for easy integration of AHBicht with other components (for example a | ||
frontend). | ||
|
||
### Autogenerate the Schemas using [`marshmallow-jsonschema`](https://github.com/fuhrysteve/marshmallow-jsonschema) | ||
|
||
The files in this directory are autogenerated from the marshmallow classes that are also used for (de-)serialization. | ||
There is a tox environment that executes [`generate_json_schemas.py`](generate_json_schemas.py) and overwrites | ||
any `.json` files in this directory. Simply run: | ||
|
||
```bash | ||
tox -e json_schemas | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
This script is run in the tox 'json_schemas' environment. | ||
It creates json schema files as described in the README.md in the same directory. | ||
""" | ||
|
||
import json | ||
import pathlib | ||
from typing import List, Type | ||
|
||
from marshmallow import Schema | ||
from marshmallow_jsonschema import JSONSchema # type:ignore[import] | ||
|
||
from maus.models.anwendungshandbuch import DeepAnwendungshandbuchSchema | ||
|
||
schema_types: List[Type[Schema]] = [ | ||
DeepAnwendungshandbuchSchema | ||
# add other schemas as you like | ||
] | ||
json_schema = JSONSchema() | ||
for schema_type in schema_types: | ||
this_directory = pathlib.Path(__file__).parent.absolute() | ||
file_name = schema_type.__name__ + ".json" # pylint:disable=invalid-name | ||
file_path = this_directory / file_name | ||
schema_instance = schema_type() | ||
json_schema_dict = json_schema.dump(schema_instance) | ||
|
||
with open(file_path, "w", encoding="utf-8") as json_schema_file: | ||
json.dump(json_schema_dict, json_schema_file, ensure_ascii=False, sort_keys=True, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters