fbreckle / go-netbox

Package netbox provides an API client for DigitalOcean's NetBox IPAM and DCIM service.
Other
1 stars 22 forks source link

:sparkles: Allow User Token's WriteEnabled field #24

Closed keshy7 closed 1 year ago

keshy7 commented 1 year ago

By default, Netbox's REST API sets User Token's write_enabled field to true. This means that if the field is not set explicitly in the request, Netbox would automatically set it to true.

This behavior results to an inconsistency if the value is set to false and omitempty is configured in the JSON tag. This is because by default, JSON Marshaller omits false booleans. Since the field is omitted, Netbox REST API would default it to true. Hence, an inconsistency would occur.

To fix this, simply remove the omitempty tag from the writable token.

References:

fbreckle commented 1 year ago

Hi

I actually make changes like this a lot. To allow for reproducable generation of the client, I modify the swagger file with a script that takes the original swaggerfile and modifies it before library generation.

See https://github.com/fbreckle/go-netbox/blob/f7f714c3510360dde34f30144b5c3b9a3ff2e6ae/preprocess.py#L144 and the following lines.

Can you please:

  1. modify the script to add the omitempty = false header
  2. run the script (you can use make preprocess for that)
  3. generate the client with `make generate´
  4. add all changes to this MR, including the modified preprocess script, the modified swagger file and changes in the go code generated
keshy7 commented 1 year ago

Thank you for the clear direction, @fbreckle! The corresponding changes are now in.