Skip to content

Conversation

@thiagoarrais
Copy link
Contributor

Fixes #20599

As reported in the mentioned issue, openapi-generator currently generates unused imports when the UmarshalJSON func is not generated and the Go compiler will refuse to accept a program with unused imports. This PR fixes that by tying the addition of imports for bytes and fmt to the enablement of the generateUnmashalJSON flag.

Validation

When generating a Go client with this modification applied for the src/test/resources/3_0/petstore.yaml sample with the UnmarshalJSON flag disabled (-p 'generateUnmarshalJSON=false'), for example, the imports for bytes and fmt should not be present on top of generated file model_pet.go. The Go compiler should also compile the generated client without complaining. This does not happen with current main/master.

Mentioning the Go technical committee as per PR instructions: @antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @lwj5

@wing328
Copy link
Member

wing328 commented Dec 10, 2025

thanks for the fix

let's give it a try

@wing328 wing328 merged commit 8f8001e into OpenAPITools:master Dec 10, 2025
14 checks passed
@wing328 wing328 added this to the 7.18.0 milestone Dec 10, 2025
lucy66hw pushed a commit to lucy66hw/openapi-generator that referenced this pull request Dec 16, 2025
rajvesh pushed a commit to rajvesh/openapi-generator that referenced this pull request Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [GO] Unused imports "fmt" and "bytes" when generateMarshalJSON=false and generateUnmarshalJSON=false

2 participants