api/

directory
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2026 License: Apache-2.0

README

Generated API Client

This directory contains the auto-generated Go client for the Turbonomic API using oapi-codegen.

Directory Structure

api/
├── README.md           # This file
├── config.yaml         # oapi-codegen configuration
└── generated/          # Generated code (do not edit manually)
    └── client.gen.go   # Generated client and types

The upstream OpenAPI specification is read from: ../api/com.vmturbo.api/target/swagger/openapi3/openapi3.yaml

Prerequisites

Install oapi-codegen:

make install-tools

Generating the Client

make generate

To use a different spec path:

make generate OPENAPI_SPEC=/path/to/openapi3.yaml
How generation works
  1. make preprocess-spec — runs scripts/preprocess-spec.sh which patches the upstream spec: renames {entity_Uuid} path parameters, strips null enum values, and merges duplicate path definitions.
  2. make generate — calls oapi-codegen -config api/config.yaml on the preprocessed spec. compatibility.always-prefix-enum-values prevents enum constant name collisions.

Configuration

config.yaml controls code generation:

package: generated
generate:
  client: true              # Generate HTTP client
  models: true              # Generate data models
  embedded-spec: false      # Do not embed OpenAPI spec in the binary

compatibility:
  always-prefix-enum-values: true   # Prefix all enum constants with their type name
                                    # (e.g. GroupByCriterionGroupType, not GroupType)
                                    # Prevents clashes with other generated types.

output: api/generated/client.gen.go
output-options:
  skip-prune: true
  response-type-suffix: Resp        # Rename client response wrappers to *Resp
                                    # to avoid clashes with schema types named *Response

Notes

  • The generated/ directory is gitignored — it is regenerated on demand
  • Always regenerate after updating the OpenAPI spec
  • Do not manually edit the generated code; put customisations in the v2 wrapper package
  • Use the v2 wrapper package for authentication, session management, and custom headers

Known Issues

GroupType / Origin redeclared after regeneration

Status: resolved — compatibility.always-prefix-enum-values: true in config.yaml makes oapi-codegen emit GroupByCriterionGroupType / GroupByCriterionOrigin directly, so the clash no longer occurs.

If you see this error after regeneration it means always-prefix-enum-values was removed from the config:

api/generated/client.gen.go: GroupType redeclared in this block
api/generated/client.gen.go: Origin redeclared in this block

Re-add always-prefix-enum-values: true under compatibility in api/config.yaml and regenerate.

Duplicate types for client response wrapper types

Status: resolved — response-type-suffix: Resp in config.yaml renames the generated HTTP client response wrapper types from *Response to *Resp, keeping them distinct from any schema types of the same name.

If the error reappears after regeneration:

./client.gen.go: UpdateClientResponse redeclared in this block

Check that response-type-suffix is still set in api/config.yaml.

Directories

Path Synopsis
Package generated provides primitives to interact with the openapi HTTP API.
Package generated provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL