equinix-labs / metal-go

[Deprecated] Golang client for Equinix Metal
https://deploy.equinix.com/labs/equinix-sdk-go/
MIT License
3 stars 2 forks source link

Generate OpenAPI spec-compliant code #85

Closed ctreatma closed 1 year ago

ctreatma commented 1 year ago

In order to ensure that the code we generate behaves according to the OpenAPI specification, we need to set disallowAdditionalPropertiesIfNotPresent to false.

The OpenAPI specification is built on top of the JSON schema spec. In the JSON schema spec, additionalProperties defaults to true in order to maximize forward compability: a client library should not break because a new property was added to an response.

The default behavior of the OpenAPI generator is to generate code that does not provide access to additionalProperties, and that validates API responses inconsistently (in, e.g., oneOf schemas, additional properties will fail validation, but passing the same JSON to the same model outside of a oneOf will pass validation).

Generating code according to the OpenAPI spec makes our code more predictable and forces us to document any restrictions on additional properties in our API spec.

Fixes #82

ctreatma commented 1 year ago

Making additional properties accessible, as done in this PR, is an alternative way to work around missing fields in the spec. Patching would still be the preferred approach, but having the option to use additionalProperties can unblock SDK users while they wait for spec fixes/patches.