OpenAPI support for query parameters
Rjevski opened this issue · 3 comments
Would it be possible to have OpenAPI support for query parameters?
At the moment this is provided by the FlexFieldsFilterBackend
however the filter backend also implements the (not thoroughly tested) query optimization features, which may not be desirable.
An easy fix would be to just separate the docs into its own (dummy) filter backend that doesn't actually do anything query-wise, so people who only want docs can include that one. It does feel a bit hacky to make an essentially fake filtering backend just for documentation so I'd like to get others' thoughts on this if there's a better way.
I think the Open API parameters should be implemented in FlexFieldsMixin
class.
@rsinger86 Could you take a look please ?
I get next error with FlexFieldsFilterBackend
File "/app/backend/.venv/lib/python3.11/site-packages/drf_spectacular/views.py", line 43, in <module>
class SpectacularAPIView(APIView):
File "/app/backend/.venv/lib/python3.11/site-packages/drf_spectacular/views.py", line 55, in SpectacularAPIView
generator_class = spectacular_settings.DEFAULT_GENERATOR_CLASS
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/backend/.venv/lib/python3.11/site-packages/rest_framework/settings.py", line 225, in __getattr__
val = perform_import(val, attr)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/backend/.venv/lib/python3.11/site-packages/rest_framework/settings.py", line 166, in perform_import
return import_from_string(val, setting_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/backend/.venv/lib/python3.11/site-packages/rest_framework/settings.py", line 180, in import_from_string
raise ImportError(msg)
ImportError: Could not import 'drf_spectacular.generators.SchemaGenerator' for API setting 'DEFAULT_GENERATOR_CLASS'. ImportError: Could not import 'rest_flex_fields.filter_backends.FlexFieldsFilterBackend' for API setting 'DEFAULT_FILTER_BACKENDS'. ImportError: Module "rest_flex_fields.filter_backends" does not define a "FlexFieldsFilterBackend" attribute/class..```
I get next error with
FlexFieldsFilterBackend
File "/app/backend/.venv/lib/python3.11/site-packages/drf_spectacular/views.py", line 43, in <module> class SpectacularAPIView(APIView): File "/app/backend/.venv/lib/python3.11/site-packages/drf_spectacular/views.py", line 55, in SpectacularAPIView generator_class = spectacular_settings.DEFAULT_GENERATOR_CLASS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/backend/.venv/lib/python3.11/site-packages/rest_framework/settings.py", line 225, in __getattr__ val = perform_import(val, attr) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/backend/.venv/lib/python3.11/site-packages/rest_framework/settings.py", line 166, in perform_import return import_from_string(val, setting_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/backend/.venv/lib/python3.11/site-packages/rest_framework/settings.py", line 180, in import_from_string raise ImportError(msg) ImportError: Could not import 'drf_spectacular.generators.SchemaGenerator' for API setting 'DEFAULT_GENERATOR_CLASS'. ImportError: Could not import 'rest_flex_fields.filter_backends.FlexFieldsFilterBackend' for API setting 'DEFAULT_FILTER_BACKENDS'. ImportError: Module "rest_flex_fields.filter_backends" does not define a "FlexFieldsFilterBackend" attribute/class..```
@mikelmulti460 You probably have put the backend in settings. However, it seems that there is some issue when doing it this way. And the way to work around is recommended by the comment, #46 (comment)