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

Default filters for foreign keys should document as integers, not strings. #1156

Closed
dragonpaw opened this issue Dec 5, 2019 · 2 comments
Closed

Comments

@dragonpaw
Copy link

Given a Django model with a FK that is an integer, the openapi documentation shows the filter as taking a string argument, not an integer.

Given:

# models.py
class That(models.Model):
    pk = models.IntegerField(primary=True)

class This(models.Model):
    that = models.ForeignKey('That')
# views.py
class ThisFilter(filters.FilterSet):
    class Meta:
        model = models.This
        fields = {
            "that": ["exact"]
        }

The resulting openapi/swagger docs will have a data type of string for the "that" filter, not integer, which is what I'd think it should be, as we're searching for an integer PK after all. Passing in just the int, unquoted, seems to work fine, so I think this is just documentation, not an actual filter issue.

@foarsitter
Copy link

Looking to the source that may be not a surprise since all the filter fields are hard coded as string.

What would be the preferred way for django-filter to implement the correct OpenAPI specification?

  • Add the definition to the corresponding fields (i.e. field.get_schema_operation_parameters)
  • Create a custom backend in a 3rd party package (dictionary between filter field and OpenAPI spec)

Either way, I'm happily give it a try!

@carltongibson
Copy link
Owner

Moving to #1432

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

3 participants