FastAPI converts the dataclass EndpointsData to a Pydantic model to create the OpenAPI specification. However, Pydantic doesn't allow fields starting with an underscore.
The simplest solution would be to set response_model=None in the route decorator:
This setting has precedence over the return annotation. In FastAPI 0.88 and earlier this was implicitly set to None and the return annotation was not used anyway.
Another solution would be to define EndpointsData as a Pydantic model with an alias definition:
from pydantic import BaseModel, Field
class EndpointsData(BaseModel):
links: EndpointsLinks = Field(..., alias="_links")
The following warning is shown using Pyctuator 1.0.1 and FastAPI 0.89.1:
FastAPI 0.89 has a new feature which uses the return annotation of a route to create the OpenAPI specification.
The warning is coming from this Pyctuator route:
https://github.com/SolarEdgeTech/pyctuator/blob/2b039ec2095df6f867cd0f6432bbdd0e4976222e/pyctuator/impl/fastapi_pyctuator.py#L45-L47
FastAPI converts the dataclass
EndpointsData
to a Pydantic model to create the OpenAPI specification. However, Pydantic doesn't allow fields starting with an underscore.The simplest solution would be to set
response_model=None
in the route decorator:This setting has precedence over the return annotation. In FastAPI 0.88 and earlier this was implicitly set to
None
and the return annotation was not used anyway.Another solution would be to define
EndpointsData
as a Pydantic model with an alias definition: