swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

[Golang] Build error (undefined: os) when using generated golang client SDK #11857

Open MasatoYagi opened 2 years ago

MasatoYagi commented 2 years ago
Description

Missing import when a model's property is an array/map of file https://swagger.io/specification/v2/#:~:text=Model%20with%20Map/Dictionary%20Properties

Swagger-codegen version

3.0.34, 3.0.34

Swagger declaration file content or url

https://gist.githubusercontent.com/Masato516/ae52739d1dfd79a37edabe7375319df6/raw/5cef0fb8fe3a9664b51646845e1aca295314c155/vuls-sample.yaml

Command line used for generation

swagger-codegen generate -i https://gist.githubusercontent.com/Masato516/ae52739d1dfd79a37edabe7375319df6/raw/5cef0fb8fe3a9664b51646845e1aca295314c155/vuls-sample.yaml -l go -o ~/project/swagger-codegen/go/out/

Steps to reproduce

go run the below main.go (Due to a build error, the content of the code is not relevant to the problem.)

package main

import (
    "fmt"

    sw "localpackages/swagger"
)

func main() {
    configuration := sw.NewConfiguration()
    apiClient := sw.NewAPIClient(configuration)
    fmt.Println(apiClient)
}

output

Build Error: go build -o /Users/masato/project/swagger-codegen/go/example/api/__debug_bin -gcflags all=-N -l .
# localpackages/swagger
../swagger/model_task_get_task_detail_response_body.go:26:19: undefined: os (exit status 2)
Related issues/PRs

I reported a similar problem on the Openapi-generator that forked Swagger-codegen and got it fixed https://github.com/OpenAPITools/openapi-generator/pull/13143

Suggest a fix/enhancement

The following PR from the openapi-generator may be helpful in solving the problem. https://github.com/OpenAPITools/openapi-generator/pull/13143

MasatoYagi commented 1 year ago

Ver 2.x doesn't cause the error.