netbox-community / go-netbox

The official Go API client for Netbox IPAM and DCIM service.
Other
194 stars 144 forks source link

Unable to write json string to device's local_context_data #118

Closed stefanhipfel closed 1 year ago

stefanhipfel commented 3 years ago

Hi,

I currently want to write some struct data to a device's local_context_data. However since this parameter needs to be a *string (local_context_data), I need to json.Marshal my go struct to a string. When using the go openapi runtime as the client.Transport, it will however json.Encode the request body again (due to the mediaType being "application/json") which just escapes my json string (e.g. "{/"foo/":/"bar/"}). The Netbox API will then respond with a 400 error: PUT /dcim/devices/{id}/][400] dcim_devices_update default map[local_context_data:[JSON data must be in object form. Example: {“foo”: 123}]

The issue could be solved if the local_context_data parameter is an interface{}, so the runtime can correctly handle the json encoding! Was there a specific reason the have a string instead? Thanks

v0ctor commented 1 year ago

Closing, as now local_context_data is defined as an object in the OpenAPI specification.