Generate the schema of a response model by property names #79
candleindark
started this conversation in
Ideas
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? |
1 reply
|
@candleindark Thanks for your correction.
Additionally, can you write a simple example so that we can provide better documentation. |
3 replies
|
I drafted a PR #81 that will be merged in the next version. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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))?
All reactions