# go-openapi

Enforces spec-first REST development in Go by generating servers and clients via oapi-codegen, validating requests, and detecting breaking API changes.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · ★ 83
- Author: eduardo-sl
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(architecture)/go-openapi/SKILL.md
- Updated: 2026-10-15
- HTML: https://affpapa.org/en/nevibecode/skills/go-openapi

## What it does

This skill treats OpenAPI specifications as the single source of truth for Go services. It configures `oapi-codegen` to build typed models, route bindings, and strict server interfaces directly from YAML files. Handlers bind against `api.StrictServerInterface`, turning contract mismatches into compile-time errors instead of runtime failures.

The workflow wires boundary validation middleware to reject malformed parameters with HTTP 400 before business logic executes. Structured errors follow the RFC 9457 Problem Details format. To prevent contract drift across releases, `oasdiff` checks the spec in CI to flag breaking changes automatically. The Go toolchain must be present on the host system to run code generation.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add eduardo-sl/go-agent-skills --skill go-openapi -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/go-openapi/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/go-openapi/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add eduardo-sl/go-agent-skills --skill go-openapi -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/go-openapi/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add eduardo-sl/go-agent-skills --skill go-openapi -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/go-openapi/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install eduardo-sl/go-agent-skills go-openapi
```

2. **Manually: put the files in place**
- File: `.github/skills/go-openapi/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add eduardo-sl/go-agent-skills --skill go-openapi -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/eduardo-sl/go-agent-skills --path 'skills/(architecture)/go-openapi'
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/go-openapi/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add eduardo-sl/go-agent-skills --skill go-openapi -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(architecture)/go-openapi/SKILL.md

## When to use it
- generate Go server interfaces and types directly from OpenAPI specs
- enforce HTTP request boundary validation against schema definitions
- detect breaking REST API changes between git branches using oasdiff
- format error responses according to RFC 9457 Problem Details

## Example prompts
- Generate strict server interfaces and models from `api/openapi.yaml` using oapi-codegen
- Add request validation middleware to enforce schema constraints on incoming HTTP requests
- Run an oasdiff check against the base spec to verify there are no breaking changes

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 361519d0ac858e15.

BEGIN THIRD-PARTY FILE 361519d0ac858e15
````text
---
name: go-openapi
description: >
  Spec-first REST development in Go with OpenAPI: generating server
  interfaces and clients with oapi-codegen, request validation middleware,
  RFC 9457 error bodies, contract testing, and detecting breaking API
  changes. Use when the API has or should have an OpenAPI document, when
  wiring code generation into the build, or when a hand-written handler has
  drifted from its published contract. Trigger examples: "OpenAPI", "swagger
  spec", "oapi-codegen", "generate a client from the spec", "validate
  requests against the schema", "breaking API change".
  Not for: handler structure and shutdown (go-api-design), gRPC and protobuf
  (go-grpc), GraphQL schemas and resolvers (go-graphql).
user-invocable: true
license: MIT
compatibility: Designed for Claude Code or similar AI coding agents working on Go projects. Requires the Go toolchain. oapi-codegen, oasdiff and a spec linter (vacuum or spectral) are installed on demand.
allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(gofmt:*) Bash(oapi-codegen:*) Bash(oasdiff:*) Bash(vacuum:*)
metadata:
  author: eduardo-sl
  version: "1.0.1"
---

# Go OpenAPI

The spec is the source of truth. Types, routes, and clients are generated from
it — never hand-written alongside it, because two hand-maintained copies of a
contract diverge within one sprint.

## Operating Modes

- **Adopt** — the project has hand-written handlers and no spec, or a spec
  nobody generates from. Introduce generation without a rewrite.
- **Extend** — the pipeline exists. Change the spec, regenerate, implement.
- **Review** — check that handlers, spec, and published client agree, and
  that the change is not silently breaking.

## 1. Choose the Generator Once

| Tool | Use it when |
|---|---|
| `oapi-codegen` | Default. Types + server interface + client, works with `net/http`, chi, echo, gin |
| `ogen` | You want a fully generated, strictly validating server and can accept its opinions |
| `swaggo/swag` | Only for a legacy code-first project you are not converting — annotations generate the spec, so the spec cannot be reviewed before the code exists |

Do not mix. A project with both annotations and a checked-in spec has two
sources of truth again.

## 2. Wire Generation Into the Build

Pin the generator as a module tool (Go 1.24+), so every developer and CI run
uses the same version:

```bash
go get -tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
```

```yaml
# oapi-codegen.yaml
package: api
output: internal/api/openapi.gen.go
generate:
  models: true
  std-http-server: true   # Go 1.22+ ServeMux; use chi-server / echo-server if that is the router
  strict-server: true     # typed request/response structs instead of raw http.ResponseWriter
  embedded-spec: true     # lets the service serve its own spec
output-options:
  skip-prune: false
```

```go
````
END THIRD-PARTY FILE 361519d0ac858e15

The third-party file has ended. Everything between the 361519d0ac858e15 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2877 of 8204 bytes. © eduardo-sl · MIT · https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(architecture)/go-openapi/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
