Files
coder/scripts/apidocgen/swaginit/main.go
T
Marcin Tojek 456c0bced9 fix: enable strict mode for swagger generation & upgrade swag (#21975)
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).
2026-02-06 13:04:35 +01:00

38 lines
1023 B
Go

// Package main wraps swag init with Strict mode enabled.
//
// The upstream swag CLI (v1.16.2) does not expose a --strict
// flag, so warnings about duplicate routes are silently
// ignored. This wrapper calls the Go API directly with
// Strict: true, turning those warnings into hard errors.
package main
import (
"log"
"os"
"github.com/swaggo/swag/gen"
)
func main() {
logger := log.New(os.Stdout, "", log.LstdFlags)
err := gen.New().Build(&gen.Config{
SearchDir: "./coderd,./codersdk,./enterprise/coderd,./enterprise/wsproxy/wsproxysdk",
MainAPIFile: "coderd.go",
OutputDir: "./coderd/apidoc",
OutputTypes: []string{"go", "json"},
ParseDependency: 1,
Strict: true,
OverridesFile: gen.DefaultOverridesFile,
ParseGoList: true,
ParseDepth: 100,
CollectionFormat: "csv",
Debugger: logger,
LeftTemplateDelim: "{{",
RightTemplateDelim: "}}",
})
if err != nil {
log.Fatalf("swag init failed: %v", err)
}
}