OpenAPITools / OpenAPITools/openapi-generator
[BUG] Missing model type declarations in generated Go code
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issuue still exists?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I use the openapitools/openapi-generator-cli docker image to generate a Go package. With the latest release I get errors complaining about undefined types when I try to use the autogenerated package.
This was not an issue with v4.3.1.
I used the Petstore example in the README.md file and see the same behavior.
Basically in the Petstore example there is a struct type called Pet. It is used in various places in the generated code such as here in api_pet.go:
func (r ApiFindPetsByStatusRequest) Execute() ([]Pet, *_nethttp.Response, error) {
But its not defined anywhere.
In v4.3.1 it is defined in a file called model_pet.go, but there are no model_ files generated with v5.0.0.
openapi-generator version
v5.0.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Using example in README file:
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g go -o /local/out/go
No Pet type defined:
> grep -rI "type Pet" ./out/go/
./out/go/api_pet.go:type PetApiService service
>
But used in multiple places:
> grep -rI "Pet)" ./out/go/
./out/go/api_pet.go:func (r ApiAddPetRequest) Body(body Pet) ApiAddPetRequest {
./out/go/api_pet.go:func (r ApiUpdatePetRequest) Body(body Pet) ApiUpdatePetRequest {
...
With 4.3.1:
> sudo rm -rf out
> docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v4.3.1 generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g go -o /local/out/go
Pet defined in model_pet.go:
> grep -rI "type Pet " ./out/go/
./out/go/model_pet.go:type Pet struct {
>
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the README generation command and the Petstore spec at modules/openapi-generator/src/test/resources/2_0/petstore.yaml. Compare generated api_pet.go with the v4.3.1 output, especially the missing model_pet.go and references to Pet. Done means the Go generator again emits model declarations usable by the generated API code and the reproduction no longer reports undefined types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- backend-api-design, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100