swagger-api / swagger-api/swagger-codegen

[Go] Bug generating nested imports

Open
#11,775 0 comments 0 reactions 0 assignees View on GitHub

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

swagger.json

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
  1. Execute the swagger-codegen-cli specified above.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.