Skip to content

Commit dc6d271

Browse files
authored
feat: Build framework for generating API docs (#5383)
* WIP * Gen * WIP * chi swagger * WIP * WIP * WIP * GetWorkspaces * GetWorkspaces * Markdown * Use widdershins * WIP * WIP * WIP * Markdown template * Fix: makefile * fmt * Fix: comment * Enable swagger conditionally * fix: site * Default false * Flag tests * fix * fix * template fixes * Fix * Fix * Fix * WIP * Formatted * Cleanup * Templates * BEGIN END SECTION * subshell exit code * Fix * Fix merge * WIP * Fix * Fix fmt * Fix * Generic api.md page * Fix merge * Link pages * Fix * Fix * Fix: links * Add icon * Write manifest file * Fix fmt * Fix: enterprise * Fix: Swagger.Enable * Fix: rename apidocs to apidoc * Fix: find -not -prune * Fix: json not available * Fix: rename Coderd API to Coder API * Fix: npm exec * Fix: api dir * Fix: by ID * Fix: string uuid * Fix: include deleted * Fix: indirect go.mod * Fix: source lib.sh * Fix: shellcheck * Fix: pushd popd * Fix: fmt * Fix: improve workspaces * Fix: swagger-enable * Fix * Fix: mention only HTTP 200 * Fix: IDs * Fix: https * Fix: icon * More APis * Fix: format swagger.json * Fix: SwaggerEndpoint * Fix: SCRIPT_DIR * Fix: PROJECT_ROOT * Fix: use code tags in schemas.md * Fix: examples * Fix: examples * Fix: improve format * Fix: date-time,enums * Fix: include_deleted * Fix: array of * Fix: parameter, response * Fix: string time or null * Workspaces: more docs * Workspaces: more docs * Fix: renderDisplayName * Fix: ActiveUserCount * Fix * Fix: typo * Templates: docs * Notice: incomplete
1 parent f239ca7 commit dc6d271

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+9272
-76
lines changed

Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,14 @@ gen: \
410410
provisionersdk/proto/provisioner.pb.go \
411411
provisionerd/proto/provisionerd.pb.go \
412412
site/src/api/typesGenerated.ts \
413-
docs/admin/prometheus.md
413+
docs/admin/prometheus.md \
414+
coderd/apidoc/swagger.json
414415
.PHONY: gen
415416

416417
# Mark all generated files as fresh so make thinks they're up-to-date. This is
417418
# used during releases so we don't run generation scripts.
418419
gen/mark-fresh:
419-
files="coderd/database/dump.sql coderd/database/querier.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts docs/admin/prometheus.md"
420+
files="coderd/database/dump.sql coderd/database/querier.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts docs/admin/prometheus.md coderd/apidoc/swagger.json"
420421
for file in $$files; do
421422
echo "$$file"
422423
if [ ! -f "$$file" ]; then
@@ -464,6 +465,11 @@ docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/me
464465
cd site
465466
yarn run format:write ../docs/admin/prometheus.md
466467

468+
coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen -not \( -path './scripts/apidocgen/node_modules' -prune \) -type f) $(wildcard coderd/*.go) $(wildcard codersdk/*.go)
469+
./scripts/apidocgen/generate.sh
470+
cd site
471+
yarn run format:write ../docs/api ../docs/manifest.json ../coderd/apidoc/swagger.json
472+
467473
update-golden-files: cli/testdata/.gen-golden
468474
.PHONY: update-golden-files
469475

cli/deployment/config.go

+8
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ func newConfig() *codersdk.DeploymentConfig {
452452
Flag: "max-token-lifetime",
453453
Default: 24 * 30 * time.Hour,
454454
},
455+
Swagger: &codersdk.SwaggerConfig{
456+
Enable: &codersdk.DeploymentConfigField[bool]{
457+
Name: "Enable swagger endpoint",
458+
Usage: "Expose the swagger endpoint via /swagger.",
459+
Flag: "swagger-enable",
460+
Default: false,
461+
},
462+
},
455463
}
456464
}
457465

cli/server.go

+4
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,10 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
678678
), cfg.Prometheus.Address.Value, "prometheus")()
679679
}
680680

681+
if cfg.Swagger.Enable.Value {
682+
options.SwaggerEndpoint = cfg.Swagger.Enable.Value
683+
}
684+
681685
// We use a separate coderAPICloser so the Enterprise API
682686
// can have it's own close functions. This is cleaner
683687
// than abstracting the Coder API itself.

cli/testdata/coder_server_--help.golden

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ Flags:
169169
"ecdsa", or "rsa4096".
170170
Consumes $CODER_SSH_KEYGEN_ALGORITHM
171171
(default "ed25519")
172+
--swagger-enable Expose the swagger endpoint via /swagger.
173+
Consumes $CODER_SWAGGER_ENABLE
172174
--telemetry Whether telemetry is enabled or not.
173175
Coder collects anonymized usage data to
174176
help improve our product.

0 commit comments

Comments
 (0)