-
Notifications
You must be signed in to change notification settings - Fork 17
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
error-responses-with-drf-spectacular #4
Conversation
…s using drf-spectacular
Codecov Report
@@ Coverage Diff @@
## main #4 +/- ##
==========================================
+ Coverage 99.39% 99.69% +0.29%
==========================================
Files 6 9 +3
Lines 165 649 +484
Branches 25 161 +136
==========================================
+ Hits 164 647 +483
+ Misses 1 0 -1
- Partials 0 2 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
…d the possible error codes taking into account nested and list serializers, composite serializer fields and errors raised by django filter backend
…g hook. This version excludes error components from postprocessing to avoid raising warnings about multiple enums having the same choices. Package users will be encouraged to use this version instead of the one provided by drf-spectacular.
…to a separate method to make it easy to add extra error codes per field if necessary (by overriding the method and manipulating the returned list of fields)
…d and the view has auth classes defined
Hello, I'm interested in this feature, especially the serializers as I already have my own schema class. Is it still planned ? Thank you |
yep, this feature is still planned since I also need it. However, it just fell down in my priority list. I'll try to make progress soon. I already have some tests that I didn't push. But, as shown in the test coverage report, the amount of code added for error response introspection is more than 3 times the existing code, so it takes a while to get to a decent test coverage. Other than that, I still need to add the docs. Still, if you only need the serializers, I suggest you just copy them without having to wait (since I don't expect changing them). However, I should mention that the important work in this feature is in the |
…t drf-spectacular version
…but forget to provide corresponding serializer
… code blank in choice fields (invalid_choice is the error code in that case)
validate_image_file_extension and validate_integer
…re passed when initializing package settings
…y from drf-spectacular with one change to exclude error components from being processed by the hook (a test was added for that change in the previous commit)
…verage github action
… are dicts and the values of the dict is a string that represents the path to a class to be imported
…ings that represent the path to the serializer class which describes the error response and update the corresponding test
…nerate error responses
…esponses schemas with drf-spectacular
To use:
"DEFAULT_SCHEMA_CLASS"
to"drf_standardized_errors.openapi.AutoSchema"
ENUM_NAME_OVERRIDES
:But if you're already overriding it, make sure to replace the enums postprocessing hook from drf-spectacular with the one from this package. The hook will avoid raising warnings for dynamically created error code enums per field.
Notes:
ALLOWED_ERROR_STATUS_CODES
and changing the error response schema if neededERROR_SCHEMAS
. Other than that, the generation logic is separated into multiple methods underAutoSchema
making it easy to override specific aspects of the generation process.ALLOWED_ERROR_STATUS_CODES
.Here's how this looks in swagger UI:
validation_error_example
validation_error_schema