drf-yasg icon indicating copy to clipboard operation
drf-yasg copied to clipboard

Hashid field type incorrect (int instead of str) in the path parameters

Open ayushin opened this issue 2 years ago • 1 comments

This is related https://github.com/axnsan12/drf-yasg/issues/383

However this requires overriding the entire generator get_path_parameters method in its entirety just to be able to do:

            if isinstance(model_field, HashidFieldMixin):
                attrs = {'type': openapi.TYPE_STRING}
            else:

While I agree HashidField implementation is somewhere incorrect, it would be great to have something like SWAGGER_BASIC_TYPE_INFO_OVERRIDES so that get_basic_type_info would first look there.

Then an easy solution would be:

SWAGGER_BASIC_TYPE_OVERRIDES=[
    (HashidFieldMixin, (openapi.TYPE_STRING, None)),

]

Any other ideas how to fix this easier?

ayushin avatar Feb 16 '22 02:02 ayushin

Alternatively, somewhere in your project?

from drf_yasg import openapi
from drf_yasg.inspectors.field import model_field_to_basic_type
from hashid_field.field import HashidFieldMixin

model_field_to_basic_type.insert(
    0, (HashidFieldMixin, (openapi.TYPE_STRING, None)),
)

ayushin avatar Feb 16 '22 02:02 ayushin