equinix / equinix-sdk-go

Golang client for Equinix APIs
https://deploy.equinix.com/labs/equinix-sdk-go
MIT License
2 stars 4 forks source link

[Metal] default Metal Gateway responses do not match the API spec #64

Open ctreatma opened 6 days ago

ctreatma commented 6 days ago

This is a finding from investigation on https://github.com/equinix-labs/metal-go/issues/137. This also relates to https://github.com/equinix-labs/metal-go/issues/128.

The Metal Gateway API endpoints are all specified as returning the following schema:

oneOf:
- $ref: ./MetalGateway.yaml
- $ref: ./VrfMetalGateway.yaml

In OpenAPI 3, a oneOf has to match exactly one of the nested schemas, but by default, the Metal API response from Metal Gateway endpoints does not include enough information to differentiate between gateways (anything that matches the VrfMetalGateway schema will also match the MetalGateway schema).

This could be addressed with API changes, or possibly with spec changes that do not require an API change, but in the meantime the best workaround we have found is to add the following to all Metal Gateway API requests made with this SDK:

.Includes([]string{"ip_reservation"})

This workaround instructs the API to include IP reservation details in the API response. IPReservation and VrfIpReservation can be distinguished by the SDK, which enables the SDK to determine the gateway type (because MetalGateway has an IPReservation and VrfMetalGateway has a VrfIpReservation.

NOTE: because the Metal Gateway deletes are async, you also need to include the IP reservation in delete requests to avoid a response validation error.

You can see an example of the .Include() call here: https://github.com/equinix/terraform-provider-equinix/blob/611e78a32a865aa374d2e4896cd0978252b983c4/internal/resources/metal/gateway/resource.go#L173