REST API docs: vid_ranges POST example for VLANGroup is triple‑nested ([[[lo, hi]]]) instead of [[lo, hi]] #11683

Closed
opened 2025-12-29 21:48:36 +01:00 by adam · 2 comments
Owner

Originally created by @pheus on GitHub (Oct 3, 2025).

Originally assigned to: @pheus on GitHub.

NetBox Edition

NetBox Community

NetBox Version

v4.4.2

Python Version

3.12

Steps to Reproduce

  1. Open /api/schema/swagger-ui/.
  2. Go to IPAM → VLAN groups → POST /api/ipam/vlan-groups/.
  3. Inspect the request body “Example Value”.

Expected Behavior

vid_ranges should be a list of two‑integer ranges:

"vid_ranges": [[10, 20]]

Observed Behavior

vid_ranges is shown with an extra nesting level:

"vid_ranges": [[[0, 0]]]

Additional Information

The OpenAPI serializer extension for IntegerRangeSerializer returns an array of arrays for a single range; with many=True on vid_ranges, drf‑spectacular wraps it again, causing triple nesting.

Proposed Fix (schema extension)

# netbox/core/api/schema.py
class FixIntegerRangeSerializerSchema(OpenApiSerializerExtension):
    target_class = 'netbox.api.fields.IntegerRangeSerializer'

    def map_serializer(self, auto_schema, direction):
        # One range = two integers; many=True will wrap this in an outer array
        return {
            "type": "array",
            "items": {"type": "integer"},
            "minItems": 2,
            "maxItems": 2,
        }
Originally created by @pheus on GitHub (Oct 3, 2025). Originally assigned to: @pheus on GitHub. ### NetBox Edition NetBox Community ### NetBox Version v4.4.2 ### Python Version 3.12 ### Steps to Reproduce 1. Open `/api/schema/swagger-ui/`. 2. Go to **IPAM → VLAN groups → POST /api/ipam/vlan-groups/**. 3. Inspect the request body “Example Value”. ### Expected Behavior `vid_ranges` should be a list of two‑integer ranges: ```json "vid_ranges": [[10, 20]] ``` ### Observed Behavior `vid_ranges` is shown with an extra nesting level: ```json "vid_ranges": [[[0, 0]]] ``` ### Additional Information The OpenAPI serializer extension for `IntegerRangeSerializer` returns an **array of arrays** for a single range; with `many=True` on `vid_ranges`, drf‑spectacular wraps it again, causing triple nesting. ### Proposed Fix (schema extension) ```python # netbox/core/api/schema.py class FixIntegerRangeSerializerSchema(OpenApiSerializerExtension): target_class = 'netbox.api.fields.IntegerRangeSerializer' def map_serializer(self, auto_schema, direction): # One range = two integers; many=True will wrap this in an outer array return { "type": "array", "items": {"type": "integer"}, "minItems": 2, "maxItems": 2, } ```
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:48:36 +01:00
adam closed this issue 2025-12-29 21:48:36 +01:00
Author
Owner

@pheus commented on GitHub (Oct 3, 2025):

I’ve identified a root cause and I’m happy to open a PR if this report is accepted.

@pheus commented on GitHub (Oct 3, 2025): I’ve identified a root cause and I’m happy to open a PR if this report is accepted.
Author
Owner

@arthanson commented on GitHub (Oct 3, 2025):

I'll assign to you @pheus thanks!

@arthanson commented on GitHub (Oct 3, 2025): I'll assign to you @pheus thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11683