Skip to content
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

OpenAPI support for query parameters #98

Open
Rjevski opened this issue Jun 1, 2022 · 3 comments
Open

OpenAPI support for query parameters #98

Rjevski opened this issue Jun 1, 2022 · 3 comments

Comments

@Rjevski
Copy link
Contributor

Rjevski commented Jun 1, 2022

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.

@WatchDogsDev
Copy link

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

@rsinger86 Could you take a look please ?

@mikelmulti460
Copy link

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..```

@baojd42
Copy link

baojd42 commented Apr 10, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants