Union of a model with a Color raises error in creating openAPI.json.
#8160
-
|
To Reproduce
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
from pydantic.color import Color
class A(BaseModel):
type: str
class B(BaseModel):
bla: Color
C = Union[A, B]
app = FastAPI()
@app.get('/{var}', response_model=C)
def get(var: int):
if var == 1:
return {'type': 'a'}
else:
return {'bla': '#ff00ff'}
Expected behavior Environment:
Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
|
Not sure if you're allowed to use |
Beta Was this translation helpful? Give feedback.
-
|
it's not a bug in FastAPI @jorgecarleitao |
Beta Was this translation helpful? Give feedback.
-
|
@euri10, got it. Thanks. Is there anything to report to pydantic then? If yes, what would be the minimal example for them? |
Beta Was this translation helpful? Give feedback.
-
|
I just created a PR @jorgecarleitao |
Beta Was this translation helpful? Give feedback.
-
|
Perfect. Thanks a lot, @euri10. I am closing this so that we monitor it from there. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @euri10 for your help here and implementing it in Pydantic! 🍰 🚀 Thanks @jorgecarleitao for reporting back and closing the issue. Just in case, this should be available in a recent version of FastAPI. |
Beta Was this translation helpful? Give feedback.
Thanks @euri10 for your help here and implementing it in Pydantic! 🍰 🚀
Thanks @jorgecarleitao for reporting back and closing the issue.
Just in case, this should be available in a recent version of FastAPI.