swagger icon indicating copy to clipboard operation
swagger copied to clipboard

fixed template rendering with current version of go-swagger

Open jpriebe opened this issue 5 years ago • 0 comments

Recently I started getting these errors when I try to compile code generated with stratoscale/swagger:

restapi/operations/foo/foo_create_parameters.go:56:38: not enough arguments in call to "github.com/go-openapi/errors".Required
        have (string, string)
        want (string, string, interface {})

A breaking change was made to go-openapi/errors in the summer of 2020:

  • https://github.com/go-openapi/errors/issues/22
  • https://github.com/go-openapi/errors/issues/25

In order for go-swagger-generated code to compile properly, you need to use at least version v0.24.0 of go-swagger:

  • https://github.com/go-swagger/go-swagger/issues/2361

Unfortunately, stratoscale/swagger is not compatible with the latest versions of go-swagger; the template fails to render with this error:

failed rendering template data for configure: template execution failed for template configure: template: serverConfigureapi:142:149: executing "serverConfigureapi" at <.WithContext>: can't evaluate field WithContext in type generator.GenOperation

I fixed this by removing the {{ if .WithContext }} conditional from the Operations block in server/configureapi.gotmpl. The template renders and the resulting code is compatible with the latest go-openapi/errors.

I'm not clear on the implications of removing the WithContext conditional. It's possible that other changes need to be made to the templates to compensate for the removal of this block. I'll leave that up to the experts. But I'd greatly appreciate a 1.0.28 release with a fix for this incompatibility.

jpriebe avatar Nov 20 '20 16:11 jpriebe