mirror of
https://github.com/coder/coder.git
synced 2026-06-04 05:28:20 +00:00
456c0bced9
Adds a Go wrapper (`scripts/apidocgen/swaginit/main.go`) that calls swag's Go API with `Strict: true`. The `--strict` flag isn't available in swag's CLI in any version, so the wrapper is the only way to enable it. Also upgrades swag from v1.16.2 to v1.16.6 (better generics support, precise numeric formats, `x-enum-descriptions`, CVE-2024-45338 fix).
42 lines
1.1 KiB
Bash
Executable File
42 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# This script generates swagger description file and required Go docs files
|
|
# from the coderd API.
|
|
|
|
set -euo pipefail
|
|
# shellcheck source=scripts/lib.sh
|
|
source "$(dirname "$(dirname "${BASH_SOURCE[0]}")")/lib.sh"
|
|
|
|
APIDOCGEN_DIR=$(dirname "${BASH_SOURCE[0]}")
|
|
API_MD_TMP_FILE=$(mktemp /tmp/coder-apidocgen.XXXXXX)
|
|
|
|
cleanup() {
|
|
rm -f "${API_MD_TMP_FILE}"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
log "Use temporary file: ${API_MD_TMP_FILE}"
|
|
|
|
pushd "${PROJECT_ROOT}"
|
|
# Use our custom wrapper instead of "go tool swag init" to enable
|
|
# Strict mode, which turns duplicate-route warnings into hard errors.
|
|
# The upstream swag CLI does not expose a --strict flag.
|
|
go run "${APIDOCGEN_DIR}/swaginit/main.go"
|
|
popd
|
|
|
|
pushd "${APIDOCGEN_DIR}"
|
|
|
|
# Make sure that widdershins is installed correctly.
|
|
pnpm exec -- widdershins --version
|
|
# Render the Markdown file.
|
|
pnpm exec -- widdershins \
|
|
--user_templates "./markdown-template" \
|
|
--search false \
|
|
--omitHeader true \
|
|
--language_tabs "shell:curl" \
|
|
--summary "../../coderd/apidoc/swagger.json" \
|
|
--outfile "${API_MD_TMP_FILE}"
|
|
# Perform the postprocessing
|
|
go run postprocess/main.go -in-md-file-single "${API_MD_TMP_FILE}"
|
|
popd
|