# 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

```yml
go:
  version: 1.2.3
  modulePath: "github.com/my-company/company-go-sdk"
  sdkPackageName: "company"
```

## Additional dependencies

```yml
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.

```yml
go:
  retractions:
    - version: v1.0.0
      comment: Published accidentally
    - version: v1.0.1
```

## Method and parameter management

```yml
go
  maxMethodParams: 4
  methodArguments: "require-security-and-request"
```

## Security configuration

```yml
go
  envVarPrefix: SPEAKEASY
  flattenGlobalSecurity: true
```

## Import management

```yml
go
  imports:
    paths:
      callbacks: models/callbacks
      errors: models/errors
      operations: models/operations
      shared: models/components
      webhooks: models/webhooks
```

## Error and response handling

```yml
go:
  responseFormat: "envelope-http"
```

## Nullable and optional field handling

```yml
go:
  nullableOptionalWrapper: true
```

### When it applies

The wrapper is generated only for fields that are:

- Optional (the property is not listed in the parent schema's `required` array)
- Nullable (the property `type` includes `"null"` in OpenAPI 3.1)

For example, the following JSON Schema (OpenAPI 3.1) defines an optional, nullable `nickname`:

```yaml
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:

```go
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:

```go
// 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()`.
