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:
- _abc_impl = <_abc._abc_data object>¶
- _get_property_description(attr, prop_type)[source]¶
Generate proper description format for Smart Data Models.
- Parameters:
attr – The attribute object
prop_type – The JSON schema type
- Returns:
Formatted description
- Return type:
- _get_property_type(property_type)[source]¶
Maps B-UML types to JSON schema types and returns format when needed.
- Parameters:
property_type – The B-UML type to map.
- Returns:
(type, format) where format is None if not applicable
- Return type:
- _prepare_smart_data_schema_for_class(class_def)[source]¶
Prepares schema data for Smart Data format for a specific class.
- Parameters:
class_def – The class to prepare the schema for.
- Returns:
A dictionary containing the schema data.
- Return type:
- 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.
- 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.