JSON Schema Generator¶
-
class besser.generators.json.json_schema_generator.JSONSchemaGenerator(model: DomainModel, output_dir: str =
None, mode: str ='regular')[source]¶ Bases:
GeneratorInterfaceJSONSchemaGenerator is a class that implements the GeneratorInterface and is responsible for generating JSONSchema code based on B-UML models.
- Parameters:¶
model (DomainModel) – An instance of the DomainModel class representing the B-UML model.
output_dir (str, optional) – The output directory where the generated code will be saved. Defaults to None.
mode (str, optional) – The generation mode, either ‘regular’ or ‘smart_data’. Defaults to ‘regular’.
-
TYPES =
{'bool': 'boolean', 'date': 'string', 'datetime': 'string', 'float': 'number', 'int': 'integer', 'str': 'string'}¶
-
regenerable =
True¶
- _get_property_type(property_type)[source]¶
Maps B-UML types to JSON schema types and returns format when needed.
- _get_property_description(attr, prop_type)[source]¶
Generate proper description format for Smart Data Models.
- _prepare_smart_data_schema_for_class(class_def)[source]¶
Prepares schema data for Smart Data format for a specific class.
- _prepare_schema()[source]¶
Builds the regular-mode schema: one entry per class under both
propertiesanddefinitions, plus the enumerations.
- generate()[source]¶
Generates JSONSchema code based on the provided B-UML model and saves it to the specified output directory. If the output directory was not specified, the code generated will be stored in the <current directory>/output folder.
- Returns:¶
None, but store the generated code as a file
- generate_example(schema_str)[source]¶
Generates an example JSON based on the rendered schema string.
- generate_normalized_example(base_example)[source]¶
Generate NGSI v2 normalized example.
- generate_jsonld_example(base_example)[source]¶
Generate JSON-LD example.
- generate_normalized_jsonld_example(base_example)[source]¶
Generate NGSI-LD normalized example.
-
static tojson_ordered(value, indent=
4, base_indent=0)[source]¶ Serializes ordered JSON with additional indentation only for internal lines, keeping the first line without extra indentation.
-
_abc_impl =
<_abc._abc_data object>¶
- besser.generators.json.json_schema_generator.extract_example_and_type(prop, details)[source]¶
Infer NGSI type and value based on JSON schema, handling anyOf, array, and formats.