|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +`github.com/go-openapi/runtime` is the runtime library for the go-openapi toolkit. |
| 8 | +It provides HTTP client and server components used by code generated by [go-swagger](https://github.com/go-swagger/go-swagger) |
| 9 | +and for untyped OpenAPI/Swagger API usage. |
| 10 | + |
| 11 | +See [docs/MAINTAINERS.md](../docs/MAINTAINERS.md) for CI/CD, release process, and repo structure details. |
| 12 | + |
| 13 | +### Modules and Package layout |
| 14 | + |
| 15 | +This is a mono-repo with a `go.work` workspace containing two modules: |
| 16 | + |
| 17 | +| Module | Purpose | |
| 18 | +|--------|---------| |
| 19 | +| `.` (root) | Core runtime library | |
| 20 | +| `client-middleware/opentracing` | Optional OpenTracing middleware for client transport | |
| 21 | + |
| 22 | +Packages in the root module: |
| 23 | + |
| 24 | +| Package | Contents | |
| 25 | +|---------|----------| |
| 26 | +| `runtime` (root) | Core interfaces (`Consumer`, `Producer`, `Authenticator`, `Authorizer`, `OperationHandler`), content-type handlers (JSON, XML, CSV, text, bytestream), HTTP request/response helpers | |
| 27 | +| `client` | HTTP client transport: `Runtime` with TLS, timeouts, proxy, keepalive, OpenTelemetry tracing | |
| 28 | +| `middleware` | Server-side request lifecycle: routing, content negotiation, parameter binding, validation, security, Swagger UI / RapiDoc serving | |
| 29 | +| `middleware/denco` | Internal path-pattern router | |
| 30 | +| `middleware/header` | HTTP header parsing utilities | |
| 31 | +| `middleware/untyped` | Untyped (reflection-based) API request/response handling | |
| 32 | +| `security` | Auth scheme implementations: Basic, API Key, Bearer/OAuth2 (with `*Ctx` context-aware variants) | |
| 33 | +| `logger` | `Logger` interface with `Printf`/`Debugf`; debug enabled via `SWAGGER_DEBUG` or `DEBUG` env vars | |
| 34 | +| `flagext` | CLI flag extensions (e.g. `ByteSize`) | |
| 35 | +| `yamlpc` | YAML producer/consumer support | |
| 36 | +| `internal/testing` | Internal test utilities | |
| 37 | + |
| 38 | +### Key API |
| 39 | + |
| 40 | +Core interfaces (root package, `interfaces.go`): |
| 41 | + |
| 42 | +- `Consumer` / `ConsumerFunc` — bind request body to a Go value |
| 43 | +- `Producer` / `ProducerFunc` — serialize a Go value to the response body |
| 44 | +- `Authenticator` / `AuthenticatorFunc` — authenticate a request, return a principal |
| 45 | +- `Authorizer` / `AuthorizerFunc` — authorize a principal for a request |
| 46 | +- `OperationHandler` / `OperationHandlerFunc` — handle a matched API operation |
| 47 | +- `Validatable`, `ContextValidatable` — custom validation hooks for generated types |
| 48 | + |
| 49 | +Built-in content-type factories: `JSONConsumer()`, `JSONProducer()`, `XMLConsumer()`, `XMLProducer()`, |
| 50 | +`CSVConsumer()`, `CSVProducer()`, `TextConsumer()`, `TextProducer()`, |
| 51 | +`ByteStreamConsumer()`, `ByteStreamProducer()` |
| 52 | + |
| 53 | +Client transport (`client` package): |
| 54 | + |
| 55 | +- `Runtime` — configurable HTTP transport (TLS, auth, timeout, OpenTelemetry) |
| 56 | +- `TLSClientOptions` — mTLS / custom CA configuration |
| 57 | + |
| 58 | +Server middleware (`middleware` package): |
| 59 | + |
| 60 | +- `Context` — request lifecycle manager (routes, binds, validates, authenticates, executes) |
| 61 | +- `NewRouter()` — builds a router from an analyzed OpenAPI spec |
| 62 | +- `Spec()`, `SwaggerUI()`, `RapiDoc()` — spec and documentation serving middleware |
| 63 | + |
| 64 | +### Dependencies |
| 65 | + |
| 66 | +Key direct dependencies (`go.mod`): |
| 67 | + |
| 68 | +| Dependency | Role | |
| 69 | +|------------|------| |
| 70 | +| `go-openapi/analysis` | OpenAPI spec analysis | |
| 71 | +| `go-openapi/errors` | Structured API error types | |
| 72 | +| `go-openapi/loads` | OpenAPI spec loading | |
| 73 | +| `go-openapi/spec` | OpenAPI spec model types | |
| 74 | +| `go-openapi/strfmt` | String format registry (date-time, UUID, etc.) | |
| 75 | +| `go-openapi/swag/*` | Utilities: conv, fileutils, jsonutils, stringutils | |
| 76 | +| `go-openapi/validate` | Spec-based validation | |
| 77 | +| `go-openapi/testify/v2` | Test assertions (zero-dep fork of stretchr/testify) | |
| 78 | +| `go.opentelemetry.io/otel` | OpenTelemetry tracing | |
| 79 | +| `docker/go-units` | Human-readable size parsing | |
| 80 | + |
| 81 | +### Notable historical design decisions |
| 82 | + |
| 83 | +- **Functional adapter pattern**: every core interface has a companion `*Func` type |
| 84 | + (e.g. `ConsumerFunc`) so handlers can be plain functions or full structs. |
| 85 | +- **Consumer/Producer split**: request deserialization and response serialization are |
| 86 | + decoupled behind separate interfaces, allowing per-content-type pluggability. |
| 87 | +- **Context-aware auth variants**: security functions come in pairs (`BasicAuth` / `BasicAuthCtx`) |
| 88 | + to support both legacy and context-propagating call paths. |
| 89 | +- **Middleware pipeline**: server processing flows through |
| 90 | + Router → Binder → Validator → Security → OperationExecutor → Responder, |
| 91 | + each stage composable via `middleware.Builder`. |
| 92 | +- **OpenTracing kept in a separate module**: avoids pulling the OpenTracing dependency |
| 93 | + into consumers that only need the core runtime or use OpenTelemetry directly. |
0 commit comments