Pydantic Generator#

class besser.generators.pydantic_classes.pydantic_classes_generator.PydanticGenerator(model: DomainModel, backend: bool = False, nested_creations: bool = False, output_dir: str = None)[source]#

Bases: GeneratorInterface

PydanticGenerator is a class that implements the GeneratorInterface and is responsible for generating the Python domain model code based on the input B-UML model.

Parameters:
  • model (DomainModel) – An instance of the DomainModel class representing the B-UML model.

  • backend (bool, optional) – A boolean flag indicating whether the generator should generate code for a backend API.

  • nested_creations (bool, optional) – This parameter determines how entities are linked in the API request. If set to True, both nested creations and linking by the ID of the entity are enabled. If set to False, only the ID of the linked entity will be used. The default value is False.

  • output_dir (str, optional) – The output directory where the generated code will be saved. Defaults to None.

_abc_impl = <_abc._abc_data object>#
generate()[source]#

Generates Python domain model 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 named pydantic_classes.py