You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Using openapi-python-client on a valid FastAPI/pydantic API is generating invalid client library on 0.7.2 when there is a somewhat complex set of nested Dict and Union types.
To Reproduce
Put the following in a main.py
from typing import Any, Dict, List, Union
from fastapi import FastAPI
from pydantic import (
BaseModel,
StrictBool,
StrictInt,
StrictFloat,
StrictStr,
)
app = FastAPI()
JSONValue = Union[
Dict[str, Any], List[Any], StrictBool, StrictFloat, StrictInt, StrictStr, None
]
JSONDict = Dict[str, JSONValue]
class ItemMapResource(BaseModel):
items: JSONDict
@app.get("/", response_model=ItemMapResource)
def read_item():
return ItemMapResource(items={})
Thanks for reporting the bug, we'll have to make sure we add an end to end test case with nesting like this so we don't miss it in the future 😅. I should have a chance to fix this at the end of the week, but CC @packyg in case you get a moment to check this out before I do.
* Fix indentation of union-ed addtionalProperties
* Fix instance check for lists in unions
* Handle non-templated union values separately from ones with templates
* Add ModelWithAnyJsonProperties to e2e tests
* Union Property - use `data` from inner function when returning primitive values
Co-authored-by: Packy Gallagher <packyg@benchling.com>
Describe the bug
Using
openapi-python-client
on a valid FastAPI/pydantic API is generating invalid client library on 0.7.2 when there is a somewhat complex set of nestedDict
andUnion
types.To Reproduce
Put the following in a main.py
Run it like this:
Generate a client library like this
Expected behavior
Should generate valid python library
Actual behavior
Generates code with broken indents which fails to execute:
Note the line
if isinstance(prop, ItemMapResourceItemsAdditionalProperty):
is indented incorrectly.OpenAPI Spec File
Desktop (please complete the following information):
Additional context
This worked fine with 0.7.0, so I suspect a regression from #252
The text was updated successfully, but these errors were encountered: