Open tkaraouzene opened 9 months ago
This looks like a duplicate of https://github.com/unionai-oss/pandera/issues/1395, correct?
My bad I forgot to specify that I was using pydantic v1 (1.10.2). So no it is not a duplicate
Gotcha. Feel free to try and debug this and opening a PR for a fix!
The part of the codebase that creates the json schema representation is here
Thanks, I'll have a look on it
@tkaraouzene did you have any success getting pandera to work with generating openapi schema accurately using pydantic v1 and fastapi? I am having a similar issue where I am orienting the dataframe as records (list) but openapi is generating a schema where each column is an array like:
"year_id": {
"type": "array",
"items": {
"type": "integer"
}
},
My actual response model is returned as a list of record objects that each have a year_id, etc. , which doesn't match the schema being generated.
The state of the json_schema support is still the same as before, see this issue: https://github.com/unionai-oss/pandera/issues/1395
Would welcome any PRs to actually fix the to_json_schema function here: https://github.com/unionai-oss/pandera/blob/cf6b5e45dfb0cd593f948b12a2a327bbf3699657/pandera/api/pandas/model.py#L651-L661
Ok, thanks. In the meantime is there a recommended way to override the _to_json_schema function to explicitly specify the schema? Alternatively, would returning a dataframe model with
class Config:
to_format = "dict"
to_format_kwargs = {"orient": "list"}
match the way that the schema is currently generated with columns as arrays?
Edit: using the above kwargs worked for me to make my responses match the way pandera generates the openapi schema
Describe the bug A clear and concise description of what the bug is.
Code Sample, a copy-pastable example
Expected behavior
When I run my app I would like to see
InputPandera
andOutputPandera
in the generated openAPI as it is done forInputPydantic
andOutputPydantic
objects:Moreover, provided examples for both request and response are wrong:
Request
x
should befloat
and notint
so it leads to an execution failure when "Try it out"Response
Provided response example is has not the good format:
Instead of:![image](https://github.com/unionai-oss/pandera/assets/20064077/e86afd81-2995-4835-ba47-e636a89815e4)
Desktop (please complete the following information):
Additional context
Both
[io]
and[fastapi]
extensions have been installed