FastAPI 0.89.1 shows warning
NGEfreak opened this issue · 2 comments
The following warning is shown using Pyctuator 1.0.1 and FastAPI 0.89.1:
fastapi\utils.py:88: RuntimeWarning: fields may not start with an underscore, ignoring "_links"
return response_field(field_info=field_info)
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:
pyctuator/pyctuator/impl/fastapi_pyctuator.py
Lines 45 to 47 in 2b039ec
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:
@router.get("/", include_in_schema=include_in_openapi_schema, tags=["pyctuator"], response_model=None)
def get_endpoints() -> EndpointsData:
return self.get_endpoints_data()
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")
Fixed in #91
Version 1.0.2