Skip to content

Commit fec990c

Browse files
DouglasDwyerDwyer
andauthored
Add support for strict server with Gorilla (oapi-codegen#716)
* Create strict-gorilla.tmpl * Add Gorilla template * Abstract strict HTTP server * Regenerate samples Co-authored-by: Dwyer <dodwyer@ptc.com>
1 parent c70fd2b commit fec990c

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

examples/petstore-expanded/strict/api/petstore-server.gen.go

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

internal/test/strict-server/chi/server.gen.go

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

pkg/codegen/operations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,8 @@ func GenerateGorillaServer(t *template.Template, operations []OperationDefinitio
911911

912912
func GenerateStrictServer(t *template.Template, operations []OperationDefinition, opts Configuration) (string, error) {
913913
templates := []string{"strict/strict-interface.tmpl"}
914-
if opts.Generate.ChiServer {
915-
templates = append(templates, "strict/strict-chi.tmpl")
914+
if opts.Generate.ChiServer || opts.Generate.GorillaServer {
915+
templates = append(templates, "strict/strict-http.tmpl")
916916
}
917917
if opts.Generate.EchoServer {
918918
templates = append(templates, "strict/strict-echo.tmpl")

pkg/codegen/templates/strict/strict-chi.tmpl renamed to pkg/codegen/templates/strict/strict-http.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ type StrictHandlerFunc func(ctx context.Context, w http.ResponseWriter, r *http.
22

33
type StrictMiddlewareFunc func(f StrictHandlerFunc, operationID string) StrictHandlerFunc
44

5-
type StrictChiServerOptions struct {
5+
type StrictHTTPServerOptions struct {
66
RequestErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
77
ResponseErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
88
}
99

1010
func NewStrictHandler(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc) ServerInterface {
11-
return &strictHandler{ssi: ssi, middlewares: middlewares, options: StrictChiServerOptions {
11+
return &strictHandler{ssi: ssi, middlewares: middlewares, options: StrictHTTPServerOptions {
1212
RequestErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {
1313
http.Error(w, err.Error(), http.StatusBadRequest)
1414
},
@@ -18,14 +18,14 @@ func NewStrictHandler(ssi StrictServerInterface, middlewares []StrictMiddlewareF
1818
}}
1919
}
2020

21-
func NewStrictHandlerWithOptions(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc, options StrictChiServerOptions) ServerInterface {
21+
func NewStrictHandlerWithOptions(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc, options StrictHTTPServerOptions) ServerInterface {
2222
return &strictHandler{ssi: ssi, middlewares: middlewares, options: options}
2323
}
2424

2525
type strictHandler struct {
2626
ssi StrictServerInterface
2727
middlewares []StrictMiddlewareFunc
28-
options StrictChiServerOptions
28+
options StrictHTTPServerOptions
2929
}
3030

3131
{{range .}}

0 commit comments

Comments
 (0)