Skip to content

Commit 0d73e8c

Browse files
authored
doc: added READMEs per module, updated agentic instructions (#439)
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent c234c6a commit 0d73e8c

4 files changed

Lines changed: 152 additions & 8 deletions

File tree

.claude/CLAUDE.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ See [docs/MAINTAINERS.md](../docs/MAINTAINERS.md) for CI/CD, release process, an
1212

1313
### Modules and Package layout
1414

15-
This is a mono-repo with a `go.work` workspace containing two modules:
15+
This is a mono-repo with a `go.work` workspace containing three modules:
1616

1717
| Module | Purpose |
1818
|--------|---------|
1919
| `.` (root) | Core runtime library |
20-
| `client-middleware/opentracing` | Optional OpenTracing middleware for client transport |
20+
| `server-middleware` | Standalone, dependency-free server middleware: `mediatype`, `negotiate`, `negotiate/header`, `docui`. No transitive dependency on `go-openapi/spec`, `loads`, or `validate`. |
21+
| `client-middleware/opentracing` | Optional OpenTracing middleware for client transport (compatibility module; new code should use the OpenTelemetry support built into `client.Runtime`). |
2122

2223
Packages in the root module:
2324

2425
| Package | Contents |
2526
|---------|----------|
2627
| `runtime` (root) | Core interfaces (`Consumer`, `Producer`, `Authenticator`, `Authorizer`, `OperationHandler`), content-type handlers (JSON, XML, CSV, text, bytestream), HTTP request/response helpers |
2728
| `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` | Server-side request lifecycle: routing, parameter binding, validation, security, operation execution. Doc-UI and negotiation primitives have moved to `server-middleware/*`; the legacy entry points (`Spec`, `SwaggerUI`, `RapiDoc`, `Redoc`, `NegotiateContentType`, …) remain as deprecated shims in `seam.go`. |
2930
| `middleware/denco` | Internal path-pattern router |
30-
| `middleware/header` | HTTP header parsing utilities |
31+
| `middleware/header` | Deprecated shim — re-exports `server-middleware/negotiate/header` |
3132
| `middleware/untyped` | Untyped (reflection-based) API request/response handling |
3233
| `security` | Auth scheme implementations: Basic, API Key, Bearer/OAuth2 (with `*Ctx` context-aware variants) |
3334
| `logger` | `Logger` interface with `Printf`/`Debugf`; debug enabled via `SWAGGER_DEBUG` or `DEBUG` env vars |
@@ -59,7 +60,12 @@ Server middleware (`middleware` package):
5960

6061
- `Context` — request lifecycle manager (routes, binds, validates, authenticates, executes)
6162
- `NewRouter()` — builds a router from an analyzed OpenAPI spec
62-
- `Spec()`, `SwaggerUI()`, `RapiDoc()` — spec and documentation serving middleware
63+
64+
Standalone server middleware (`server-middleware` module):
65+
66+
- `mediatype.MediaType`, `mediatype.Set` — typed RFC 7231 media-type values + asymmetric matching
67+
- `negotiate.ContentType()`, `negotiate.ContentEncoding()``Accept` / `Accept-Encoding` selection (honours MIME parameters by default; opt out with `WithIgnoreParameters`)
68+
- `docui.SwaggerUI()`, `docui.RapiDoc()`, `docui.Redoc()`, `docui.ServeSpec()` — stdlib-only doc-UI and spec-serving handlers
6369

6470
### Dependencies
6571

@@ -91,3 +97,7 @@ Key direct dependencies (`go.mod`):
9197
each stage composable via `middleware.Builder`.
9298
- **OpenTracing kept in a separate module**: avoids pulling the OpenTracing dependency
9399
into consumers that only need the core runtime or use OpenTelemetry directly.
100+
- **`server-middleware` extracted as a separate module**: lets any `net/http` application
101+
reuse the negotiation, media-type, and doc-UI primitives without inheriting the OpenAPI
102+
spec/loads/validate dependency tree. The root `middleware` package keeps deprecated
103+
shims for source compatibility.

.github/copilot-instructions.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ This is a mono-repo with a `go.work` workspace:
1313
| Module | Purpose |
1414
|--------|---------|
1515
| `.` (root) | Core runtime library |
16-
| `client-middleware/opentracing` | Optional OpenTracing middleware for client transport |
16+
| `server-middleware` | Standalone, dependency-free server middleware (`mediatype`, `negotiate`, `negotiate/header`, `docui`) |
17+
| `client-middleware/opentracing` | OpenTracing middleware for client transport (compatibility module; prefer the OpenTelemetry support built into `client.Runtime`) |
1718

1819
## Package Layout
1920

2021
| Package | Contents |
2122
|---------|----------|
2223
| `runtime` (root) | Core interfaces (`Consumer`, `Producer`, `Authenticator`, `Authorizer`, `OperationHandler`), content-type handlers (JSON, XML, CSV, text, bytestream), HTTP helpers |
2324
| `client` | HTTP client transport (`Runtime`) with TLS, timeouts, proxy, keepalive, OpenTelemetry |
24-
| `middleware` | Server request lifecycle: routing, content negotiation, parameter binding, validation, security, Swagger UI / RapiDoc |
25+
| `middleware` | Server request lifecycle: routing, parameter binding, validation, security, operation execution. Doc-UI and negotiation primitives moved to `server-middleware/*`; legacy entry points remain as deprecated shims in `seam.go`. |
2526
| `middleware/denco` | Internal path-pattern router |
26-
| `middleware/header` | HTTP header parsing utilities |
27+
| `middleware/header` | Deprecated shim — re-exports `server-middleware/negotiate/header` |
2728
| `middleware/untyped` | Untyped (reflection-based) API handling |
2829
| `security` | Auth implementations: Basic, API Key, Bearer/OAuth2 (with `*Ctx` variants) |
2930
| `logger` | `Logger` interface; debug via `SWAGGER_DEBUG` or `DEBUG` env vars |
@@ -47,6 +48,7 @@ This is a mono-repo with a `go.work` workspace:
4748
- Security functions come in pairs (`BasicAuth` / `BasicAuthCtx`) for context propagation.
4849
- Server middleware pipeline: Router → Binder → Validator → Security → Executor → Responder.
4950
- OpenTracing lives in a separate module to avoid pulling its dependency into the core.
51+
- `server-middleware` is a separate module so any `net/http` app can use negotiation, media-type, and doc-UI primitives without inheriting the OpenAPI spec/loads/validate tree.
5052

5153
## Dependencies
5254

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# client-middleware/opentracing
2+
3+
[![GoDoc][godoc-badge]][godoc-url]
4+
5+
OpenTracing instrumentation for the `go-openapi/runtime` client transport.
6+
7+
> **Compatibility module.** This module exists solely to support users who
8+
> still depend on the legacy [OpenTracing API][opentracing-url] and have not
9+
> yet migrated to OpenTelemetry. New code should use the **OpenTelemetry
10+
> tracing built into [`client.Runtime`](../../client)** directly — it
11+
> requires no extra wrapper.
12+
>
13+
> The OpenTracing project has been archived since 2022 in favour of
14+
> OpenTelemetry. We expect to keep this module compiling and passing tests,
15+
> but it will not gain new features.
16+
17+
It is published as a **separate Go module** so that the
18+
`opentracing-go` dependency stays out of the main runtime's import graph —
19+
projects on OpenTelemetry pay no cost for it.
20+
21+
## Install
22+
23+
```sh
24+
go get github.com/go-openapi/runtime/client-middleware/opentracing
25+
```
26+
27+
## Usage
28+
29+
`WithOpenTracing` wraps a `client.Runtime` and starts a child span for each
30+
outgoing operation, provided the operation's `context.Context` already
31+
carries a parent span. If no parent span is found in the context, the call
32+
is forwarded unchanged.
33+
34+
```go
35+
import (
36+
"github.com/go-openapi/runtime/client"
37+
otmw "github.com/go-openapi/runtime/client-middleware/opentracing"
38+
)
39+
40+
rt := client.New("api.example.com", "/v1", []string{"https"})
41+
transport := otmw.WithOpenTracing(rt)
42+
43+
// pass `transport` (a runtime.ClientTransport) to your generated client
44+
```
45+
46+
Per-request tags can be added through the variadic `opentracing.StartSpanOption`
47+
arguments:
48+
49+
```go
50+
transport := otmw.WithOpenTracing(rt, opentracing.Tag{Key: "service", Value: "billing"})
51+
```
52+
53+
## Migrating to OpenTelemetry
54+
55+
The main `client.Runtime` already emits OpenTelemetry spans; no wrapper is
56+
needed. Users coming from this module typically:
57+
58+
1. Replace the `opentracing-go` `Tracer` setup with an OpenTelemetry
59+
`TracerProvider`.
60+
2. Drop the `WithOpenTracing` wrapper — instrument the `client.Runtime` directly.
61+
3. Remove the import of this module.
62+
63+
See the [main runtime README](../../README.md) for the OpenTelemetry
64+
configuration entry points.
65+
66+
## License
67+
68+
[Apache-2.0](../../LICENSE).
69+
70+
[godoc-badge]: https://pkg.go.dev/badge/github.com/go-openapi/runtime/client-middleware/opentracing
71+
[godoc-url]: https://pkg.go.dev/github.com/go-openapi/runtime/client-middleware/opentracing
72+
[opentracing-url]: https://github.com/opentracing/opentracing-go

server-middleware/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# server-middleware
2+
3+
[![GoDoc][godoc-badge]][godoc-url]
4+
5+
Standalone, dependency-free server-side middleware utilities for OpenAPI applications.
6+
7+
This module is part of the [`go-openapi/runtime`][runtime-url] toolkit, but is
8+
maintained as a **separate Go module** so it can be used by any `net/http`
9+
application — including ones that have no OpenAPI spec at all. It carries no
10+
transitive dependency on `go-openapi/spec`, `go-openapi/loads`, or
11+
`go-openapi/validate`; only the standard library and (for tests)
12+
`go-openapi/testify/v2`.
13+
14+
## Packages
15+
16+
| Package | Purpose |
17+
|---------|---------|
18+
| [`mediatype`](./mediatype) | Typed RFC 7231 / RFC 2045 media-type values (`MediaType`, `Set`) and asymmetric matching used by both server-side validation and `Accept`-header negotiation. |
19+
| [`negotiate`](./negotiate) | Server-side HTTP content negotiation: select the response `Content-Type` from `Accept`, and the response `Content-Encoding` from `Accept-Encoding`. Honours MIME parameters by default; opt out with `WithIgnoreParameters`. |
20+
| [`negotiate/header`](./negotiate/header) | Low-level RFC-7231 header parsing primitives reused by `negotiate`. Exported for callers that need raw `Accept`/`Accept-Encoding` parsing without the typed media-type layer. |
21+
| [`docui`](./docui) | Stdlib-only HTTP middlewares that serve OpenAPI documentation UIs (Swagger UI, ReDoc, RapiDoc) and the spec document itself. Mountable on any `net/http` mux. |
22+
23+
## Install
24+
25+
```sh
26+
go get github.com/go-openapi/runtime/server-middleware
27+
```
28+
29+
## Quick start — content negotiation
30+
31+
```go
32+
import "github.com/go-openapi/runtime/server-middleware/negotiate"
33+
34+
offers := []string{"application/json", "application/xml"}
35+
chosen := negotiate.ContentType(r.Header, offers, "application/json")
36+
w.Header().Set("Content-Type", chosen)
37+
```
38+
39+
## Quick start — serving Swagger UI
40+
41+
```go
42+
import "github.com/go-openapi/runtime/server-middleware/docui"
43+
44+
handler := docui.SwaggerUI(docui.WithSpecURL("/swagger.json"), docui.WithBasePath("/docs"))
45+
http.Handle("/docs/", handler)
46+
```
47+
48+
## Further reading
49+
50+
- [`docs/MEDIA_TYPES.md`](../docs/MEDIA_TYPES.md) — the full server-side
51+
selection algorithm and its asymmetric matching rules.
52+
- Full API reference on [pkg.go.dev][godoc-url].
53+
54+
## License
55+
56+
[Apache-2.0](../LICENSE).
57+
58+
[runtime-url]: https://github.com/go-openapi/runtime
59+
[godoc-badge]: https://pkg.go.dev/badge/github.com/go-openapi/runtime/server-middleware
60+
[godoc-url]: https://pkg.go.dev/github.com/go-openapi/runtime/server-middleware

0 commit comments

Comments
 (0)