๐Ÿ“– 2 min read (~ 400 words).

Core

The root github.com/go-openapi/runtime package defines a small set of interfaces shared by every other piece of the runtime.

Everything else โ€” client transport, server middleware pipeline โ€” is built on top of these.

Concepts

  • Producer and Consumer are the codecs that map data structures to and from JSON, YAML, XML, byte streams, etc.
  • “Parameters bindings” is the machinery to serialize / deserialize OpenAPI request parameters as go types
  • “Content negotiation” refers to the handling of the Content-Type header to agree on a serialization and encoding format.
  • “Operation” is the OpenAPI term for “handler”, i.e. a unitary service invoked by a request

Module map

runtime ships as three Go modules, each with its own go.mod and dependencies.

ModulePurpose
github.com/go-openapi/runtimeCore interfaces, content-type codecs, client transport, full server middleware pipeline. Pulls in analysis, loads, spec, strfmt, validate.
github.com/go-openapi/runtime/server-middlewareStandalone, dependency-free server middleware: media types, content negotiation, doc UIs. Usable from any plain net/http server.
github.com/go-openapi/runtime/client-middleware/opentracingOptional OpenTracing transport middleware (compatibility add-on โ€” new code should use the OpenTelemetry support built into client.Runtime).

server-middleware lets you reuse the negotiation and doc-UI primitives without inheriting the OpenAPI spec/loads/validate dependency tree.

Where the pieces fit

flowchart TD
    cli["Application client code<br/>(models, โ€ฆ)"]
    app["Application server code<br/>(handlers, models, โ€ฆ)"]
    client[["client<br/>(transport)"]]
    mw[["middleware<br/>(pipeline)"]]
    sm[["server-middleware<br/>(standalone โ€” stdlib only)"]]
    core{{"runtime<br/>core interfaces<br/>Consumer ยท Producer<br/>Authenticator ยท Authorizer<br/>OperationHandler ยท Validatable"}}

    cli -- import --> client
    app -- import --> mw
    app --> sm
    client --> core
    mw --> core
    mw -.-> sm

middleware reuses the server-middleware primitives (the dotted arrow): negotiation, media-type matching and the doc-UI handlers all live in server-middleware.

Backward-compatibility note

The legacy entry points pre-existing in package middleware before v0.30.0 (NegotiateContentType, SwaggerUI, โ€ฆ) are still available as a shim (middleware/seam.go) that now forwards to the new module โ€” see server / deprecated shims.

Read on for what each interface does, the built-in content-type codecs and the validation hooks.

  • The five core interfaces โ€” Consumer, Producer, Authenticator, Authorizer, OperationHandler โ€” and where each one fires on the client and server sides.
  • Built-in Consumer / Producer factories (JSON, XML, CSV, text, bytestream, YAML) and how to register your own.
  • Validatable and ContextValidatable interfaces, when the runtime invokes them, and how they interact with spec-based validation.