Go configuration options
This section details the available configuration options for the Go SDK. All configuration is managed in the gen.yaml file under the go section.
Version and general configuration
go:
version: 1.2.3
modulePath: "github.com/my-company/company-go-sdk"
sdkPackageName: "company"Additional dependencies
go:
additionalDependencies:
axios: "0.21.0"Retractions
You can use retractions to mark specific versions of your Go module as unsuitable for use. Each retraction requires a version and can optionally include a comment explaining why the version was retracted.
go:
retractions:
- version: v1.0.0
comment: Published accidentally
- version: v1.0.1Method and parameter management
go
maxMethodParams: 4
methodArguments: "require-security-and-request"Security configuration
go
envVarPrefix: SPEAKEASY
flattenGlobalSecurity: trueImport management
go
imports:
paths:
callbacks: models/callbacks
errors: models/errors
operations: models/operations
shared: models/components
webhooks: models/webhooksError and response handling
go:
responseFormat: "envelope-http"Nullable and optional field handling
go:
nullableOptionalWrapper: trueWhen it applies
The wrapper is generated only for fields that are:
- Optional (the property is not listed in the parent schema’s
requiredarray) - Nullable (the property
typeincludes"null"in OpenAPI 3.1)
For example, the following JSON Schema (OpenAPI 3.1) defines an optional, nullable nickname:
type: object
required:
- id
properties:
id:
type: string
nickname:
type:
- string
- "null"Generated code
With nullableOptionalWrapper: true, the corresponding Go model uses a wrapper type:
type Pet struct {
ID string `json:"id"`
Nickname optionalnullable.OptionalNullable[string] `json:"nickname,omitempty"`
}Without the wrapper (when disabled for existing SDKs), the same field may be generated as a pointer type.
Using the wrapper
Set values using helper constructors on OptionalNullable and retrieve values via Get(), which returns (*T, bool) — ok indicates presence, and a nil pointer indicates an explicit null value:
// Set a present, non-null value
pet := shared.Pet{}
nickname := "Finn"
pet.Nickname = optionalnullable.From(&nickname)
// Read a value
if val, ok := pet.Nickname.Get(); ok {
if val == nil {
fmt.Println("nickname is explicitly null")
} else {
fmt.Println("nickname:", *val)
}
} else {
fmt.Println("nickname not set")
}Enabling this flag changes the generated field type and how values are set and read. This is a breaking change for existing SDKs and requires migrating code that accessed those fields directly or through pointer checks to use optionalnullable.From(...) and .Get().
Last updated on