-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Introduced here: #155 (comment)
Problem
The schema generator in hack/jsonschemagen/main.go
uses filepath.Join("..", "..", "specs")
to build the output path for schema files. This approach only works when the binary is executed from the hack/jsonschemagen
directory. When run from the repository root (as done by make update-codegen
and CI workflows with go run ./hack/jsonschemagen
), this resolves to an incorrect path (../../specs
from repo root) and causes the write operation to fail.
Impact
- Schema generation fails when invoked from the repo root
- CI workflows and make targets cannot successfully generate schemas
- Inconsistent behavior depending on the current working directory
Proposed Solution
Use runtime.Caller
to determine the source file's location, then derive the repository root from there before appending specs
. This makes the path resolution independent of the current working directory:
_, callerFile, _, ok := runtime.Caller(0)
if !ok {
log.Fatal("failed to determine generator location")
}
repoRoot := filepath.Join(filepath.Dir(callerFile), "..", "..")
specsDir := filepath.Join(repoRoot, "specs")
Metadata
Metadata
Assignees
Labels
No labels