We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The Generated API Client for GoLang does not work properly for plain string body types.
The error message is: Invalid body type text/plain
Invalid body type text/plain
2.3.1
/Token/: post: operationId: Token consumes: - text/plain responses: '200': description: OK schema: type: string '400': description: Bad Request schema: type: string produces: - "application/json" - "text/json" parameters: - in: body name: body description: The Grand Type schema: type: string
Api_client.go
func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { bodyBuf = &bytes.Buffer{} } if reader, ok := body.(io.Reader); ok { _, err = bodyBuf.ReadFrom(reader) } else if b, ok := body.([]byte); ok { _, err = bodyBuf.Write(b) } else if s, ok := body.(string); ok { // <<-- _, err = bodyBuf.WriteString(s) } else if jsonCheck.MatchString(contentType) { err = json.NewEncoder(bodyBuf).Encode(body) } else if xmlCheck.MatchString(contentType) { xml.NewEncoder(bodyBuf).Encode(body) } if err != nil { return nil, err } if bodyBuf.Len() == 0 { err = fmt.Errorf("Invalid body type %s\n", contentType) return nil, err } return bodyBuf, nil }
The check should be changed from `body.(string); ok The body is an interface containing the pointer to the string.
} else if s, ok := body.(*string); ok { _, err = bodyBuf.WriteString(*s)
The text was updated successfully, but these errors were encountered:
Plain string body type can not be set
655dbbf
fixes swagger-api#7751
fixed by #7987
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
Description
The Generated API Client for GoLang does not work properly for plain string body types.
The error message is:
Invalid body type text/plain
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Steps to reproduce
Api_client.go
Suggest a fix/enhancement
The check should be changed from `body.(string); ok
The body is an interface containing the pointer to the string.
The text was updated successfully, but these errors were encountered: