swagger-api / swagger-api/swagger-codegen

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

Open
#11,857 1 comment 1 reaction 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

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

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

Start by reproducing the issue with the provided vuls-sample.yaml and the swagger-codegen generate ... -l go command. Inspect the generated model_task_get_task_detail_response_body.go file and compare the missing import behavior with the referenced OpenAPI Generator PR. Done means the generated Go SDK builds and the example main.go runs without the undefined os error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.