Python

There are special use-cases that each language supports; this document pertains to Python models.

The generated Python models require at least v3.7.

Generate Pydantic models

In some cases you might want to use pydantic data validation and settings management using Python type hints for the models. Modelina follows Pydantic v2.

There are some limitations to the current implementation:

  1. The preset doesn't unwrap properties of type ConstrainedDictionaryModel with serialilzationType = unwrap, they are simply excluded from the serialization

You can find an example of its use here

Generate models with JSON Serializer and Deserializer methods

Using the preset PYTON_JSON_SERIALIZER, you can generate serializeToJson method to convert model instance to JSON and deserializeFromJson method to convert JSON to model instance.

Limitations

  1. Above preset doesn't unwrap properties of type ConstrainedDictionaryModel with serialilzationType = unwrap
  2. The serialized JSON object will have the same property names as defined in the model object.

Check out this example for a live demonstration.