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

fix openapi fields rendering for range type filters #1323

Conversation

A-Ashiq
Copy link

@A-Ashiq A-Ashiq commented Feb 5, 2021

This fix is aimed at Issue 1292.

Within the get_schema_fields method on DjangoFilterBackend. The coreapi field named tuples are made by looping over the filters retrieved from the filterset class. This change adds a check to see if there is widget which has been declared which in turn will provide us with the suffixes used to build range type fields. If no suffixes have been declared or the list is empty, then a single field will be rendered as normal with reference to the field_name.

For example, the DateFromToRangeFilter requires 2 fields to be rendered on swagger. If say the field name is created_at then we would expect created_at_after and created_at_before to be rendered. The current implementation will only render a single field as created_at which won't work.

@A-Ashiq
Copy link
Author

A-Ashiq commented Feb 5, 2021

This will be followed up with tests + a fix for my use of f-strings

Copy link
Owner

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @A-Ashiq. Here you're adjusting the old CoreAPI generation, rather than the OpenAPI fields that we need.

django_filters/rest_framework/backends.py Show resolved Hide resolved
MoisesGSalas added a commit to eduNEXT/eox-tagging that referenced this pull request Feb 9, 2021
    * A new view under `/eox-tagging/api-docs` can be used to interact
      with the REST API
    * Added descriptions of all the parameters and methods used by the
      API
    * Included a backport fix for [django-filter](carltongibson/django-filter#1323)
MoisesGSalas added a commit to eduNEXT/eox-tagging that referenced this pull request Feb 10, 2021
    * A new view under `/eox-tagging/api-docs` can be used to interact
      with the REST API
    * Added descriptions of all the parameters and methods used by the
      API
    * Included a backport fix for carltongibson/django-filter#1323
Base automatically changed from master to main March 3, 2021 08:48
@A-Ashiq
Copy link
Author

A-Ashiq commented May 3, 2021

@carltongibson can this be reviewed again?

@heavenshell
Copy link

heavenshell commented Jun 16, 2021

Hi. Is there any news about this?

@carltongibson carltongibson added this to the 21.1 milestone Jul 12, 2021
@carltongibson carltongibson removed this from the 21.1 milestone Aug 29, 2021
@lparolari
Copy link

Hi. Any news on this?

Why the PR cannot be merged? This will help a lot.

Thank you!

@carltongibson
Copy link
Owner

As per #1432 the in-built schema support is going to be deprecated in the next version.

Rather, I recommend you migrate to use drf-spectacular, which is much more fully featured, and under active development.

https://drf-spectacular.readthedocs.io/en/latest/readme.html

If for some reason you're not able to use drf-spectacular you can copy the django_filters.rest_framework.backends.DjangoFilterBackend into your own project to customise as needed. (But use drf-spectacular.)

Thanks.

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

Successfully merging this pull request may close these issues.

4 participants