Skip to content

Echo: generate Unimplemented implementation#631

Closed
urso wants to merge 1 commit intooapi-codegen:mainfrom
urso:echo-unimplemented
Closed

Echo: generate Unimplemented implementation#631
urso wants to merge 1 commit intooapi-codegen:mainfrom
urso:echo-unimplemented

Conversation

@urso
Copy link
Copy Markdown

@urso urso commented Jun 16, 2022

Update echo-interface.tmpl to generate an implementation for ServerInterface that always returns a 404.

The Unimplemented server can be used like this (assuming the code is generated in package spec):

type MyAPIServer struct {
  spec.Unimplemented
}

...

Using Unimplemented is optional, but might help when prototyping APIs or in case the OpenAPI spec is managed in a separate repo and mutliple developers.

grpc-go uses a similar strategy. For example see the examples/route_guide/server/server.go file.

Comment thread pkg/codegen/templates/echo/echo-interface.tmpl Outdated
type Unimplemented struct {}
{{range .}}{{.SummaryAsComment }}
// ({{.Method}} {{.Path}})
func (_ Unimplemented) {{.OperationId}}(ctx echo.Context{{genParamArgs .PathParams}}{{if .RequiresParamObject}}, params {{.OperationId}}Params{{end}}) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (_ Unimplemented) {{.OperationId}}(ctx echo.Context{{genParamArgs .PathParams}}{{if .RequiresParamObject}}, params {{.OperationId}}Params{{end}}) error {
func (Unimplemented) {{.OperationId}}(ctx echo.Context{{genParamArgs .PathParams}}{{if .RequiresParamObject}}, params {{.OperationId}}Params{{end}}) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mirrors how we've done it in #1090

Update echo-interface.tmpl to generate an implementation for
ServerInterface that always returns a 404.

The `Unimplemented` server can be used like this (assuming the code is
generated in package `spec`):

```
type MyAPIServer struct {
  spec.Unimplemented
}

...
```

Using `Unimplemented` is optional, but might help when prototyping APIs
or in case the OpenAPI spec is managed in a separate repo and mutliple
developers.

grpc-go uses a similar strategy. For example see the
[examples/route_guide/server/server.go](https://github.com/grpc/grpc-go/blob/master/examples/route_guide/server/server.go#L57)
file.
@mromaszewicz
Copy link
Copy Markdown
Member

Thank you for contributing, and I'm very sorry for taking so long to get to this PR. At this point, the code has changed so much that it's no longer relevant because the Unimplemented struct pattern now exists for all 7 server frameworks (Echo, Chi, Fiber, Gin, Gorilla, Iris, stdhttp). This PR only targeted Echo's legacy template and the feature is already implemented.

@urso urso deleted the echo-unimplemented branch February 25, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants