-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply multi responses to one HttpStatus or apply arbitrary str as responses key #136
Labels
Comments
You can do this: https://docs.pydantic.dev/latest/concepts/models/#rootmodel-and-custom-root-types from pydantic import RootModel
class Resp(BaseModel):
a: int
class Resp1(BaseModel):
b: int
class UnionRespResp2(RootModel):
root:Union[Resp, Resp1]
@app.get("/", responses={200: UnionRespResp2})
def book():
pass |
When you don't have a configuration example, the Swagger UI automatically generates one. You can do this by configuring openapi_extra fields in the from typing import Union
from pydantic import BaseModel, RootModel
from flask_openapi3 import OpenAPI
app = OpenAPI(__name__)
class Resp(BaseModel):
a: str
class Resp1(BaseModel):
b: int
class UnionRespResp2(RootModel):
root: Union[Resp, Resp1]
model_config = {
"openapi_extra": {
"examples": {
"Success Example": {
"summary": "Success Example",
"value": {
"a": "sss"
}
},
"Fail Example": {
"summary": "Fail Example",
"value": {
"b": -1
}
}
}
}
}
@app.get("/", responses={200: UnionRespResp2})
def book():
return "ok"
if __name__ == "__main__":
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In current flask-openapi3, I can only map 200 to Resp, 201: Resp1.
But I want to map all of these to one HttpStatus, because they are both HttpStatus 200. like
Or allow the key of responses can be arbitrary str like
The text was updated successfully, but these errors were encountered: