mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #2968: Correct API documentation for SerializerMethodFields
This commit is contained in:
@ -24,6 +24,10 @@ to now use "Extras | Tag."
|
|||||||
* [#2791](https://github.com/digitalocean/netbox/issues/2791) - Add a `comment` field for tags
|
* [#2791](https://github.com/digitalocean/netbox/issues/2791) - Add a `comment` field for tags
|
||||||
* [#2926](https://github.com/digitalocean/netbox/issues/2926) - Add changelog to the Tag model
|
* [#2926](https://github.com/digitalocean/netbox/issues/2926) - Add changelog to the Tag model
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
* [#2968](https://github.com/digitalocean/netbox/issues/2968) - Correct API documentation for SerializerMethodFields
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
v2.5.8 (FUTURE)
|
v2.5.8 (FUTURE)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from drf_yasg.utils import swagger_serializer_method
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.validators import UniqueTogetherValidator
|
from rest_framework.validators import UniqueTogetherValidator
|
||||||
from taggit_serializer.serializers import TaggitSerializer, TagListSerializerField
|
from taggit_serializer.serializers import TaggitSerializer, TagListSerializerField
|
||||||
@ -35,6 +36,7 @@ class ConnectedEndpointSerializer(ValidatedModelSerializer):
|
|||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@swagger_serializer_method(serializer_or_field=serializers.DictField)
|
||||||
def get_connected_endpoint(self, obj):
|
def get_connected_endpoint(self, obj):
|
||||||
"""
|
"""
|
||||||
Return the appropriate serializer for the type of connected object.
|
Return the appropriate serializer for the type of connected object.
|
||||||
@ -312,6 +314,7 @@ class DeviceSerializer(TaggitSerializer, CustomFieldModelSerializer):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@swagger_serializer_method(serializer_or_field=NestedDeviceSerializer)
|
||||||
def get_parent_device(self, obj):
|
def get_parent_device(self, obj):
|
||||||
try:
|
try:
|
||||||
device_bay = obj.parent_bay
|
device_bay = obj.parent_bay
|
||||||
@ -334,6 +337,7 @@ class DeviceWithConfigContextSerializer(DeviceSerializer):
|
|||||||
'custom_fields', 'config_context', 'created', 'last_updated',
|
'custom_fields', 'config_context', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@swagger_serializer_method(serializer_or_field=serializers.DictField)
|
||||||
def get_config_context(self, obj):
|
def get_config_context(self, obj):
|
||||||
return obj.get_config_context()
|
return obj.get_config_context()
|
||||||
|
|
||||||
@ -531,9 +535,11 @@ class CableSerializer(ValidatedModelSerializer):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@swagger_serializer_method(serializer_or_field=serializers.DictField)
|
||||||
def get_termination_a(self, obj):
|
def get_termination_a(self, obj):
|
||||||
return self._get_termination(obj, 'a')
|
return self._get_termination(obj, 'a')
|
||||||
|
|
||||||
|
@swagger_serializer_method(serializer_or_field=serializers.DictField)
|
||||||
def get_termination_b(self, obj):
|
def get_termination_b(self, obj):
|
||||||
return self._get_termination(obj, 'b')
|
return self._get_termination(obj, 'b')
|
||||||
|
|
||||||
@ -564,6 +570,7 @@ class InterfaceConnectionSerializer(ValidatedModelSerializer):
|
|||||||
model = Interface
|
model = Interface
|
||||||
fields = ['interface_a', 'interface_b', 'connection_status']
|
fields = ['interface_a', 'interface_b', 'connection_status']
|
||||||
|
|
||||||
|
@swagger_serializer_method(serializer_or_field=NestedInterfaceSerializer)
|
||||||
def get_interface_a(self, obj):
|
def get_interface_a(self, obj):
|
||||||
context = {'request': self.context['request']}
|
context = {'request': self.context['request']}
|
||||||
return NestedInterfaceSerializer(instance=obj, context=context).data
|
return NestedInterfaceSerializer(instance=obj, context=context).data
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
from drf_yasg.utils import swagger_serializer_method
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from dcim.api.nested_serializers import (
|
from dcim.api.nested_serializers import (
|
||||||
@ -112,6 +113,7 @@ class ImageAttachmentSerializer(ValidatedModelSerializer):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@swagger_serializer_method(serializer_or_field=serializers.DictField)
|
||||||
def get_parent(self, obj):
|
def get_parent(self, obj):
|
||||||
|
|
||||||
# Static mapping of models to their nested serializers
|
# Static mapping of models to their nested serializers
|
||||||
@ -215,6 +217,7 @@ class ObjectChangeSerializer(serializers.ModelSerializer):
|
|||||||
'id', 'time', 'user', 'user_name', 'request_id', 'action', 'content_type', 'changed_object', 'object_data',
|
'id', 'time', 'user', 'user_name', 'request_id', 'action', 'content_type', 'changed_object', 'object_data',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@swagger_serializer_method(serializer_or_field=serializers.DictField)
|
||||||
def get_changed_object(self, obj):
|
def get_changed_object(self, obj):
|
||||||
"""
|
"""
|
||||||
Serialize a nested representation of the changed object.
|
Serialize a nested representation of the changed object.
|
||||||
|
@ -308,6 +308,7 @@ SWAGGER_SETTINGS = {
|
|||||||
'drf_yasg.inspectors.ChoiceFieldInspector',
|
'drf_yasg.inspectors.ChoiceFieldInspector',
|
||||||
'drf_yasg.inspectors.FileFieldInspector',
|
'drf_yasg.inspectors.FileFieldInspector',
|
||||||
'drf_yasg.inspectors.DictFieldInspector',
|
'drf_yasg.inspectors.DictFieldInspector',
|
||||||
|
'drf_yasg.inspectors.SerializerMethodFieldInspector',
|
||||||
'drf_yasg.inspectors.SimpleFieldInspector',
|
'drf_yasg.inspectors.SimpleFieldInspector',
|
||||||
'drf_yasg.inspectors.StringDefaultFieldInspector',
|
'drf_yasg.inspectors.StringDefaultFieldInspector',
|
||||||
],
|
],
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from drf_yasg.utils import swagger_serializer_method
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from taggit_serializer.serializers import TaggitSerializer, TagListSerializerField
|
from taggit_serializer.serializers import TaggitSerializer, TagListSerializerField
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ class VirtualMachineWithConfigContextSerializer(VirtualMachineSerializer):
|
|||||||
'config_context', 'created', 'last_updated',
|
'config_context', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@swagger_serializer_method(serializer_or_field=serializers.DictField)
|
||||||
def get_config_context(self, obj):
|
def get_config_context(self, obj):
|
||||||
return obj.get_config_context()
|
return obj.get_config_context()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user