Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 52 additions & 49 deletions contrib/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -206935,8 +206935,8 @@
"format": "int64"
},
"object": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"user": {
"$ref": "#/components/schemas/BriefUser"
Expand Down Expand Up @@ -211700,8 +211700,8 @@
"readOnly": true
},
"termination": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"created": {
"type": "string",
Expand Down Expand Up @@ -211972,8 +211972,8 @@
"nullable": true
},
"termination": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"port_speed": {
"type": "integer",
Expand Down Expand Up @@ -212176,8 +212176,8 @@
"format": "int64"
},
"member": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"priority": {
"type": "object",
Expand Down Expand Up @@ -212561,8 +212561,8 @@
"nullable": true
},
"termination": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"port_speed": {
"type": "integer",
Expand Down Expand Up @@ -212978,8 +212978,8 @@
"nullable": true
},
"scope": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"description": {
"type": "string",
Expand Down Expand Up @@ -215293,9 +215293,8 @@
"format": "int64"
},
"object": {
"type": "object",
"additionalProperties": {},
"readOnly": true
"readOnly": true,
"nullable": true
},
"contact": {
"$ref": "#/components/schemas/BriefContact"
Expand Down Expand Up @@ -219029,9 +219028,8 @@
"nullable": true
},
"action_object": {
"type": "object",
"additionalProperties": {},
"readOnly": true
"readOnly": true,
"nullable": true
},
"description": {
"type": "string",
Expand Down Expand Up @@ -219536,8 +219534,8 @@
"format": "int64"
},
"interface": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"priority": {
"type": "integer",
Expand Down Expand Up @@ -221339,8 +221337,8 @@
"nullable": true
},
"assigned_object": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"nat_inside": {
"allOf": [
Expand Down Expand Up @@ -222501,8 +222499,8 @@
"format": "int64"
},
"parent": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"name": {
"type": "string",
Expand Down Expand Up @@ -225660,8 +225658,8 @@
"nullable": true
},
"component": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"tags": {
"type": "array",
Expand Down Expand Up @@ -226044,8 +226042,8 @@
"nullable": true
},
"component": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"created": {
"type": "string",
Expand Down Expand Up @@ -226327,8 +226325,8 @@
"format": "int64"
},
"assigned_object": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"created": {
"type": "string",
Expand Down Expand Up @@ -226777,8 +226775,8 @@
"format": "int64"
},
"assigned_object": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"tags": {
"type": "array",
Expand Down Expand Up @@ -227155,8 +227153,8 @@
"nullable": true
},
"assigned_object": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"description": {
"type": "string",
Expand Down Expand Up @@ -229542,8 +229540,8 @@
"format": "int64"
},
"object": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"user": {
"$ref": "#/components/schemas/BriefUser"
Expand Down Expand Up @@ -229796,7 +229794,11 @@
"format": "int64"
},
"changed_object": {
"nullable": true,
"readOnly": true,
"nullable": true
},
"object_repr": {
"type": "string",
"readOnly": true
},
"message": {
Expand All @@ -229821,6 +229823,7 @@
"display_url",
"id",
"message",
"object_repr",
"postchange_data",
"prechange_data",
"request_id",
Expand Down Expand Up @@ -248892,8 +248895,8 @@
"nullable": true
},
"scope": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"tenant": {
"allOf": [
Expand Down Expand Up @@ -252745,8 +252748,8 @@
"format": "int64"
},
"parent": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"name": {
"type": "string",
Expand Down Expand Up @@ -253669,8 +253672,8 @@
"format": "int64"
},
"object": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"user": {
"$ref": "#/components/schemas/BriefUser"
Expand Down Expand Up @@ -255193,8 +255196,8 @@
"nullable": true
},
"termination": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"outside_ip": {
"allOf": [
Expand Down Expand Up @@ -255671,8 +255674,8 @@
"nullable": true
},
"scope": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"vid_ranges": {
"type": "array",
Expand Down Expand Up @@ -258528,8 +258531,8 @@
"nullable": true
},
"scope": {
"nullable": true,
"readOnly": true
"readOnly": true,
"nullable": true
},
"tenant": {
"allOf": [
Expand Down
33 changes: 4 additions & 29 deletions netbox/circuits/api/serializers_/circuits.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.contenttypes.models import ContentType
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers

from circuits.choices import CircuitPriorityChoices, CircuitStatusChoices, VirtualCircuitTerminationRoleChoices
Expand All @@ -11,12 +10,12 @@
from dcim.api.serializers_.device_components import InterfaceSerializer
from dcim.api.serializers_.cables import CabledObjectSerializer
from netbox.api.fields import ChoiceField, ContentTypeField, RelatedObjectCountField
from netbox.api.gfk_fields import GFKSerializerField
from netbox.api.serializers import (
NetBoxModelSerializer, OrganizationalModelSerializer, PrimaryModelSerializer, WritableNestedSerializer,
)
from netbox.choices import DistanceUnitChoices
from tenancy.api.serializers_.tenants import TenantSerializer
from utilities.api import get_serializer_for_model
from .providers import ProviderAccountSerializer, ProviderNetworkSerializer, ProviderSerializer

__all__ = (
Expand Down Expand Up @@ -55,7 +54,7 @@ class CircuitCircuitTerminationSerializer(WritableNestedSerializer):
default=None
)
termination_id = serializers.IntegerField(allow_null=True, required=False, default=None)
termination = serializers.SerializerMethodField(read_only=True)
termination = GFKSerializerField(read_only=True)

class Meta:
model = CircuitTermination
Expand All @@ -64,14 +63,6 @@ class Meta:
'upstream_speed', 'xconnect_id', 'description',
]

@extend_schema_field(serializers.JSONField(allow_null=True))
def get_termination(self, obj):
if obj.termination_id is None:
return None
serializer = get_serializer_for_model(obj.termination)
context = {'request': self.context['request']}
return serializer(obj.termination, nested=True, context=context).data


class CircuitGroupSerializer(OrganizationalModelSerializer):
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
Expand Down Expand Up @@ -134,7 +125,7 @@ class CircuitTerminationSerializer(NetBoxModelSerializer, CabledObjectSerializer
default=None
)
termination_id = serializers.IntegerField(allow_null=True, required=False, default=None)
termination = serializers.SerializerMethodField(read_only=True)
termination = GFKSerializerField(read_only=True)

class Meta:
model = CircuitTermination
Expand All @@ -146,20 +137,12 @@ class Meta:
]
brief_fields = ('id', 'url', 'display', 'circuit', 'term_side', 'description', 'cable', '_occupied')

@extend_schema_field(serializers.JSONField(allow_null=True))
def get_termination(self, obj):
if obj.termination_id is None:
return None
serializer = get_serializer_for_model(obj.termination)
context = {'request': self.context['request']}
return serializer(obj.termination, nested=True, context=context).data


class CircuitGroupAssignmentSerializer(CircuitGroupAssignmentSerializer_):
member_type = ContentTypeField(
queryset=ContentType.objects.filter(CIRCUIT_GROUP_ASSIGNMENT_MEMBER_MODELS)
)
member = serializers.SerializerMethodField(read_only=True)
member = GFKSerializerField(read_only=True)

class Meta:
model = CircuitGroupAssignment
Expand All @@ -169,14 +152,6 @@ class Meta:
]
brief_fields = ('id', 'url', 'display', 'group', 'member_type', 'member_id', 'member', 'priority')

@extend_schema_field(serializers.JSONField(allow_null=True))
def get_member(self, obj):
if obj.member_id is None:
return None
serializer = get_serializer_for_model(obj.member)
context = {'request': self.context['request']}
return serializer(obj.member, nested=True, context=context).data


class VirtualCircuitTypeSerializer(OrganizationalModelSerializer):

Expand Down
Loading