-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openapi3: move ref codegen to Go (#956)
* Move ref code gen from bash to go Keeps things in the go ecosystem and it will make a change I'll like to do far easier with go available. No changes to the generated refs.go other than a warning that it's generated to devs and IDEs. * Re-run ./docs.sh
- Loading branch information
1 parent
45b4399
commit 518b18d
Showing
6 changed files
with
74 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//go:build ignore | ||
// +build ignore | ||
|
||
// The program generates refs.go, invoke `go generate ./...` to run. | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"os" | ||
"text/template" | ||
) | ||
|
||
//go:embed refs.tmpl | ||
var tmplData string | ||
|
||
func main() { | ||
file, err := os.Create("refs.go") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer func() { | ||
if err := file.Close(); err != nil { | ||
panic(err) | ||
} | ||
}() | ||
|
||
packageTemplate := template.Must(template.New("openapi3-refs").Parse(tmplData)) | ||
|
||
if err := packageTemplate.Execute(file, struct { | ||
Package string | ||
Types []string | ||
}{ | ||
Package: os.Getenv("GOPACKAGE"), // set by the go:generate directive | ||
Types: []string{ | ||
"Callback", | ||
"Example", | ||
"Header", | ||
"Link", | ||
"Parameter", | ||
"RequestBody", | ||
"Response", | ||
"Schema", | ||
"SecurityScheme", | ||
}, | ||
}); err != nil { | ||
panic(err) | ||
} | ||
} |