Skip to content

Conversation

@jnovinger
Copy link
Member

Fixes: #20638

POST operations on NetBoxModelViewSet endpoints accept both single objects and arrays, but the schema only documented single objects. This prevented REST API client generators from producing correct code.

Add explicit bulk_create_enabled flag to NetBoxModelViewSet and update schema generation to emit oneOf for these endpoints.

FWIW, I don't believe the PUT issue reported is a bug. The schema seems to correctly document PUT as array-only. NetBox's PUT is a bulk operation by design. For single updates, use PATCH /api/model/{id}/.

POST operations on NetBoxModelViewSet endpoints accept both single
objects and arrays, but the schema only documented single objects.
This prevented API client generators from producing correct code.

Add explicit bulk_create_enabled flag to NetBoxModelViewSet and
update schema generation to emit oneOf for these endpoints.
@jnovinger jnovinger requested review from a team and arthanson and removed request for a team November 10, 2025 12:00
@jeremystretch jeremystretch requested review from jeremystretch and removed request for arthanson November 10, 2025 13:40

# Declare that this viewset accepts either single objects or arrays for creation
# Refs: #20638
bulk_create_enabled = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we shouldn't rely on an explicit declaration of functionality as this can be unreliable. Rather, we should infer bulk creation ability from the existence of some inherent indicator. For instance, we could detect bulk update support by the existence of a bulk_update() method.

We might be able to achieve this by declaring a separate bulk_create() method and extending NetBoxRouter to route to it for POST operations on the list view. I suspect this would simplify some of the logic under NetBoxAutoSchema as well.


return response_serializers

def _get_request_for_media_type(self, serializer, direction):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To preserve the default

Suggested change
def _get_request_for_media_type(self, serializer, direction):
def _get_request_for_media_type(self, serializer, direction='request'):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swagger UI generating incorrect schemas for /users/users/ endpoint

3 participants