photoprism/scripts/tools/swaggerfix/main.go
Michael Mayer a2b7615c93 Go: Apply go fix modernizations across backend packages
Run `go fix ./...` and keep mechanical modernization updates.

- Replace `interface{}` with `any` in signatures and local types
- Apply formatter/style cleanups from go1.26 tooling
- Keep `omitempty` behavior-preserving simplifications suggested by fix
- No functional feature changes intended

Validation:
- go test ./... -run '^$' -count=1 (Go 1.26.0)
- GOTOOLCHAIN=go1.24.10 go test ./... -run '^$' -count=1

Signed-off-by: Michael Mayer <michael@photoprism.app>
2026-02-20 03:54:33 +01:00

51 lines
1.2 KiB
Go

package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "usage: swaggerfix <swagger.json>")
os.Exit(2)
}
path := os.Args[1]
b, err := ioutil.ReadFile(path)
if err != nil {
fmt.Fprintln(os.Stderr, "read:", err)
os.Exit(1)
}
var doc map[string]any
if err := json.Unmarshal(b, &doc); err != nil {
fmt.Fprintln(os.Stderr, "parse:", err)
os.Exit(1)
}
// Traverse to definitions.time.Duration
defs, _ := doc["definitions"].(map[string]any)
if defs == nil {
fmt.Fprintln(os.Stderr, "no definitions in swagger file")
os.Exit(1)
}
td, _ := defs["time.Duration"].(map[string]any)
if td == nil {
fmt.Fprintln(os.Stderr, "no time.Duration schema found; nothing to do")
os.Exit(0)
}
// Remove unstable enums and varnames to ensure deterministic output.
delete(td, "enum")
delete(td, "x-enum-varnames")
defs["time.Duration"] = td
doc["definitions"] = defs
out, err := json.MarshalIndent(doc, "", " ")
if err != nil {
fmt.Fprintln(os.Stderr, "marshal:", err)
os.Exit(1)
}
if err := ioutil.WriteFile(path, out, 0644); err != nil {
fmt.Fprintln(os.Stderr, "write:", err)
os.Exit(1)
}
}