snipe-it icon indicating copy to clipboard operation
snipe-it copied to clipboard

API: type of custom_fields in JSON inconsistent

Open SelfDrivingCarp opened this issue 4 years ago • 2 comments

Please confirm you have done the following before posting your bug report:

Describe the bug When retrieving hardware via the API the output JSON has a an inconsistent type for the custom_fields field. Sometimes it's an object with the custom fields, others it's an empty array. I'm guessing that the empty array is for assets with no fieldset for custom fields.

To Reproduce Steps to reproduce the behavior:

  1. Via the API, retrieve an asset with an associated fieldset
  2. Via the API, retrieve an asset with no associated fieldset
  3. Compare the type of custom_fields
  4. See that they differ

Expected behavior For assets with no associated fieldset, custom_fields should either be omitted or be an empty object.

For dynamic languages like Python this isn't really a big deal. I'm working in Go where you commonly unmarshal JSON directly into a static type. Without a custom unmarshaller, unmarshalling fails. I can create the custom unmarshaller as a workaround

Screenshots

Here's some redacted output of just the JSON of custom_fields for a few assets:

custom_fields:  []
custom_fields:  []
custom_fields:  {"_deprecated_ Asset Line":{"field":"_snipeit_deprecated_asset_line_2","value":null,"field_format":"NUMERIC"},"_deprecated_MAC Address":{"field":"_snipeit_deprecated_mac_address_1","value":null,"field_format":"MAC"},"YYYYY":{"field":"_snipeit_xxxxxxx_7","value":null,"field_format":"MAC"},"YYYYY":{"field":"_snipeit_xxxxxxx_8","value":"XXXXXX","field_format":"MAC"},"YYYYY":{"field":"_snipeit_xxxxxxx_3","value":"","field_format":"ANY"},"XXX":{"field":"_snipeit_xx_4","value":"XXXXXX","field_format":"ANY"}}
custom_fields:  {"_deprecated_ Asset Line":{"field":"_snipeit_deprecated_asset_line_2","value":null,"field_format":"NUMERIC"},"_deprecated_MAC Address":{"field":"_snipeit_deprecated_mac_address_1","value":null,"field_format":"MAC"},"XXXXXXXXX":{"field":"_snipeit_xxxxxxx_7","value":null,"field_format":"MAC"},"XXXXXX":{"field":"_snipeit_xxxxxxx_8","value":"XXXXXXXXXXXXXXXX","field_format":"MAC"},"XXXXX":{"field":"_snipeit_xxxxxxx_3","value":"","field_format":"ANY"},"YYY":{"field":"_snipeit_xx_4","value":"XXXXXXXXXXXX","field_format":"ANY"}}

Server (please complete the following information):

  • Snipe-IT Version: v5.0.12 - build 5705
  • OS: Cloud hosted on snipe-it.io
  • Web Server: Cloud hosted on snipe-it.io
  • PHP Version: Cloud hosted on snipe-it.io

SelfDrivingCarp avatar Jun 11 '21 23:06 SelfDrivingCarp

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

welcome[bot] avatar Jun 11 '21 23:06 welcome[bot]

I am still experiencing the exact same issue. Were there any developments to this?

viniciusdel avatar Sep 06 '22 17:09 viniciusdel

Was just about to make a duplicate issue, when I noticed that a fix had just been released. A happy surprise for a rustacean!

I wager this can be closed now as fixed @snipe.

StarlessNights avatar Dec 09 '22 12:12 StarlessNights