Adding extra models to swagger spec #6603

Closed
opened 2025-12-29 19:42:55 +01:00 by adam · 3 comments
Owner

Originally created by @amhn on GitHub (Jun 27, 2022).

NetBox version

v3.2.5

Feature type

Change to existing functionality

Proposed functionality

The current swagger spec states that PATCH for e.g. /virtualization/virtual-machines/{id}/ needs to use the WritableVirtualMachineWithConfigContext model. This model defines the properties "name" and "cluster" as required.

The actual API endpoint accepts requests without either one of those, e.g.:

curl \
  -H "Content-Type: application/json" \
  -H "Authorization: Token $NETBOX_TOKEN" \
   https://$NETBOX_URL/api/virtualization/virtual-machines/376/ \
  -X PATCH -d "{\"primary_ip4\":null}"

returns a modified object with a 200 status code.

To fix this difference a new model could be created e.g. PartialWritableVirtualMachineWithConfigContext (naming suggestions welcome :-)), this model would contain the same fields as the original, except marking the required fields optional.

The same problem exist for the bulk_update, bulk_delete and bulk_partial_update which don't even list "id" as a property while it is required by the API endpoints. Here the "id" field would have to be marked required and readonly=False

While this creates a lot of models (up to 6 per django model), it would ease the use of code generated from the swagger spec.

A very rough draft of the possible changes is in https://github.com/amhn/netbox/tree/add_extra_models_to_swagger_spec

Use case

This change would make the life of API users easier, especially for generated code from the swagger spec.

Currently in code generated with go-swagger you have to fill some fields for a PATCH request, even if you don't want to change them.

I have not yet checked it, but I assume the bulk operations are not usable in the generated code, because you can not set the "id" property while the API requires it.

Database changes

No response

External dependencies

No response

Originally created by @amhn on GitHub (Jun 27, 2022). ### NetBox version v3.2.5 ### Feature type Change to existing functionality ### Proposed functionality The current swagger spec states that PATCH for e.g. /virtualization/virtual-machines/{id}/ needs to use the WritableVirtualMachineWithConfigContext model. This model defines the properties "name" and "cluster" as required. The actual API endpoint accepts requests without either one of those, e.g.: ``` curl \ -H "Content-Type: application/json" \ -H "Authorization: Token $NETBOX_TOKEN" \ https://$NETBOX_URL/api/virtualization/virtual-machines/376/ \ -X PATCH -d "{\"primary_ip4\":null}" ``` returns a modified object with a 200 status code. To fix this difference a new model could be created e.g. PartialWritableVirtualMachineWithConfigContext (naming suggestions welcome :-)), this model would contain the same fields as the original, except marking the required fields optional. The same problem exist for the bulk_update, bulk_delete and bulk_partial_update which don't even list "id" as a property while it is required by the API endpoints. Here the "id" field would have to be marked required and readonly=False While this creates a lot of models (up to 6 per django model), it would ease the use of code generated from the swagger spec. A very rough draft of the possible changes is in https://github.com/amhn/netbox/tree/add_extra_models_to_swagger_spec ### Use case This change would make the life of API users easier, especially for generated code from the swagger spec. Currently in code generated with go-swagger you have to fill some fields for a PATCH request, even if you don't want to change them. I have not yet checked it, but I assume the bulk operations are not usable in the generated code, because you can not set the "id" property while the API requires it. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: featurestatus: needs ownerpending closure labels 2025-12-29 19:42:55 +01:00
adam closed this issue 2025-12-29 19:42:55 +01:00
Author
Owner

@github-actions[bot] commented on GitHub (Aug 27, 2022):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Aug 27, 2022): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Nov 13, 2022):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Nov 13, 2022): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Dec 14, 2022):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Dec 14, 2022): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6603