Skip to main content

Announcing Major Updates to Go SDKs

· 6 min read

We have introduced some significant enhancements and new features in our Go SDK.

Multiple Authentication Scheme Support

Our Go SDK now supports multiple authentication schemes. With this update, you can authorize your API calls using various combinations of security schemes.

What Has Changed?

This release introduces improvements to the interface of the ‘Configuration’ structure for setting up authentication credentials in the Go SDK. The credentials for each security scheme are now grouped into one instance, ensuring clean and descriptive client initialization. Explore the updated Go client initialization in our documentation for more details.

note

The previous Single Authentication flow is now unified with the Multiple Authentication flow.

oneOf and anyOf Support

We are pleased to introduce support for oneOf and anyOf types in our Go SDKs. For a detailed overview of this support, please refer to the detailed documentation.

Revamping Go Code Samples

Revamping of Go Code Samples brings significant improvements to generated code samples, especially in initializing parameters for APIs. Notable changes include simplifying code samples, fixing linting issues, and addressing bugs to enhance code readability and functionality. For detailed documentation about the revamping, please visit here.

Dynamic Error Messages Support

What Has Changed?

Previously, APIMatic's generated Go SDK supported Custom Error Messages, but the support for default cases and ranged HTTP response codes (4XX, 5XX) was missing. Now, with the improvements in Custom Error Messages for the Golang SDK, you can also customize these ranged error messages to provide meaningful information for failed calls. For more details on this feature, refer to Custom Error Messages.

OpenAPI v3.0
"responses": {
"0": {
"description": "Custom error message for default case."
},
"4XX": {
"description": "Custom Error template 4XX."
},
"500": {
"description": "Custom error message for 500."
}
}

Although Custom Error Messages support customizing error responses, there was previously no way to provide information from the exception at runtime. To address this limitation, we have introduced Dynamic Error Messages, allowing users to define templated placeholders that are populated at runtime. This feature can be configured by defining errors at either the endpoint level or globally.

OpenAPI v3.0
"ErrorTemplates": {
"0": "Dynamic error message for default case: {$statusCode}, accept => {$response.header.content-type}, body => {$response.body}.",
   "4XX": "Dynamic Error template 4XX: {$statusCode}, accept => {$response.header.content-type}, body => {$response.body#/unknownProperty}.",
   "402": "Dynamic Error template 40X: {$statusCode}, accept => {$response.header.content-type}, body => {$response.body#/unknownProperty}.",
   "500": "Dynamic error message for 500",
}

Now, whenever an API call fails, dynamically configured error messages will be provided. For instance, in the case of error 402, the SDK will surface the following error response:

Dynamic Error template 40X: `402`, accept => `application/json`, body => `The HTTP 402 status code indicates that the client must make a payment to access the requested resource`."

For more details on Dynamic Error Messages, please refer to our feature documentation.

Array Serialization Support

This serialization setting allows you to configure marshaling and un-marshaling values in APIMatic's Go SDK. This setting adds an array serialization scheme for primitive types (applicable to form and query params). Allowed values are: Indexed, UnIndexed, Plain, CSV, TSV, PSV. For more information refer to its documentation.

What Has Changed?

To use this feature in the Go SDK, you need to specify an ArraySerialization value. By default, its value is set to Indexed.

`vehicleData[1]=1&vehicleData[2]=2`

WrapBodyInObject Support

It is an endpoint setting used to wrap multiple body parameters in a single object, which provides ease in marshaling and unmarshalling body parameters in Go SDK.

What Has Changed?

In the API specification, this setting will be enabled (true) at the endpoint level. By default, it is disabled (false). For more information about its multiple-body-parameters ruleset, you can refer to its documentation.

CollectParameters Support

It is also an endpoint setting used to collect more than one parameter into a single collection (map), which provides ease in initializing parameters in Go SDK. For more information about CollectParameters, and it's ruleset regarding same-parameters-name-for-parameter-collection, you can refer to their documentation.

Enable Additional Model Properties Support

This setting comes under the category of Model Code Generation Settings, this setting allows to add additional properties of models that are not part of the model description, by default these properties will be discarded during marshaling and unmarshalling of the model.

What Has Changed?

To integrate this setting, you can follow its documentation. In the generated Golang code, you will find an additional field named AdditionalProperties in all your models. This field is responsible for handling additional model properties. Additionally, it has a special JSON tag json:"_" that is used to ignore this field during marshaling and unmarshaling.

type Car struct {
   ...
   AdditionalProperties map[string]any `json:"_"`
   ...
}

Allow Dynamic Form/Query Parameters Support

Allow Dynamic Form Parameters

This is an optional advanced setting used to customize the generated code for endpoint parameters, allowing the inclusion of additional form Parameters not described in the endpoint definition. Its documentation will provide more insights about allowDynamicFormParameters.

func (f *FormParamsController) AllowDynamicFormParam(
   ...
   formParams map[string]any)

Allow Dynamic Query Parameters

This is also an optional advanced setting used to customize the generated code for endpoint parameters, allowing additional query parameters that are not described in the endpoint definition to be passed. Its documentation can provide more information about allowDynamicQueryParameters.

func (q *QueryParamController) OptionalDynamicQueryParam(
   ...
   queryParams map[string]any)

IsLatestVersion Support

IsLatestVersion is an SDK Docs Configuration setting that allows you to transform your installation commands into generic ones. This way, you can avoid the need to update the documentation with each SDK release. More details can be found here.

What Has Changed?

$ go get github.com/apimatic-com/ab-golang-sdk
You can also view the package at: https://pkg.go.dev/github.com/apimatic-com/ab-golang-sdk