-
Notifications
You must be signed in to change notification settings - Fork 41
[Feature Request] Be able to change 422 validation errors to other http response status code (e.g. 400) #83
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
Conversation
If there's another way that you'd prefer to manage this that would allow a user to modify the 422 to a 400, please feel free to point it out. Would this be better in a config file? I was thinking about overwriting it using a global. |
Thanks @CostcoFanboy for working this. I prefer to accept an explicit parameter app = OpenAPI(__name__, validation_error_status="400") Can you follow this idea and continue to complete it? And also requires a unit test. |
Why did you use a custom library of strings instead of the official HTTPStatus lib built-in in Python everywhere? There's inconsistencies vs HTTP Status as a string and HTTP Status as an int. Would you be open to change this? Not necessarily same PR. |
Signed-off-by: Mihai Damaschin <[email protected]>
@CostcoFanboy It is unreasonable to add But I am also stuck in a stalemate, adding We need to find a better solution. |
@CostcoFanboy I improve implement |
Agreed, I tried to initially avoid that with the global var. Otherwise need to replace it everywhere. But in one sense it does make sense to have it everywhere like this because maybe we should allow the http status code to be overwritten depending on the endpoint 🤔. I think this would be more of a "validation_error_status v2.0" effort though and we're doing v1.1
Anything that can change the HTTP response code can help.
So my first idea was to have a global variable I can use to overwrite the variable you have to make it non-intrusive. By the way, why not use inheritance for the get, post, put, patch, etc? They are 95% similar. Great work on the library otherwise, please don't see my comments as hate, I'm a fan of the package. I will try to test it tomorrow in free time. |
flask_openapi3/openapi.py
Outdated
openapi_extensions: Extensions to the OpenAPI Schema. | ||
See https://spec.openapis.org/oas/v3.0.3#specification-extensions. | ||
validation_error_status: HTTP Status of the response given when a validation error is detected by pydantic. | ||
Defaults to 422 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defaults in English would be more accurate.
"It defaults to" vs "it default to".
Not important of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English is not my native language, thank you for pointing out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, it's not mine either, we're all here to help each other out for a common goal :)
flask_openapi3/openapi.py
Outdated
spec.paths = self.paths | ||
|
||
# Add ValidationErrorResponseModel to components schemas | ||
self.components_schemas[ValidationErrorResponseModel.__name__] = Schema(**ValidationErrorResponseModel.schema()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be addable by the user when initializing the application? What if the user doesn't use validation but chooses to use your library?
I agree that it's a strange/weird scenario if he chooses that though. May not be valid. Mostly brainstorming.
@CostcoFanboy I realize that you may have misunderstood:
Please be free to point out my mistake, I am open to it. |
@CostcoFanboy @atistler I think I have already completed this issue. Can you do a test to ensure that my implementation meets everyone's requirements? |
Hi, do you have any prediction of when this feature will be published? |
Hey @luolingchun sorry for the delay I was on vacation then this escaped my mind. I did a quick test using your changes and this is more than satisfactory. Great work! @higorsnt Feel free to actually contribute instead of just asking when things will be ready. |
@higorsnt It's preliminarily completed, and I will do the final round of testing, probably in the first week of August. |
Checklist:
pytest tests
and no failed.flake8 flask_openapi3 tests examples
and no failed.mypy flask_openapi3
and no failed.mkdocs serve
and no failed.