openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[GO] Generate imports for UnmarshalJSON func only when it's present

Open thiagoarrais opened this issue 2 months ago • 0 comments

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

thiagoarrais avatar Dec 09 '25 13:12 thiagoarrais