meraki / openapi

This repository contains OpenAPI specifications for the Meraki Dashboard API
https://meraki.com/developers
25 stars 19 forks source link

getOrganizationDevicesStatuses response of wrong type #50

Open stephengroat opened 1 year ago

stephengroat commented 1 year ago

Error on GetOrganizationDevicesStatuses unmarshal in OrganizationApi

json: cannot unmarshal object into Go struct field GetOrganizationDevicesStatuses200ResponseInnerComponents.components.powerSupplies of type string

currently marked as array of string in spec

see https://github.com/meraki/dashboard-api-go/issues/18

TKIPisalegacycipher commented 1 year ago

Hi @stephengroat please mention the specific part of the OAS if you believe there is an issue with the spec so we can investigate. What you've provided so far does not point directly to any section of our OAS.

stephengroat commented 1 year ago
        "operationId": "getOrganizationDevicesStatuses",
...
                  "components": {
                    "type": "object",
                    "properties": {
                      "powerSupplies": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        },
                        "description": "Power Supplies"
                      }
                    },
                    "description": "Components"
                  },

as seen in the error message

json: cannot unmarshal object into Go struct field GetOrganizationDevicesStatuses200ResponseInnerComponents.components.powerSupplies of type string

powerSupplies is showing as type string, instead of an array of string

stephengroat-dd commented 1 year ago

👋 wondering if anymore information is needed to triage

jyoung15 commented 1 year ago

I ran into this issue as well. It seems the API returns an object array instead of a string array. Example:

{
  "powerSupplies": [
    {
      "slot": 1,
      "serial": "XXXX-XXXX-XXXX",
      "model": "PWR-MS320-1025WAC",
      "status": "powering",
      "poe": {
        "unit": "watts",
        "maximum": 740
      }
    },
    {
      "slot": 2,
      "serial": "",
      "model": "",
      "status": "disconnected",
      "poe": {
        "unit": "watts",
        "maximum": 0
      }
    }
  ]
}

Until the spec can be corrected, the following can be applied to address https://github.com/meraki/dashboard-api-go/issues/18:

diff --git a/client/model_get_organization_devices_statuses_200_response_inner_components.go b/client/model_get_organization_devices_statuses_200_response_inner_components.go
index cae93d96..c38caf6b 100644
--- a/client/model_get_organization_devices_statuses_200_response_inner_components.go
+++ b/client/model_get_organization_devices_statuses_200_response_inner_components.go
@@ -17,10 +17,23 @@ import (
 // checks if the GetOrganizationDevicesStatuses200ResponseInnerComponents type satisfies the MappedNullable interface at compile time
 var _ MappedNullable = &GetOrganizationDevicesStatuses200ResponseInnerComponents{}

+type Poe struct {
+       Unit    string `json:"unit"`
+       Maximum int    `json:"maximum"`
+}
+
+type PowerSupply struct {
+       Slot   int    `json:"slot"`
+       Serial string `json:"serial"`
+       Model  string `json:"model"`
+       Status string `json:"status"`
+       Poe    Poe    `json:"poe"`
+}
+
 // GetOrganizationDevicesStatuses200ResponseInnerComponents Components
 type GetOrganizationDevicesStatuses200ResponseInnerComponents struct {
        // Power Supplies
-       PowerSupplies []string `json:"powerSupplies,omitempty"`
+       PowerSupplies []PowerSupply `json:"powerSupplies,omitempty"`
 }

 // NewGetOrganizationDevicesStatuses200ResponseInnerComponents instantiates a new GetOrganizationDevicesStatuses200ResponseInnerComponents object
@@ -41,9 +54,9 @@ func NewGetOrganizationDevicesStatuses200ResponseInnerComponentsWithDefaults() *
 }

 // GetPowerSupplies returns the PowerSupplies field value if set, zero value otherwise.
-func (o *GetOrganizationDevicesStatuses200ResponseInnerComponents) GetPowerSupplies() []string {
+func (o *GetOrganizationDevicesStatuses200ResponseInnerComponents) GetPowerSupplies() []PowerSupply {
        if o == nil || IsNil(o.PowerSupplies) {
-               var ret []string
+               var ret []PowerSupply
                return ret
        }
        return o.PowerSupplies
@@ -51,7 +64,7 @@ func (o *GetOrganizationDevicesStatuses200ResponseInnerComponents) GetPowerSuppl

 // GetPowerSuppliesOk returns a tuple with the PowerSupplies field value if set, nil otherwise
 // and a boolean to check if the value has been set.
-func (o *GetOrganizationDevicesStatuses200ResponseInnerComponents) GetPowerSuppliesOk() ([]string, bool) {
+func (o *GetOrganizationDevicesStatuses200ResponseInnerComponents) GetPowerSuppliesOk() ([]PowerSupply, bool) {
        if o == nil || IsNil(o.PowerSupplies) {
                return nil, false
        }
@@ -68,7 +81,7 @@ func (o *GetOrganizationDevicesStatuses200ResponseInnerComponents) HasPowerSuppl
 }

 // SetPowerSupplies gets a reference to the given []string and assigns it to the PowerSupplies field.
-func (o *GetOrganizationDevicesStatuses200ResponseInnerComponents) SetPowerSupplies(v []string) {
+func (o *GetOrganizationDevicesStatuses200ResponseInnerComponents) SetPowerSupplies(v []PowerSupply) {
        o.PowerSupplies = v
 }
TKIPisalegacycipher commented 1 year ago

Hello @stephengroat, @stephengroat-dd and @jyoung15:

Do you have this issue if you use instead the following endpoints for the same information? FWIW the getOrganizationDevicesStatuses endpoint has better alternatives:

If you are only concerned with right-now status of devices: getOrganizationDevicesAvailabilities If you are only concerned with right-now power supply statuses: getOrganizationDevicesPowerModulesStatusesByDevice If you are polling device status over time, then this third endpoint is more efficient: getOrganizationDevicesAvailabilitiesChangeHistory If you need uplinks addresses, then this is the best way to get that information: getOrganizationDevicesUplinksAddressesByDevice

I'm not aware of any schema issues on the aforementioned endpoints.

stephengroat commented 10 months ago

Sorry, this is the only endpoint that works for my use case.

Is there going to be any fix upcoming for this bug?

TKIPisalegacycipher commented 10 months ago

Hi @stephengroat, what's the use case?

stephengroat-dd commented 10 months ago

@TKIPisalegacycipher We collect every IP that meraki records on every device for historical evidence

TKIPisalegacycipher commented 10 months ago

Thanks @stephengroat-dd! This operation is the best way to get that information: getOrganizationDevicesUplinksAddressesByDevice