Skip to content

Commit

Permalink
Fix definition of vid_ranges in VLANGroup so it shows up in the O…
Browse files Browse the repository at this point in the history
…penAPI schema (#18237)
  • Loading branch information
mraerino authored Feb 26, 2025
1 parent cffb99c commit c81f4da
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion netbox/core/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import typing
from collections import OrderedDict

from drf_spectacular.extensions import OpenApiSerializerFieldExtension
from drf_spectacular.extensions import OpenApiSerializerFieldExtension, OpenApiSerializerExtension, _SchemaType
from drf_spectacular.openapi import AutoSchema
from drf_spectacular.plumbing import (
build_basic_type, build_choice_field, build_media_type_object, build_object_type, get_doc,
)
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import Direction

from netbox.api.fields import ChoiceField
from netbox.api.serializers import WritableNestedSerializer
Expand Down Expand Up @@ -277,3 +278,20 @@ def map_serializer_field(self, auto_schema, direction):
return component.ref if component else None
else:
return build_basic_type(OpenApiTypes.INT)


class FixIntegerRangeSerializerSchema(OpenApiSerializerExtension):
target_class = 'netbox.api.fields.IntegerRangeSerializer'

def map_serializer(self, auto_schema: 'AutoSchema', direction: Direction) -> _SchemaType:
return {
'type': 'array',
'items': {
'type': 'array',
'items': {
'type': 'integer',
},
'minItems': 2,
'maxItems': 2,
},
}

0 comments on commit c81f4da

Please sign in to comment.