Generate the schema of a response model by property names #79
Replies: 3 comments 5 replies
-
@candleindark We can add class BookQuery(BaseModel):
age: int
author: str
class Config:
by_alias = False
# in pydantic v2.x
model_config = ConfigDict(by_alias=False) Then using def get_schema(obj: Type[BaseModel]) -> dict:
"""Converts a Pydantic model to an OpenAPI schema."""
assert inspect.isclass(obj) and issubclass(obj, BaseModel), \
f"{obj} is invalid `pydantic.BaseModel`"
model_config = response.Config
by_alias = getattr(model_config, "by_alias", True)
return obj.schema(by_alias=False, ref_template=OPENAPI3_REF_TEMPLATE) Is this what you think? |
Beta Was this translation helpful? Give feedback.
-
@candleindark Thanks for your correction.
Additionally, can you write a simple example so that we can provide better documentation. |
Beta Was this translation helpful? Give feedback.
-
I drafted a PR #81 that will be merged in the next version. |
Beta Was this translation helpful? Give feedback.
-
Currently, the schema of a Pydantic model that is specified as a response is generated using aliases in the model as the keys (per the default behavior of a Pydantic model). Can we have a feature in flask-openapi3 that allows the schema of a Pydantic model that is specified as a response to be generated using the property names of the model (as MainModel. schema_json(by_alias=False))?
Beta Was this translation helpful? Give feedback.
All reactions