drf-spectacular
drf-spectacular copied to clipboard
[django-filter] Filter Data Type / Description Issues
Hello, first of all, thank you for your work and effort. It’s an incredible library.
Describe the bug
I’m having two problems with filters:
- When I define a filter as “integer,” I can’t get it to appear as an integer in the schema (it appears as "number"). Could you guide me on where I should indicate this, please? (type hinting, extend_schema_field...)
class PositiveIntegerFilter(filters.NumberFilter):
field_class = forms.IntegerField
I’ve tried in many places but haven’t been able to achieve it. I should note that I am applying the filter in a custom way, meaning it doesn’t apply to a specific field of an object (it's a filter for a list that has nothing to do with objects). Maybe that’s why it can’t identify the integer type through model introspection (that’s my theory).
- If I specify my filters adding extend_schema_field(OpenApiTypes.XXX), the help_text doesn’t transfer to the description (it gets lost in the schema). Is this a bug? Any way to propagate the help_text to the description?
Both problems are related for me because I can’t specify the integer type with extend_schema_field since I lose the description 😆 .
Example:
asset_currency = extend_schema_field(OpenApiTypes.STR)(filters.ModelChoiceFilter(
help_text=_('Filter by the currency code of the asset')
))
Result (without description) :
{
"in": "query",
"name": "asset_currency",
"schema": {
"type": "string"
}
To Reproduce
Define a filter with help_text like this
asset_currency = extend_schema_field(OpenApiTypes.STR)(filters.ModelChoiceFilter(
help_text=_('Filter by the currency code of the asset')
))
Expected behavior
expected result (with description=help_text):
{
"in": "query",
"name": "asset_currency",
"schema": {
"type": "string"
},
"description": "Filter by the currency code of the asset"
},
Thanks in advance