swagger-api / swagger-api/swagger-codegen
Some generated go code will never be reached
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
The generated go code contains lines which cannot be reached. The api_xxx.go files contain
if localVarHttpResponse.StatusCode >= 300 {
newErr := GenericSwaggerError{
body: localVarBody,
error: localVarHttpResponse.Status,
}
if localVarHttpResponse.StatusCode == 201 {
var v ApiResponseDocument
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
}
if localVarHttpResponse.StatusCode == 403 {
....
The if clause checking for 201 will never be true because it is not >= 300
Swagger-codegen 2.4.28
java -jar swagger-codegen-cli.jar generate -i http://my-domain/restapi/swagger.yaml -l go -o /tmp/swagger-sdk-go/
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated api_xxx.go files and reproduce the output using the provided swagger-codegen-cli.jar command and input URL. Trace the Go generator template or entry point that emits the status-code checks, then verify generated code no longer contains a condition for status 201 inside the >= 300 branch.
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
- 45/100