Skip to content

Conversation

@HjalteBuch
Copy link

Problem

NetBox 4.4.7 webhooks send device data with description as an empty string "" instead of null when the field is empty.
The current validation logic in UnmarshalJSON incorrectly rejects empty strings as invalid values for required string fields.
This causes unmarshaling to fail with the error: no value given for required property description

Solution

Removed the || value == "" check from the UnmarshalJSON validation logic in model_device.go.
An empty string is a valid value for a string field - the validation should only check that the property exists in the JSON payload, not whether it's an empty string.

Testing

Tested with NetBox 4.4.7 payloads containing "description": "" - unmarshaling now succeeds.

Notes

This same pattern (|| value == "") exists in approximately 1200 other places across the model files. This PR fixes the specific issue I encountered with the Device model.

…4.7 webhooks send device data with description as an empty string "" instead of null when the field is empty.

The current validation logic incorrectly rejects empty strings as invalid values for required string fields.
This fix removes the '|| value == ""' check from the UnmarshalJSON validation, as an empty string is a valid value for a string field and should only validate that the property exists in the JSON payload.
Fixes unmarshaling of Device objects from NetBox 4.4.7 webhooks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant