mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 17:18:16 -06:00
Fix tags field to be shown as array in API view
`tags` field in serializers is defineded as `TagListSerializerField`. It should be shown as an array value in API view but actually, it is a simple string value. This fixes it by introducing a new `FieldInspector` to handle `TagListSerializerField` type field as an array. It doesn't affects any other type fields.
This commit is contained in:
parent
b97597c645
commit
d061b975c4
@ -278,6 +278,7 @@ SWAGGER_SETTINGS = {
|
|||||||
'DEFAULT_FIELD_INSPECTORS': [
|
'DEFAULT_FIELD_INSPECTORS': [
|
||||||
'utilities.custom_inspectors.NullableBooleanFieldInspector',
|
'utilities.custom_inspectors.NullableBooleanFieldInspector',
|
||||||
'utilities.custom_inspectors.CustomChoiceFieldInspector',
|
'utilities.custom_inspectors.CustomChoiceFieldInspector',
|
||||||
|
'utilities.custom_inspectors.TagListFieldInspector',
|
||||||
'drf_yasg.inspectors.CamelCaseJSONFilter',
|
'drf_yasg.inspectors.CamelCaseJSONFilter',
|
||||||
'drf_yasg.inspectors.ReferencingSerializerInspector',
|
'drf_yasg.inspectors.ReferencingSerializerInspector',
|
||||||
'drf_yasg.inspectors.RelatedFieldInspector',
|
'drf_yasg.inspectors.RelatedFieldInspector',
|
||||||
|
@ -1,11 +1,25 @@
|
|||||||
from drf_yasg import openapi
|
from drf_yasg import openapi
|
||||||
from drf_yasg.inspectors import FieldInspector, NotHandled, PaginatorInspector, FilterInspector
|
from drf_yasg.inspectors import FieldInspector, NotHandled, PaginatorInspector, FilterInspector
|
||||||
from rest_framework.fields import ChoiceField
|
from rest_framework.fields import ChoiceField
|
||||||
|
from taggit_serializer.serializers import TagListSerializerField
|
||||||
|
|
||||||
from extras.api.customfields import CustomFieldsSerializer
|
from extras.api.customfields import CustomFieldsSerializer
|
||||||
from utilities.api import ChoiceField
|
from utilities.api import ChoiceField
|
||||||
|
|
||||||
|
|
||||||
|
class TagListFieldInspector(FieldInspector):
|
||||||
|
def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):
|
||||||
|
SwaggerType, ChildSwaggerType = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)
|
||||||
|
if isinstance(field, TagListSerializerField):
|
||||||
|
child_schema = self.probe_field_inspectors(field.child, ChildSwaggerType, use_references)
|
||||||
|
return SwaggerType(
|
||||||
|
type=openapi.TYPE_ARRAY,
|
||||||
|
items=child_schema,
|
||||||
|
)
|
||||||
|
|
||||||
|
return NotHandled
|
||||||
|
|
||||||
|
|
||||||
class CustomChoiceFieldInspector(FieldInspector):
|
class CustomChoiceFieldInspector(FieldInspector):
|
||||||
def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):
|
def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):
|
||||||
# this returns a callable which extracts title, description and other stuff
|
# this returns a callable which extracts title, description and other stuff
|
||||||
|
Loading…
Reference in New Issue
Block a user