Skip to content

Commit

Permalink
Add support for Gorilla generation (deepmap#585)
Browse files Browse the repository at this point in the history
* Add support for Gorilla generation

As part of deepmap#465, it'd be handy to have gorilla/mux, a commonly used HTTP
server as a generated server.

This is very similar to Chi, as it is also `net/http` compliant, and
allows us to mostly copy-paste the code, with very minor tweaks for
Gorilla-specific routing needs.

* Add example project for Gorilla

As part of deepmap#465, we should produce an example version of the Petstore
API using Gorilla, to validate that this works, as well as showing
sample usage to consumers.
  • Loading branch information
Jamie Tanna committed May 26, 2022
1 parent 415a22f commit fcdb08f
Show file tree
Hide file tree
Showing 17 changed files with 1,157 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -255,6 +255,9 @@ func SetupHandler() {
http.Handle("/", Handler(&myApi))
}
```

Alternatively, [Gorilla](https://github.com/gorilla/mux) is also 100% compatible with `net/http` and can be generated with `-generate gorilla`.

</summary></details>

#### Additional Properties in type definitions
Expand Down
4 changes: 3 additions & 1 deletion cmd/oapi-codegen/oapi-codegen.go
Expand Up @@ -86,7 +86,7 @@ func main() {
// All flags below are deprecated, and will be removed in a future release. Please do not
// update their behavior.
flag.StringVar(&flagGenerate, "generate", "types,client,server,spec",
`Comma-separated list of code to generate; valid options: "types", "client", "chi-server", "server", "gin", "spec", "skip-fmt", "skip-prune"`)
`Comma-separated list of code to generate; valid options: "types", "client", "chi-server", "server", "gin", "gorilla", "spec", "skip-fmt", "skip-prune"`)
flag.StringVar(&flagIncludeTags, "include-tags", "", "Only include operations with the given tags. Comma-separated list of tags.")
flag.StringVar(&flagExcludeTags, "exclude-tags", "", "Exclude operations that are tagged with the given tags. Comma-separated list of tags.")
flag.StringVar(&flagTemplatesDir, "templates", "", "Path to directory containing user templates")
Expand Down Expand Up @@ -321,6 +321,8 @@ func newConfigFromOldConfig(c oldConfiguration) configuration {
opts.Generate.EchoServer = true
case "gin":
opts.Generate.GinServer = true
case "gorilla":
opts.Generate.GorillaServer = true
case "types":
opts.Generate.Models = true
case "spec":
Expand Down
6 changes: 6 additions & 0 deletions examples/petstore-expanded/gorilla/api/cfg.yaml
@@ -0,0 +1,6 @@
package: api
generate:
gorilla-server: true
models: true
embedded-spec: true
output: petstore.gen.go

0 comments on commit fcdb08f

Please sign in to comment.