Skip to content

Code Generation Configuration

The codegen.yml file controls how Go types and handlers are generated from your OpenAPI specification.

Connexions uses oapi-codegen-dd for code generation.

Location

Place codegen.yml in the setup/ directory:

services/petstore/
└── setup/
    ├── codegen.yml     # Code generation settings
    ├── config.yml      # Service configuration
    └── openapi.yml     # OpenAPI specification

Default Configuration

The default codegen.yml generated by the service command:

package: types
output:
  use-single-file: false
  directory: ../
generate:
  omit-description: true
  default-int-type: int64
  always-prefix-enum-values: true
  validation:
    response: true
additional-imports:
  - package: github.com/go-playground/validator/v10
error-mapping:

Key Options

Package and Output

package: types              # Go package name for generated types
output:
  use-single-file: false    # Split types into multiple files
  directory: ../            # Output relative to setup/

Type Generation

generate:
  omit-description: true           # Skip schema descriptions in comments
  default-int-type: int64          # Default integer type
  always-prefix-enum-values: true  # Prefix enum values with type name
  validation:
    response: true                 # Generate Validate() methods

Filtering Operations

Filter which operations to generate:

filter:
  include:
    operation-ids:
      - GetPets
      - CreatePet
    tags:
      - pets
    paths:
      - /pets
      - /pets/{id}
  exclude:
    operation-ids:
      - DeletePet

Additional Imports

Add custom imports to generated code:

additional-imports:
  - package: github.com/go-playground/validator/v10
  - package: github.com/google/uuid
    alias: guuid

Error Mapping

Map response types to implement the error interface:

error-mapping:
  Error: true
  APIError: true

Custom Configuration

You can provide a custom codegen.yml when generating services:

go run github.com/cubahno/connexions/v2/cmd/gen/service@latest \
  -name petstore \
  -codegen-config ./my-codegen.yml \
  https://petstore3.swagger.io/api/v3/openapi.json

The custom config is merged with the default template.

Full Documentation

For complete configuration options, see the oapi-codegen-dd documentation: