Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix for Issue #8766
  • Loading branch information
beardeddragon5 committed Oct 2, 2018
commit d58ad9cb977b6d1e2f8dfbe021bb12a6cbfed752
14 changes: 12 additions & 2 deletions modules/swagger-codegen/src/main/resources/go/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (c *APIClient) prepareRequest(
}

// add form parameters and file if available.
if len(formParams) > 0 || (len(fileBytes) > 0 && fileName != "") {
if strings.HasPrefix(headerParams["Content-Type"], "multipart/form-data") && len(formParams) > 0 || (len(fileBytes) > 0 && fileName != "") {
if body != nil {
return nil, errors.New("Cannot specify postBody and multipart form at the same time.")
}
Expand Down Expand Up @@ -224,6 +224,16 @@ func (c *APIClient) prepareRequest(
w.Close()
}

if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 {
if body != nil {
return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.")
}
body = &bytes.Buffer{}
body.WriteString(formParams.Encode())
// Set Content-Length
headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len())
}

// Setup path and query parameters
url, err := url.Parse(path)
if err != nil {
Expand Down Expand Up @@ -465,4 +475,4 @@ func (e GenericSwaggerError) Body() []byte {
// Model returns the unpacked model of the error
func (e GenericSwaggerError) Model() interface{} {
return e.model
}
}
30 changes: 15 additions & 15 deletions samples/client/petstore/go/go-petstore/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,6 @@ paths:
responses:
200:
description: "successful operation"
schema:
type: "string"
headers:
X-Rate-Limit:
type: "integer"
Expand All @@ -503,6 +501,8 @@ paths:
type: "string"
format: "date-time"
description: "date in UTC when token expires"
schema:
type: "string"
400:
description: "Invalid username/password supplied"
/user/logout:
Expand Down Expand Up @@ -1105,15 +1105,15 @@ definitions:
complete:
type: "boolean"
default: false
xml:
name: "Order"
example:
petId: 6
quantity: 1
id: 0
shipDate: "2000-01-23T04:56:07.000+00:00"
complete: false
status: "placed"
xml:
name: "Order"
Category:
type: "object"
properties:
Expand All @@ -1122,11 +1122,11 @@ definitions:
format: "int64"
name:
type: "string"
xml:
name: "Category"
example:
name: "name"
id: 6
xml:
name: "Category"
User:
type: "object"
properties:
Expand All @@ -1150,6 +1150,8 @@ definitions:
type: "integer"
format: "int32"
description: "User Status"
xml:
name: "User"
example:
firstName: "firstName"
lastName: "lastName"
Expand All @@ -1159,8 +1161,6 @@ definitions:
id: 0
email: "email"
username: "username"
xml:
name: "User"
Tag:
type: "object"
properties:
Expand All @@ -1169,11 +1169,11 @@ definitions:
format: "int64"
name:
type: "string"
xml:
name: "Tag"
example:
name: "name"
id: 1
xml:
name: "Tag"
Pet:
type: "object"
required:
Expand Down Expand Up @@ -1210,6 +1210,8 @@ definitions:
- "available"
- "pending"
- "sold"
xml:
name: "Pet"
example:
photoUrls:
- "photoUrls"
Expand All @@ -1225,8 +1227,6 @@ definitions:
- name: "name"
id: 1
status: "available"
xml:
name: "Pet"
ApiResponse:
type: "object"
properties:
Expand All @@ -1253,9 +1253,9 @@ definitions:
return:
type: "integer"
format: "int32"
description: "Model for testing reserved words"
xml:
name: "Return"
description: "Model for testing reserved words"
Name:
required:
- "name"
Expand All @@ -1272,19 +1272,19 @@ definitions:
123Number:
type: "integer"
readOnly: true
description: "Model for testing model name same as property name"
xml:
name: "Name"
description: "Model for testing model name same as property name"
200_response:
properties:
name:
type: "integer"
format: "int32"
class:
type: "string"
description: "Model for testing model name starting with number"
xml:
name: "Name"
description: "Model for testing model name starting with number"
ClassModel:
properties:
_class:
Expand Down
14 changes: 12 additions & 2 deletions samples/client/petstore/go/go-petstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (c *APIClient) prepareRequest(
}

// add form parameters and file if available.
if len(formParams) > 0 || (len(fileBytes) > 0 && fileName != "") {
if strings.HasPrefix(headerParams["Content-Type"], "multipart/form-data") && len(formParams) > 0 || (len(fileBytes) > 0 && fileName != "") {
if body != nil {
return nil, errors.New("Cannot specify postBody and multipart form at the same time.")
}
Expand Down Expand Up @@ -236,6 +236,16 @@ func (c *APIClient) prepareRequest(
w.Close()
}

if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 {
if body != nil {
return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.")
}
body = &bytes.Buffer{}
body.WriteString(formParams.Encode())
// Set Content-Length
headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len())
}

// Setup path and query parameters
url, err := url.Parse(path)
if err != nil {
Expand Down Expand Up @@ -477,4 +487,4 @@ func (e GenericSwaggerError) Body() []byte {
// Model returns the unpacked model of the error
func (e GenericSwaggerError) Model() interface{} {
return e.model
}
}