API spec requires model fields on PATCH #2465

Closed
opened 2025-12-29 18:19:06 +01:00 by adam · 1 comment
Owner

Originally created by @lampwins on GitHub (Mar 14, 2019).

Environment

  • Python version: 3.7
  • NetBox version: develop-2.6

Steps to Reproduce

  1. Load the API spec /api/swagger.json

Expected Behavior

Model PATCH methods should not define required fields.

Observed Behavior

PATCH methods use the same definitions as POST and PUT methods, which define required model fields.

Screen Shot 2019-03-14 at 2 53 56 PM Screen Shot 2019-03-14 at 2 54 03 PM

This is an extension of conversations in #2665. @axnsan12 would you have any input on this? It seems like one way to do it would be to define separate serializers, but that doesn't seem fun and from reading the drf-yasg docs, picking the serializer based the request method isn't recommended anyway.

Originally created by @lampwins on GitHub (Mar 14, 2019). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.7 * NetBox version: develop-2.6 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a wrapper like pynetbox. --> ### Steps to Reproduce 1. Load the API spec `/api/swagger.json` <!-- What did you expect to happen? --> ### Expected Behavior Model PATCH methods should not define required fields. <!-- What happened instead? --> ### Observed Behavior PATCH methods use the same definitions as POST and PUT methods, which define required model fields. <img width="621" alt="Screen Shot 2019-03-14 at 2 53 56 PM" src="https://user-images.githubusercontent.com/1297132/54383825-500c3b00-4669-11e9-88fb-3c9952e6883b.png"> <img width="314" alt="Screen Shot 2019-03-14 at 2 54 03 PM" src="https://user-images.githubusercontent.com/1297132/54383835-57cbdf80-4669-11e9-9a12-a5013ca80594.png"> This is an extension of conversations in #2665. @axnsan12 would you have any input on this? It seems like one way to do it would be to define separate serializers, but that doesn't seem fun and from reading the drf-yasg docs, picking the serializer based the request method isn't recommended anyway.
adam added the type: bugstatus: accepted labels 2025-12-29 18:19:06 +01:00
adam closed this issue 2025-12-29 18:19:06 +01:00
Author
Owner

@jeremystretch commented on GitHub (Mar 31, 2020):

AFAICT this seems to be a bug in drf_yasg, where required fields are marked without respect to the type of request being made. I don't think this is something that we can reasonably fix within NetBox, but I may be wrong. Closing this out but will re-open if anyone wants to propose a specific fix.

@jeremystretch commented on GitHub (Mar 31, 2020): AFAICT this seems to be a bug in drf_yasg, where required fields are marked without respect to the type of request being made. I don't think this is something that we can reasonably fix within NetBox, but I may be wrong. Closing this out but will re-open if anyone wants to propose a specific fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2465