pvarki / python-rasenmaeher-api

1 stars 0 forks source link

All pydantic schemas MUST define extra="forbid" #33

Closed rambo closed 11 months ago

rambo commented 1 year ago

This avoids nasty bugs down the line (and also incomplete autogenerated openapi schemas)

class MyModel(BaseModel, extra="forbid"):
    """Model for My X"""

This info should probably be updated to our best_practises repo.

There is also another way that is more compatible with providing examples to the openapi.json, see https://github.com/pvarki/python-rasenmaeher-api/blob/main/src/rasenmaeher_api/web/api/tokens/schema.py

rambo commented 1 year ago

Also all the fields should use the foo: str = Field(description="bar") style for defining the fields since the extended field definition is very useful to the openapi spec generator