oxidecomputer / oxide.go

The Go SDK for Oxide.
Mozilla Public License 2.0
17 stars 3 forks source link

Account for additional fields "array" types that don't specify map keys #235

Closed karencfv closed 1 month ago

karencfv commented 1 month ago

Our OpenAPI spec defines maps in the following manner:

"Silo": {
  "description": "View of a Silo\n\nA Silo is the highest level unit of isolation.",
  "type": "object",
  "properties": {
    "mapped_fleet_roles": {
      "description": "Mapping of which Fleet roles are conferred by each Silo role\n\nThe default is that no Fleet roles are conferred by any Silo roles unless there's a corresponding entry in this map.",
      "type": "object",
      "additionalProperties": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/FleetRole"
        },
        "uniqueItems": true
      }
    }
  },
  "required": [
    "mapped_fleet_roles",
  ]
}

In this scenario this should be parsed into

type Silo struct {
    // MappedFleetRoles is mapping of which Fleet roles are conferred by each Silo role
    //
    // The default is that no Fleet roles are conferred by any Silo roles unless there's a corresponding entry in this map.
    MappedFleetRoles map[string][SiloRole]FleetRole `json:"mapped_fleet_roles,omitempty" yaml:"mapped_fleet_roles,omitempty"`
}

But, our API spec makes no mention of SiloRole. To avoid making any hardcoded one-offs, we will be setting the map key to be a string. This should be changed once our OpenAPI spec mentions the key type