Skip to content

Commit e5de454

Browse files
authored
oxide: optionally build from local openapi spec. (#311)
For local testing, we may want to generate the sdk from a local spec file, rather than pulling from github. This patch adds an environment variable override to optionally source the spec from a local file instead.
1 parent 3145079 commit e5de454

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

internal/generate/main.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,24 @@ func main() {
2424
}
2525

2626
func generateSDK() error {
27-
versionFile := "../VERSION_OMICRON"
28-
spec, err := loadAPIFromFile(versionFile)
29-
if err != nil {
30-
return err
27+
// By default, load the Omicron OpenAPI spec from upstream using a version
28+
// hash specified in `../VERSION_OMICRON`. For local testing, optionally
29+
// specify a path to an OpenAPI spec file in the `OPENAPI_SPEC_PATH`
30+
// environment variable, and use its contents instead.
31+
var spec *openapi3.T
32+
var err error
33+
specFileOverride := os.Getenv("OPENAPI_SPEC_PATH")
34+
if specFileOverride != "" {
35+
spec, err = openapi3.NewLoader().LoadFromFile(specFileOverride)
36+
if err != nil {
37+
return err
38+
}
39+
} else {
40+
versionFile := "../VERSION_OMICRON"
41+
spec, err = loadAPIFromFile(versionFile)
42+
if err != nil {
43+
return err
44+
}
3145
}
3246

3347
typesFile := "../../oxide/types.go"

oxide/types.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)