Change API-Documentation for AvailailableIP/Prefix to accept list of objects #6958

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

Originally created by @amhn on GitHub (Sep 9, 2022).

NetBox version

v3.3.3

Feature type

Change to existing functionality

Proposed functionality

This is similar to #9471. But instead of changing the function, i propose to change only the API-Documentation.

The current swagger.json documents the functions to accept an object as input and return a list of objects. As far as i can see both can never be met. If the in put is a single object, the return value is always a single object, but never a list.

Changing the annotation in the post function of AvailableIPAddressesView from

request_body=serializers.AvailableIPSerializer

to

request_body=ListSerializer(serializers.AvailableIPSerializer)

changes the swagger.json while not affecting the functionality. The same can be done for AvailablePrefix.

The diff looks something like

60400c77296,77299
<                     "schema" : { "$ref" : "#/definitions/WritableAvailableIP" }
---
>                     "schema" : { 
>                         "items" : { "$ref" : "#/definitions/WritableAvailableIP" },
>                         "type" : "array"
>                       }
62497c79701,79704
<                     "schema" : { "$ref" : "#/definitions/PrefixLength" }
---
>                     "schema" : { 
>                         "items" : { "$ref" : "#/definitions/PrefixLength" },
>                         "type" : "array"
>                       }

If you want I can create a PR for this.

Use case

This would help users of strongly typed languages to generate a working library from swagger.json.

While not ideal, at least this allows users of the library to use this functionality by always providing a list, even for a single value.

Database changes

None

External dependencies

None

Originally created by @amhn on GitHub (Sep 9, 2022). ### NetBox version v3.3.3 ### Feature type Change to existing functionality ### Proposed functionality This is similar to #9471. But instead of changing the function, i propose to change only the API-Documentation. The current swagger.json documents the functions to accept an object as input and return a list of objects. As far as i can see both can never be met. If the in put is a single object, the return value is always a single object, but never a list. Changing the annotation in the post function of AvailableIPAddressesView from ``` request_body=serializers.AvailableIPSerializer ``` to ``` request_body=ListSerializer(serializers.AvailableIPSerializer) ``` changes the swagger.json while not affecting the functionality. The same can be done for AvailablePrefix. The diff looks something like ``` 60400c77296,77299 < "schema" : { "$ref" : "#/definitions/WritableAvailableIP" } --- > "schema" : { > "items" : { "$ref" : "#/definitions/WritableAvailableIP" }, > "type" : "array" > } 62497c79701,79704 < "schema" : { "$ref" : "#/definitions/PrefixLength" } --- > "schema" : { > "items" : { "$ref" : "#/definitions/PrefixLength" }, > "type" : "array" > } ``` If you want I can create a PR for this. ### Use case This would help users of strongly typed languages to generate a working library from swagger.json. While not ideal, at least this allows users of the library to use this functionality by always providing a list, even for a single value. ### Database changes None ### External dependencies None
adam added the type: featurepending closure labels 2025-12-29 19:47:11 +01:00
adam closed this issue 2025-12-29 19:47:11 +01:00
Author
Owner

@amhn commented on GitHub (Sep 10, 2022):

I thought about this a little more. If the Input object could be changed to WritableIpAddressSerializer it would be possible to create an object and set description, tenant and other parameters in just one API-Request.

For AvailablePrefix this does not work directly. Maybe adding a field data = WritablePrefixSerializer toPrefixLengthSerializer would be a solution. Maybe the same should be done for available-ip to help with backward compatibility.

As per spec address and prefix are required fields in the writable serializers, these would have to be ignored and the return values of available-ip/prefix should be used.

Currently my workflow consists of requesting an IP and then doing a PUT request to update all fields. This results in 2 changelog entries for 1 change.

@amhn commented on GitHub (Sep 10, 2022): I thought about this a little more. If the Input object could be changed to WritableIpAddressSerializer it would be possible to create an object and set description, tenant and other parameters in just one API-Request. For AvailablePrefix this does not work directly. Maybe adding a field `data = WritablePrefixSerializer` toPrefixLengthSerializer would be a solution. Maybe the same should be done for available-ip to help with backward compatibility. As per spec address and prefix are required fields in the writable serializers, these would have to be ignored and the return values of available-ip/prefix should be used. Currently my workflow consists of requesting an IP and then doing a PUT request to update all fields. This results in 2 changelog entries for 1 change.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 10, 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 10, 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 11, 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 11, 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#6958