Skip to content

feat: add OpenAPI specification#159

Merged
traefiker merged 6 commits into
traefik:masterfrom
sheddy-traefik:add-openapi-spec
Jul 1, 2026
Merged

feat: add OpenAPI specification#159
traefiker merged 6 commits into
traefik:masterfrom
sheddy-traefik:add-openapi-spec

Conversation

@sheddy-traefik

@sheddy-traefik sheddy-traefik commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What

Adds an openapi.yaml (OpenAPI 3.0.3) at the repository root describing whoami's HTTP API, and serves it at GET /openapi.yaml.

Why

whoami is widely used as a demo backend (including throughout the Traefik Hub and Traefik Proxy docs), but it ships no machine-readable API description. A spec makes it usable as a ready-made example for API gateways, portals, mock servers, and client generators without everyone hand-rolling their own.

Serving it directly from whoami means consumers get the spec from the same endpoint they are already routing to, with no additional infrastructure needed.

Details

The spec is hand-written against app.go and covers the HTTP handlers:

  • GET / — request info as plain text (wait, env query params)
  • GET /api — request info as JSON (the Data struct, incl. remoteAddr and environ)
  • GET /bench — returns 1
  • GET /data — sized payload (size, unit, attachment)
  • GET /health / POST /health — read and set the health status code
  • GET /openapi.yaml — serves this spec (embedded at build time via //go:embed)

The /echo WebSocket endpoint and the /whoami.Whoami/ gRPC service are intentionally omitted, since neither is expressible in OpenAPI; this is noted in the spec's info.description.

@immanuelfodor

immanuelfodor commented Jun 29, 2026

Copy link
Copy Markdown

Very nice addition! 🙌

However, I wonder if the whoami app could expose the openapi.yaml on a path, eg. GET /openapi.yaml, eliminating the need for using a separate application for exposing it over a URL.

@sheddy-traefik

Copy link
Copy Markdown
Contributor Author

@immanuelfodor Love this idea. Since the spec already lives at the repo root, it could be embedded at build time with //go:embed and served directly. Then it can be registered alongside the other routes in main().

@sheddy-traefik

Copy link
Copy Markdown
Contributor Author

i've implemented this in the PR: 99bb044

@sheddy-traefik sheddy-traefik changed the title docs: add OpenAPI specification add OpenAPI specification Jun 29, 2026
@sheddy-traefik sheddy-traefik changed the title add OpenAPI specification feat: add OpenAPI specification Jun 29, 2026

@immanuelfodor immanuelfodor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🥳

@immanuelfodor

Copy link
Copy Markdown

FYI, CI is failing

@sheddy-traefik

Copy link
Copy Markdown
Contributor Author

FYI, CI is failing

Yeah @immanuelfodor the issue is with golanglint, the version it uses doesn't support Go v1.26 and its pinned.

Comment thread openapi.yaml Outdated
@jspdown jspdown added status/2-needs-review kind/enhancement a new or improved feature. labels Jul 1, 2026
sheddy-traefik and others added 3 commits July 1, 2026 09:16
golangci-lint v2.1.2 is built with go1.24 and panics parsing the
go1.26 stdlib that the 'stable' toolchain now installs. Bump to
v2.12.2 (built with go1.26) and disable the newly-added linters
(iotamixing, noinlineerr, wsl_v5) to keep the existing style rules.
The pinned master install.sh currently resolves the wrong release
asset (downloads the .sbom.json instead of the tarball), so its
checksum verification fails deterministically. Install through the
Go module proxy instead, which is not subject to GitHub asset
resolution or rate limiting.
Comment thread .github/workflows/ci.yml Outdated
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}

@ldez ldez Jul 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}

Or

      - uses: golangci/golangci-lint-action@v9
        with:
          version: ${{ env.GOLANGCI_LINT_VERSION }}
          install-only: 'true'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better with the GH action. Thanks @ldez

@traefiker traefiker merged commit 8951300 into traefik:master Jul 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement a new or improved feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants