Skip to content

[BUG] [go-server][golang] Trivial API file causes the generated code not to compile, due to missing imports "io" and "errors" #19237

@Andrei-Errapart

Description

@Andrei-Errapart
Description

The code generated doesn't compile, with the following error message:

go/api_silly_api.go:65:50: undefined: errors
go/api_silly_api.go:65:65: undefined: io
openapi-generator version
  • 7.6.0
  • 7.7.0
  • 8.0.0-20240527.073301-5
    They all exhibit the same behaviour.
OpenAPI declaration file content or url

https://gist.github.com/Andrei-Errapart/8a7eeaf6744aad7409a054df6f7fc398

Generation Details

All default options.

Steps to reproduce
rm -rf sillyserver
mkdir -p sillyserver
java -jar $jar generate -i api-1.0.1.yaml -g go-server --output sillyserver || exit $?
cd sillyserver
go get || exit $?
go build . || exit $?
Related issues/PRs

#8847

Perhaps the same trick can be employed here: simply assign unused imports

Suggest a fix

Here is one recommendation: #8847 possible fix

The idea is to use to mark the imports as used and generate them always:

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions