Skip to content

Conversation

peteski22
Copy link
Contributor

@peteski22 peteski22 commented Oct 14, 2025

Summary

Adds programmatic OpenAPI YAML export to maintain 1:1 mapping between API code and hosted documentation.

Changes

  • Extracts route registration into internal/api/RegisterRoutes() as single source of truth
  • Adds tools/docsgen/api/ tool that generates OpenAPI spec without running daemon
  • Integrates into CI via make docs-api in deploy-docs workflow
  • Introduces api.APIVersion constant (v1) to prevent version mismatches between daemon and docs

Benefits

  • OpenAPI spec auto-generated on every release from actual API code
  • No manual maintenance of API documentation
  • Eliminates risk of stale/inaccurate docs
  • Spec available at /openapi.yaml during runtime AND in static docs (https://.../mcpd/api/openapi.yaml)

Side improvements

  • Reorganizes docsgen tools into separate directories (fixes package conflicts)
  • Adds build tags to golangci-lint configuration
  • Updates GitHub Actions to latest versions

Local testing

make docs

The check out the docs 😄

@peteski22 peteski22 requested a review from agpituk October 14, 2025 21:21
@agpituk
Copy link
Member

agpituk commented Oct 15, 2025

I've been testing it out locally. So far I found a couple of things:

warnings in the logs:
WARNING - A reference to 'api/openapi.yaml' is included in the 'nav' configuration, which is not found in the documentation files.

also this link: http://localhost:8000/mcpd/api/openapi.yaml

returns a 404 - not found

WARNING - [21:42:48] "GET /mcpd/api/openapi.yaml HTTP/1.1" code 404

Extract route registration logic into internal/api/routes.go with
RegisterRoutes function. This ensures daemon and docs generation
use identical route definitions, maintaining 1:1 mapping between
code and documentation.

Introduces api.APIVersion constant as single source of truth for
API version used in OpenAPI spec and URL paths. The RegisterRoutes
function extracts this version from the router's OpenAPI spec and
returns the path prefix for logging.

All parameters require non-nil values with defensive checks using
reflection to prevent panics from interface nil checks.

Updates internal/daemon/api_server.go to use RegisterRoutes and
api.APIVersion constant, removing duplicate route registration code.
Introduce tools/docsgen/api/openapi.go for programmatic OpenAPI spec
export. The tool uses api.RegisterRoutes with stub implementations of
contracts to generate the spec without running the daemon.

Output is written to docs/api/openapi.yaml which is excluded from
version control via .gitignore, matching the pattern used for CLI
docs in docs/commands/.

This ensures a 1:1 mapping between the actual API code and the
published OpenAPI specification, automatically generated during
documentation deployment.
Add error handling for encoder.Close() call in updateMkDocsNav
function to satisfy errcheck linter.

The encoder must be properly closed to flush any buffered output
before writing the final YAML to the file.
Update Makefile targets to reflect new tools structure where each
standalone tool lives in its own directory (cmds/, nav/, api/)
rather than sharing tools/docsgen/cli/.

Add docs-api target to generate OpenAPI specification.

Configure golangci-lint to include build tags for all docsgen tools
and validate_registry, ensuring proper linting of build-tagged files
that were previously excluded from analysis.
Add OpenAPI spec generation step to deploy-docs workflow between
CLI docs generation and navigation updates. This ensures the spec
is generated fresh on every docs deployment.

Update mkdocs.yaml to include API Reference section with link to
the generated OpenAPI specification file.

Update GitHub Actions versions across all workflows to latest
pinned releases for actions/checkout, actions/setup-go, and
astral-sh/setup-uv.
* make docs includes building OpenAPI too
@peteski22 peteski22 force-pushed the peteski22/api/openapi-docs-generation branch from c6cdf96 to 651c157 Compare October 16, 2025 07:24
@peteski22
Copy link
Contributor Author

I've been testing it out locally. So far I found a couple of things:

warnings in the logs: WARNING - A reference to 'api/openapi.yaml' is included in the 'nav' configuration, which is not found in the documentation files.

also this link: http://localhost:8000/mcpd/api/openapi.yaml

returns a 404 - not found

WARNING - [21:42:48] "GET /mcpd/api/openapi.yaml HTTP/1.1" code 404

🤦🏼 whoops, I forgot to include the docs-api for the docs target in the Makefile when I updated something earlier, should be fixed now. Thanks for catching.

Copy link
Member

@agpituk agpituk left a comment

Choose a reason for hiding this comment

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

LGTM! :) 🚀

@peteski22 peteski22 merged commit cad312d into main Oct 16, 2025
3 checks passed
@peteski22 peteski22 deleted the peteski22/api/openapi-docs-generation branch October 16, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants