swagger-api / swagger-api/swagger-codegen
[Go] Bug generating nested imports
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Go client generator generates nested imports when --import-mappings is specified
Swagger-codegen version
swagger-codegen-cli-2.4.27.jar
Swagger declaration file content or url
Command line used for generation
java -jar swagger-codegen-cli-2.4.27.jar generate -i pet.json -l go --import-mappings uuid.UUID='github.com/google/uuid' --type-mappings UUID=uuid.UUID -o go-client
Steps to reproduce
- Execute the swagger-codegen-cli specified above.
- Check the generated pet_dto.go
Result
package swagger
import (
import (
"github.com/google/uuid"
"time"
)
)
type PetDto struct {
// The creation timestamp
CreatedAt time.Time `json:"createdAt,omitempty"`
// The user who created
CreatedBy uuid.UUID `json:"createdBy,omitempty"`
// The ID
Id uuid.UUID `json:"id,omitempty"`
// The name of the pet
Name string `json:"name,omitempty"`
}
Related issues/PRs
#11776
Suggest a fix/enhancement
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
Reproduce the issue with swagger-codegen-cli-2.4.27.jar, the linked swagger.json, and the shown Go generation command. Inspect the generated pet_dto.go and the Go generator templates or entry points responsible for imports. Done means generation no longer produces a nested import block and the resulting file has the expected imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100