REST API Generator

class besser.generators.rest_api.rest_api_generator.RESTAPIGenerator(model: DomainModel, http_methods: list = None, nested_creations: bool = False, backend: bool = False, output_dir: str = None)[source]#

Bases: GeneratorInterface

Rest_API_Generator is a class that implements the GeneratorInterface and is responsible for generating the Rest API domain model code based on the input B-UML model. This version of the generator allows specifying which HTTP methods (e.g., GET, POST, PATCH) should be included in the generated code. It can generate code for one or more specified methods, enabling more customizable API endpoint generation.

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

  • http_methods (list) – A list of strings representing the HTTP methods for which code should be generated. Each element should be one of “GET”, “POST”, “PUT”,”PATCH”,”DELETE”. This allows generating only the parts of the API that are needed.

  • 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 Rest API 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 rest_api.py and uses the Pydantic_Generator to generate the Pydantic classes