| hide |
|
|---|
By default, objects are unmarshalled to dictionaries. You can use dynamically created dataclasses by providing the x-model property inside the schema definition with the name of the model.
# ...
components:
schemas:
Coordinates:
x-model: Coordinates
type: object
required:
- lat
- lon
properties:
lat:
type: number
lon:
type: numberAs a result of the unmarshalling process, you will get a Coordinates class instance with lat and lon attributes.
You can use your own dataclasses, pydantic models, or models generated by third-party generators (e.g., datamodel-code-generator) by providing the x-model-path property inside the schema definition with the location of your class.
# ...
components:
schemas:
Coordinates:
x-model-path: foo.bar.Coordinates
type: object
required:
- lat
- lon
properties:
lat:
type: number
lon:
type: numberfrom dataclasses import dataclass
@dataclass
class Coordinates:
lat: float
lon: floatAs a result of the unmarshalling process, you will get an instance of your own dataclass or model.