drf-flex-fields icon indicating copy to clipboard operation
drf-flex-fields copied to clipboard

OpenAPI support for query parameters

Open Rjevski opened this issue 2 years ago • 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.

Rjevski avatar Jun 01 '22 05:06 Rjevski

I think the Open API parameters should be implemented in FlexFieldsMixin class.

@rsinger86 Could you take a look please ?

WatchDogsDev avatar Jun 25 '22 05:06 WatchDogsDev

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 avatar Apr 09 '23 02:04 mikelmulti460

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, https://github.com/rsinger86/drf-flex-fields/issues/46#issuecomment-735380938

baojd42 avatar Apr 10 '24 08:04 baojd42