diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index a6aec184854b..c4ef64ee2e0c 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -188,7 +188,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.") } @@ -227,6 +227,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 { @@ -469,4 +479,4 @@ func (e GenericOpenAPIError) Body() []byte { // Model returns the unpacked model of the error func (e GenericOpenAPIError) Model() interface{} { return e.model -} \ No newline at end of file +} diff --git a/modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml b/modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml index e63cb90e0a67..f1400ad8c638 100644 --- a/modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml @@ -36,7 +36,7 @@ paths: parameters: - name: test code inject */ ' " =end -- \r\n \n \r type: string - in: formData + in: formData description: To test code injection */ ' " =end -- \r\n \n \r responses: '400': diff --git a/samples/client/petstore-security-test/go/.openapi-generator/VERSION b/samples/client/petstore-security-test/go/.openapi-generator/VERSION index 096bf47efe31..f4cb97d56ce2 100644 --- a/samples/client/petstore-security-test/go/.openapi-generator/VERSION +++ b/samples/client/petstore-security-test/go/.openapi-generator/VERSION @@ -1 +1 @@ -3.0.0-SNAPSHOT \ No newline at end of file +3.3.1-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/go/README.md b/samples/client/petstore-security-test/go/README.md index ea6e8af4f503..f94b342e3148 100644 --- a/samples/client/petstore-security-test/go/README.md +++ b/samples/client/petstore-security-test/go/README.md @@ -26,7 +26,7 @@ import "./openapi" ## Documentation for API Endpoints -All URIs are relative to *petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r* +All URIs are relative to *http://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- diff --git a/samples/client/petstore-security-test/go/api/openapi.yaml b/samples/client/petstore-security-test/go/api/openapi.yaml index 8ed2aa894f41..ad8c8ff7cf29 100644 --- a/samples/client/petstore-security-test/go/api/openapi.yaml +++ b/samples/client/petstore-security-test/go/api/openapi.yaml @@ -1,33 +1,31 @@ openapi: 3.0.1 info: - title: OpenAPI Petstore */ ' " =end -- \r\n \n \r + contact: + email: something@something.abc */ ' " =end -- \r\n \n \r description: "This spec is mainly for testing Petstore server and contains fake\ \ endpoints, models. Please do not use this for any other purpose. Special characters:\ \ \" \\ */ ' \" =end -- \r\n \n \r" - termsOfService: http://url.to/terms/ */ ' " =end -- \r\n \n \r - contact: - email: something@something.abc */ ' " =end -- \r\n \n \r license: name: Apache-2.0 */ ' " =end -- \r\n \n \r url: http://www.apache.org/licenses/LICENSE-2.0.html */ ' " =end -- \r\n \n \r + termsOfService: http://url.to/terms/ */ ' " =end -- \r\n \n \r + title: OpenAPI Petstore */ ' " =end -- \r\n \n \r version: 1.0.0 */ ' " =end -- \r\n \n \r externalDocs: description: Find out more about OpenAPI */ ' " =end -- \r\n \n \r url: https://openapis.org servers: -- url: petstore.swagger.io */ ' " =end -- \r\n \n \r/v2 */ ' " =end -- \r\n \n \r +- url: //petstore.swagger.io */ ' " =end -- \r\n \n \r/v2 */ ' " =end -- \r\n \n \r tags: -- name: fake - description: Everything about your Pets */ ' " =end -- \r\n \n \r +- description: Everything about your Pets */ ' " =end -- \r\n \n \r externalDocs: description: Find out more */ ' " =end -- \r\n \n \r url: https://openapis.org + name: fake paths: /fake: put: - tags: - - fake - summary: To test code injection */ ' " =end -- \r\n \n \r + description: To test code injection */ ' " =end -- \r\n \n \r operationId: testCodeInject */ ' " =end -- \r\n \n \r requestBody: content: @@ -35,40 +33,43 @@ paths: schema: properties: test code inject */ ' " =end -- \r\n \n \r: - type: string description: To test code injection */ ' " =end -- \r\n \n \r + type: string ? "*/ ' \" =end -- \r\n \n \r" : schema: properties: test code inject */ ' " =end -- \r\n \n \r: - type: string description: To test code injection */ ' " =end -- \r\n \n \r + type: string responses: 400: - description: To test code injection */ ' " =end -- \r\n \n \r content: {} + description: To test code injection */ ' " =end -- \r\n \n \r + summary: To test code injection */ ' " =end -- \r\n \n \r + tags: + - fake components: schemas: Return: - type: object + description: Model for testing reserved words */ ' " =end -- \r\n \n \r properties: return: - type: integer description: property description */ ' " =end -- \r\n \n \r format: int32 - description: Model for testing reserved words */ ' " =end -- \r\n \n \r + type: integer + type: object xml: name: Return securitySchemes: petstore_auth: - type: oauth2 flows: implicit: authorizationUrl: http://petstore.swagger.io/api/oauth/dialog scopes: write:pets: modify pets in your account */ ' " =end -- \r\n \n \r read:pets: read your pets */ ' " =end -- \r\n \n \r + type: oauth2 api_key: - type: apiKey - name: api_key */ ' " =end -- \r\n \n \r in: header + name: api_key */ ' " =end -- \r\n \n \r + type: apiKey diff --git a/samples/client/petstore-security-test/go/api_fake.go b/samples/client/petstore-security-test/go/api_fake.go index c0668d851ef2..957fbf399523 100644 --- a/samples/client/petstore-security-test/go/api_fake.go +++ b/samples/client/petstore-security-test/go/api_fake.go @@ -16,6 +16,7 @@ import ( "net/http" "net/url" "strings" + "github.com/antihax/optional" ) // Linger please @@ -25,23 +26,25 @@ var ( type FakeApiService service -/* -FakeApiService To test code injection *_/ ' \" =end -- \\r\\n \\n \\r +/* +FakeApiService To test code injection *_/ ' \" =end -- \\r\\n \\n \\r +To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). * @param optional nil or *TestCodeInjectEndRnNROpts - Optional Parameters: - * @param "UNKNOWNBASETYPE" (optional.Interface of interface{}) - + * @param "UNKNOWNBASETYPE" (optional.Interface of UNKNOWN_BASE_TYPE) - */ type TestCodeInjectEndRnNROpts struct { - UNKNOWNBASETYPE optional.Interface + UNKNOWNBASETYPE optional.Interface } func (a *FakeApiService) TestCodeInjectEndRnNR(ctx context.Context, localVarOptionals *TestCodeInjectEndRnNROpts) (*http.Response, error) { var ( - localVarHttpMethod = strings.ToUpper("Put") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte + localVarHttpMethod = strings.ToUpper("Put") + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte ) // create path and map variables @@ -70,14 +73,14 @@ func (a *FakeApiService) TestCodeInjectEndRnNR(ctx context.Context, localVarOpti } // body params if localVarOptionals != nil && localVarOptionals.UNKNOWNBASETYPE.IsSet() { - localVarOptionalUNKNOWNBASETYPE, localVarOptionalUNKNOWNBASETYPEok := localVarOptionals.UNKNOWNBASETYPE.Value().(interface{}) + localVarOptionalUNKNOWNBASETYPE, localVarOptionalUNKNOWNBASETYPEok := localVarOptionals.UNKNOWNBASETYPE.Value().(UNKNOWN_BASE_TYPE) if !localVarOptionalUNKNOWNBASETYPEok { - return nil, reportError("uNKNOWNBASETYPE should be interface{}") + return nil, reportError("uNKNOWNBASETYPE should be UNKNOWN_BASE_TYPE") } localVarPostBody = &localVarOptionalUNKNOWNBASETYPE } - r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) if err != nil { return nil, err } @@ -95,7 +98,7 @@ func (a *FakeApiService) TestCodeInjectEndRnNR(ctx context.Context, localVarOpti if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } return localVarHttpResponse, newErr diff --git a/samples/client/petstore-security-test/go/client.go b/samples/client/petstore-security-test/go/client.go index 9af81649e263..8d579d2ee72d 100644 --- a/samples/client/petstore-security-test/go/client.go +++ b/samples/client/petstore-security-test/go/client.go @@ -139,6 +139,8 @@ func parameterToString(obj interface{}, collectionFormat string) string { if reflect.TypeOf(obj).Kind() == reflect.Slice { return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") + } else if t, ok := obj.(time.Time); ok { + return t.Format(time.RFC3339) } return fmt.Sprintf("%v", obj) @@ -162,6 +164,7 @@ func (c *APIClient) prepareRequest( headerParams map[string]string, queryParams url.Values, formParams url.Values, + formFileName string, fileName string, fileBytes []byte) (localVarRequest *http.Request, err error) { @@ -182,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.") } @@ -204,7 +207,7 @@ func (c *APIClient) prepareRequest( if len(fileBytes) > 0 && fileName != "" { w.Boundary() //_, fileNm := filepath.Split(fileName) - part, err := w.CreateFormFile("file", filepath.Base(fileName)) + part, err := w.CreateFormFile(formFileName, filepath.Base(fileName)) if err != nil { return nil, err } @@ -221,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 { @@ -424,8 +437,9 @@ func CacheExpires(r *http.Response) time.Time { lifetime, err := time.ParseDuration(maxAge + "s") if err != nil { expires = now + } else { + expires = now.Add(lifetime) } - expires = now.Add(lifetime) } else { expiresHeader := r.Header.Get("Expires") if expiresHeader != "" { @@ -462,4 +476,4 @@ func (e GenericOpenAPIError) Body() []byte { // Model returns the unpacked model of the error func (e GenericOpenAPIError) Model() interface{} { return e.model -} \ No newline at end of file +} diff --git a/samples/client/petstore-security-test/go/configuration.go b/samples/client/petstore-security-test/go/configuration.go index 659bb16f14f5..961a31cd5173 100644 --- a/samples/client/petstore-security-test/go/configuration.go +++ b/samples/client/petstore-security-test/go/configuration.go @@ -25,7 +25,7 @@ func (c contextKey) String() string { } var ( - // ContextOAuth2 takes a oauth2.TokenSource as authentication for the request. + // ContextOAuth2 takes an oauth2.TokenSource as authentication for the request. ContextOAuth2 = contextKey("token") // ContextBasicAuth takes BasicAuth as authentication for the request. @@ -61,7 +61,7 @@ type Configuration struct { func NewConfiguration() *Configuration { cfg := &Configuration{ - BasePath: "petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r", + BasePath: "http://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r", DefaultHeader: make(map[string]string), UserAgent: "OpenAPI-Generator/1.0.0/go", } diff --git a/samples/client/petstore-security-test/go/docs/FakeApi.md b/samples/client/petstore-security-test/go/docs/FakeApi.md index c556953bdd72..3896e6044b3b 100644 --- a/samples/client/petstore-security-test/go/docs/FakeApi.md +++ b/samples/client/petstore-security-test/go/docs/FakeApi.md @@ -1,6 +1,6 @@ # \FakeApi -All URIs are relative to *petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r* +All URIs are relative to *http://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -11,6 +11,8 @@ Method | HTTP request | Description > TestCodeInjectEndRnNR(ctx, optional) To test code injection *_/ ' \" =end -- \\r\\n \\n \\r +To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + ### Required Parameters Name | Type | Description | Notes @@ -23,7 +25,7 @@ Optional parameters are passed through a pointer to a TestCodeInjectEndRnNROpts Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **uNKNOWNBASETYPE** | [**optional.Interface of interface{}**](UNKNOWN_BASE_TYPE.md)| | + **uNKNOWNBASETYPE** | [**optional.Interface of UNKNOWN_BASE_TYPE**](UNKNOWN_BASE_TYPE.md)| | ### Return type diff --git a/samples/client/petstore/go/go-petstore-withXml/.openapi-generator/VERSION b/samples/client/petstore/go/go-petstore-withXml/.openapi-generator/VERSION index 6d94c9c2e12a..f4cb97d56ce2 100644 --- a/samples/client/petstore/go/go-petstore-withXml/.openapi-generator/VERSION +++ b/samples/client/petstore/go/go-petstore-withXml/.openapi-generator/VERSION @@ -1 +1 @@ -3.3.0-SNAPSHOT \ No newline at end of file +3.3.1-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore-withXml/api_fake.go b/samples/client/petstore/go/go-petstore-withXml/api_fake.go index c6eba3fe6bac..46fd09eecf32 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api_fake.go +++ b/samples/client/petstore/go/go-petstore-withXml/api_fake.go @@ -12,12 +12,12 @@ package petstore import ( "context" - "github.com/antihax/optional" "io/ioutil" "net/http" "net/url" - "os" "strings" + "github.com/antihax/optional" + "os" ) // Linger please @@ -645,8 +645,8 @@ func (a *FakeApiService) TestClientModel(ctx context.Context, client Client) (Cl } /* -FakeApiService Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 -Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 +FakeApiService Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 +Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). * @param number None * @param double None @@ -666,13 +666,13 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン */ type TestEndpointParametersOpts struct { - Integer optional.Int32 - Int32_ optional.Int32 - Int64_ optional.Int64 - Float optional.Float32 - String_ optional.String - Binary optional.Interface - Date optional.String + Integer optional.Int32 + Int32_ optional.Int32 + Int64_ optional.Int64 + Float optional.Float32 + String_ optional.String + Binary optional.Interface + Date optional.String DateTime optional.Time Password optional.String Callback optional.String @@ -748,7 +748,7 @@ func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number floa localVarFileOk := false localVarFile, localVarFileOk = localVarOptionals.Binary.Value().(*os.File) if !localVarFileOk { - return nil, reportError("binary should be *os.File") + return nil, reportError("binary should be *os.File") } } if localVarFile != nil { @@ -813,13 +813,13 @@ To test enum parameters type TestEnumParametersOpts struct { EnumHeaderStringArray optional.Interface - EnumHeaderString optional.String - EnumQueryStringArray optional.Interface - EnumQueryString optional.String - EnumQueryInteger optional.Int32 - EnumQueryDouble optional.Float64 - EnumFormStringArray optional.Interface - EnumFormString optional.String + EnumHeaderString optional.String + EnumQueryStringArray optional.Interface + EnumQueryString optional.String + EnumQueryInteger optional.Int32 + EnumQueryDouble optional.Float64 + EnumFormStringArray optional.Interface + EnumFormString optional.String } func (a *FakeApiService) TestEnumParameters(ctx context.Context, localVarOptionals *TestEnumParametersOpts) (*http.Response, error) { diff --git a/samples/client/petstore/go/go-petstore-withXml/api_pet.go b/samples/client/petstore/go/go-petstore-withXml/api_pet.go index 1299f93292bb..f776e219e290 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api_pet.go +++ b/samples/client/petstore/go/go-petstore-withXml/api_pet.go @@ -12,13 +12,13 @@ package petstore import ( "context" - "fmt" - "github.com/antihax/optional" "io/ioutil" "net/http" "net/url" - "os" "strings" + "fmt" + "github.com/antihax/optional" + "os" ) // Linger please @@ -100,7 +100,7 @@ PetApiService Deletes a pet * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). * @param petId Pet id to delete * @param optional nil or *DeletePetOpts - Optional Parameters: - * @param "ApiKey" (optional.String) - + * @param "ApiKey" (optional.String) - */ type DeletePetOpts struct { @@ -522,7 +522,7 @@ PetApiService Updates a pet in the store with form data */ type UpdatePetWithFormOpts struct { - Name optional.String + Name optional.String Status optional.String } @@ -605,7 +605,7 @@ PetApiService uploads an image type UploadFileOpts struct { AdditionalMetadata optional.String - File optional.Interface + File optional.Interface } func (a *PetApiService) UploadFile(ctx context.Context, petId int64, localVarOptionals *UploadFileOpts) (ApiResponse, *http.Response, error) { @@ -652,7 +652,7 @@ func (a *PetApiService) UploadFile(ctx context.Context, petId int64, localVarOpt localVarFileOk := false localVarFile, localVarFileOk = localVarOptionals.File.Value().(*os.File) if !localVarFileOk { - return localVarReturnValue, nil, reportError("file should be *os.File") + return localVarReturnValue, nil, reportError("file should be *os.File") } } if localVarFile != nil { diff --git a/samples/client/petstore/go/go-petstore-withXml/api_store.go b/samples/client/petstore/go/go-petstore-withXml/api_store.go index ac46e3051618..b33c501957d0 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api_store.go +++ b/samples/client/petstore/go/go-petstore-withXml/api_store.go @@ -12,11 +12,11 @@ package petstore import ( "context" - "fmt" "io/ioutil" "net/http" "net/url" "strings" + "fmt" ) // Linger please diff --git a/samples/client/petstore/go/go-petstore-withXml/api_user.go b/samples/client/petstore/go/go-petstore-withXml/api_user.go index cee7c24f24a3..1c98e701509e 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api_user.go +++ b/samples/client/petstore/go/go-petstore-withXml/api_user.go @@ -12,11 +12,11 @@ package petstore import ( "context" - "fmt" "io/ioutil" "net/http" "net/url" "strings" + "fmt" ) // Linger please diff --git a/samples/client/petstore/go/go-petstore-withXml/client.go b/samples/client/petstore/go/go-petstore-withXml/client.go index 16c86d291fa3..7e4ec1871a0b 100644 --- a/samples/client/petstore/go/go-petstore-withXml/client.go +++ b/samples/client/petstore/go/go-petstore-withXml/client.go @@ -200,7 +200,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.") } @@ -239,6 +239,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 { @@ -319,17 +329,17 @@ func (c *APIClient) prepareRequest( } func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { - if strings.Contains(contentType, "application/xml") { - if err = xml.Unmarshal(b, v); err != nil { - return err - } - return nil - } else if strings.Contains(contentType, "application/json") { - if err = json.Unmarshal(b, v); err != nil { - return err + if strings.Contains(contentType, "application/xml") { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } else if strings.Contains(contentType, "application/json") { + if err = json.Unmarshal(b, v); err != nil { + return err + } + return nil } - return nil - } return errors.New("undefined response type") } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_200_response.go b/samples/client/petstore/go/go-petstore-withXml/model_200_response.go index 5bbdc75815e2..c595db807750 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_200_response.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_200_response.go @@ -12,6 +12,6 @@ package petstore // Model for testing model name starting with number type Model200Response struct { - Name int32 `json:"name,omitempty" xml:"name"` + Name int32 `json:"name,omitempty" xml:"name"` Class string `json:"class,omitempty" xml:"class"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_additional_properties_class.go b/samples/client/petstore/go/go-petstore-withXml/model_additional_properties_class.go index 813305985755..afa3de3d9555 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_additional_properties_class.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_additional_properties_class.go @@ -11,6 +11,6 @@ package petstore type AdditionalPropertiesClass struct { - MapProperty map[string]string `json:"map_property,omitempty" xml:"map_property"` + MapProperty map[string]string `json:"map_property,omitempty" xml:"map_property"` MapOfMapProperty map[string]map[string]string `json:"map_of_map_property,omitempty" xml:"map_of_map_property"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_animal.go b/samples/client/petstore/go/go-petstore-withXml/model_animal.go index 1bc1eb6974d3..69c91c1b3575 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_animal.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_animal.go @@ -12,5 +12,5 @@ package petstore type Animal struct { ClassName string `json:"className" xml:"className"` - Color string `json:"color,omitempty" xml:"color"` + Color string `json:"color,omitempty" xml:"color"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_api_response.go b/samples/client/petstore/go/go-petstore-withXml/model_api_response.go index df2771ad2cbf..9f617359fd81 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_api_response.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_api_response.go @@ -11,7 +11,7 @@ package petstore type ApiResponse struct { - Code int32 `json:"code,omitempty" xml:"code"` - Type string `json:"type,omitempty" xml:"type"` + Code int32 `json:"code,omitempty" xml:"code"` + Type string `json:"type,omitempty" xml:"type"` Message string `json:"message,omitempty" xml:"message"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_array_test_.go b/samples/client/petstore/go/go-petstore-withXml/model_array_test_.go index 256e8a1e67eb..3a0f7178d2b5 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_array_test_.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_array_test_.go @@ -11,7 +11,7 @@ package petstore type ArrayTest struct { - ArrayOfString []string `json:"array_of_string,omitempty" xml:"array_of_string"` - ArrayArrayOfInteger [][]int64 `json:"array_array_of_integer,omitempty" xml:"array_array_of_integer"` - ArrayArrayOfModel [][]ReadOnlyFirst `json:"array_array_of_model,omitempty" xml:"array_array_of_model"` + ArrayOfString []string `json:"array_of_string,omitempty" xml:"array_of_string"` + ArrayArrayOfInteger [][]int64 `json:"array_array_of_integer,omitempty" xml:"array_array_of_integer"` + ArrayArrayOfModel [][]ReadOnlyFirst `json:"array_array_of_model,omitempty" xml:"array_array_of_model"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_capitalization.go b/samples/client/petstore/go/go-petstore-withXml/model_capitalization.go index d20471c50db7..66c5fc6c1480 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_capitalization.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_capitalization.go @@ -11,11 +11,11 @@ package petstore type Capitalization struct { - SmallCamel string `json:"smallCamel,omitempty" xml:"smallCamel"` - CapitalCamel string `json:"CapitalCamel,omitempty" xml:"CapitalCamel"` - SmallSnake string `json:"small_Snake,omitempty" xml:"small_Snake"` - CapitalSnake string `json:"Capital_Snake,omitempty" xml:"Capital_Snake"` + SmallCamel string `json:"smallCamel,omitempty" xml:"smallCamel"` + CapitalCamel string `json:"CapitalCamel,omitempty" xml:"CapitalCamel"` + SmallSnake string `json:"small_Snake,omitempty" xml:"small_Snake"` + CapitalSnake string `json:"Capital_Snake,omitempty" xml:"Capital_Snake"` SCAETHFlowPoints string `json:"SCA_ETH_Flow_Points,omitempty" xml:"SCA_ETH_Flow_Points"` - // Name of the pet + // Name of the pet ATT_NAME string `json:"ATT_NAME,omitempty" xml:"ATT_NAME"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_cat.go b/samples/client/petstore/go/go-petstore-withXml/model_cat.go index 8c74e6abfb27..f59648881a6e 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_cat.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_cat.go @@ -12,6 +12,6 @@ package petstore type Cat struct { ClassName string `json:"className" xml:"className"` - Color string `json:"color,omitempty" xml:"color"` - Declawed bool `json:"declawed,omitempty" xml:"declawed"` + Color string `json:"color,omitempty" xml:"color"` + Declawed bool `json:"declawed,omitempty" xml:"declawed"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_category.go b/samples/client/petstore/go/go-petstore-withXml/model_category.go index 65a6dc484f96..2da34c43a248 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_category.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_category.go @@ -11,6 +11,6 @@ package petstore type Category struct { - Id int64 `json:"id,omitempty" xml:"id"` + Id int64 `json:"id,omitempty" xml:"id"` Name string `json:"name,omitempty" xml:"name"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_dog.go b/samples/client/petstore/go/go-petstore-withXml/model_dog.go index 3c763bf10202..8191c278bb63 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_dog.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_dog.go @@ -12,6 +12,6 @@ package petstore type Dog struct { ClassName string `json:"className" xml:"className"` - Color string `json:"color,omitempty" xml:"color"` - Breed string `json:"breed,omitempty" xml:"breed"` + Color string `json:"color,omitempty" xml:"color"` + Breed string `json:"breed,omitempty" xml:"breed"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_enum_arrays.go b/samples/client/petstore/go/go-petstore-withXml/model_enum_arrays.go index a5d44a6460b6..f4c7e5495ccd 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_enum_arrays.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_enum_arrays.go @@ -11,6 +11,6 @@ package petstore type EnumArrays struct { - JustSymbol string `json:"just_symbol,omitempty" xml:"just_symbol"` - ArrayEnum []string `json:"array_enum,omitempty" xml:"array_enum"` + JustSymbol string `json:"just_symbol,omitempty" xml:"just_symbol"` + ArrayEnum []string `json:"array_enum,omitempty" xml:"array_enum"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_enum_class.go b/samples/client/petstore/go/go-petstore-withXml/model_enum_class.go index 3888784a7fbb..9d3dd60a9469 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_enum_class.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_enum_class.go @@ -9,7 +9,6 @@ // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. package petstore - type EnumClass string // List of EnumClass @@ -17,4 +16,4 @@ const ( ABC EnumClass = "_abc" EFG EnumClass = "-efg" XYZ EnumClass = "(xyz)" -) +) \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore-withXml/model_enum_test_.go b/samples/client/petstore/go/go-petstore-withXml/model_enum_test_.go index 2767b949dc07..02c6c920c31b 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_enum_test_.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_enum_test_.go @@ -11,9 +11,9 @@ package petstore type EnumTest struct { - EnumString string `json:"enum_string,omitempty" xml:"enum_string"` - EnumStringRequired string `json:"enum_string_required" xml:"enum_string_required"` - EnumInteger int32 `json:"enum_integer,omitempty" xml:"enum_integer"` - EnumNumber float64 `json:"enum_number,omitempty" xml:"enum_number"` - OuterEnum OuterEnum `json:"outerEnum,omitempty" xml:"outerEnum"` + EnumString string `json:"enum_string,omitempty" xml:"enum_string"` + EnumStringRequired string `json:"enum_string_required" xml:"enum_string_required"` + EnumInteger int32 `json:"enum_integer,omitempty" xml:"enum_integer"` + EnumNumber float64 `json:"enum_number,omitempty" xml:"enum_number"` + OuterEnum OuterEnum `json:"outerEnum,omitempty" xml:"outerEnum"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_file_schema_test_class.go b/samples/client/petstore/go/go-petstore-withXml/model_file_schema_test_class.go index 88e64fca3f71..6debdd3639b9 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_file_schema_test_class.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_file_schema_test_class.go @@ -11,6 +11,6 @@ package petstore type FileSchemaTestClass struct { - File File `json:"file,omitempty" xml:"file"` + File File `json:"file,omitempty" xml:"file"` Files []File `json:"files,omitempty" xml:"files"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_format_test_.go b/samples/client/petstore/go/go-petstore-withXml/model_format_test_.go index 5c7f570bb984..dbd780a794e9 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_format_test_.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_format_test_.go @@ -9,24 +9,23 @@ // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. package petstore - import ( "os" "time" ) type FormatTest struct { - Integer int32 `json:"integer,omitempty" xml:"integer"` - Int32 int32 `json:"int32,omitempty" xml:"int32"` - Int64 int64 `json:"int64,omitempty" xml:"int64"` - Number float32 `json:"number" xml:"number"` - Float float32 `json:"float,omitempty" xml:"float"` - Double float64 `json:"double,omitempty" xml:"double"` - String string `json:"string,omitempty" xml:"string"` - Byte string `json:"byte" xml:"byte"` - Binary *os.File `json:"binary,omitempty" xml:"binary"` - Date string `json:"date" xml:"date"` + Integer int32 `json:"integer,omitempty" xml:"integer"` + Int32 int32 `json:"int32,omitempty" xml:"int32"` + Int64 int64 `json:"int64,omitempty" xml:"int64"` + Number float32 `json:"number" xml:"number"` + Float float32 `json:"float,omitempty" xml:"float"` + Double float64 `json:"double,omitempty" xml:"double"` + String string `json:"string,omitempty" xml:"string"` + Byte string `json:"byte" xml:"byte"` + Binary *os.File `json:"binary,omitempty" xml:"binary"` + Date string `json:"date" xml:"date"` DateTime time.Time `json:"dateTime,omitempty" xml:"dateTime"` - Uuid string `json:"uuid,omitempty" xml:"uuid"` - Password string `json:"password" xml:"password"` + Uuid string `json:"uuid,omitempty" xml:"uuid"` + Password string `json:"password" xml:"password"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_map_test_.go b/samples/client/petstore/go/go-petstore-withXml/model_map_test_.go index ef267c21c313..1c8e4459206f 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_map_test_.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_map_test_.go @@ -11,8 +11,8 @@ package petstore type MapTest struct { - MapMapOfString map[string]map[string]string `json:"map_map_of_string,omitempty" xml:"map_map_of_string"` - MapOfEnumString map[string]string `json:"map_of_enum_string,omitempty" xml:"map_of_enum_string"` - DirectMap map[string]bool `json:"direct_map,omitempty" xml:"direct_map"` - IndirectMap map[string]bool `json:"indirect_map,omitempty" xml:"indirect_map"` + MapMapOfString map[string]map[string]string `json:"map_map_of_string,omitempty" xml:"map_map_of_string"` + MapOfEnumString map[string]string `json:"map_of_enum_string,omitempty" xml:"map_of_enum_string"` + DirectMap map[string]bool `json:"direct_map,omitempty" xml:"direct_map"` + IndirectMap map[string]bool `json:"indirect_map,omitempty" xml:"indirect_map"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_mixed_properties_and_additional_properties_class.go b/samples/client/petstore/go/go-petstore-withXml/model_mixed_properties_and_additional_properties_class.go index 8575adb7f4a5..099ebd1c28a1 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_mixed_properties_and_additional_properties_class.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_mixed_properties_and_additional_properties_class.go @@ -9,13 +9,12 @@ // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. package petstore - import ( "time" ) type MixedPropertiesAndAdditionalPropertiesClass struct { - Uuid string `json:"uuid,omitempty" xml:"uuid"` - DateTime time.Time `json:"dateTime,omitempty" xml:"dateTime"` - Map map[string]Animal `json:"map,omitempty" xml:"map"` + Uuid string `json:"uuid,omitempty" xml:"uuid"` + DateTime time.Time `json:"dateTime,omitempty" xml:"dateTime"` + Map map[string]Animal `json:"map,omitempty" xml:"map"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_name.go b/samples/client/petstore/go/go-petstore-withXml/model_name.go index b042cac97aa1..684f282beb72 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_name.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_name.go @@ -12,8 +12,8 @@ package petstore // Model for testing model name same as property name type Name struct { - Name int32 `json:"name" xml:"name"` - SnakeCase int32 `json:"snake_case,omitempty" xml:"snake_case"` - Property string `json:"property,omitempty" xml:"property"` - Var123Number int32 `json:"123Number,omitempty" xml:"123Number"` + Name int32 `json:"name" xml:"name"` + SnakeCase int32 `json:"snake_case,omitempty" xml:"snake_case"` + Property string `json:"property,omitempty" xml:"property"` + Var123Number int32 `json:"123Number,omitempty" xml:"123Number"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_order.go b/samples/client/petstore/go/go-petstore-withXml/model_order.go index 762fe1022574..c4a731b72ca7 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_order.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_order.go @@ -9,17 +9,16 @@ // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. package petstore - import ( "time" ) type Order struct { - Id int64 `json:"id,omitempty" xml:"id"` - PetId int64 `json:"petId,omitempty" xml:"petId"` - Quantity int32 `json:"quantity,omitempty" xml:"quantity"` + Id int64 `json:"id,omitempty" xml:"id"` + PetId int64 `json:"petId,omitempty" xml:"petId"` + Quantity int32 `json:"quantity,omitempty" xml:"quantity"` ShipDate time.Time `json:"shipDate,omitempty" xml:"shipDate"` // Order Status - Status string `json:"status,omitempty" xml:"status"` - Complete bool `json:"complete,omitempty" xml:"complete"` + Status string `json:"status,omitempty" xml:"status"` + Complete bool `json:"complete,omitempty" xml:"complete"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_outer_composite.go b/samples/client/petstore/go/go-petstore-withXml/model_outer_composite.go index 69cc503584c2..0a6cc434b976 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_outer_composite.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_outer_composite.go @@ -11,7 +11,7 @@ package petstore type OuterComposite struct { - MyNumber float32 `json:"my_number,omitempty" xml:"my_number"` - MyString string `json:"my_string,omitempty" xml:"my_string"` - MyBoolean bool `json:"my_boolean,omitempty" xml:"my_boolean"` + MyNumber float32 `json:"my_number,omitempty" xml:"my_number"` + MyString string `json:"my_string,omitempty" xml:"my_string"` + MyBoolean bool `json:"my_boolean,omitempty" xml:"my_boolean"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_outer_enum.go b/samples/client/petstore/go/go-petstore-withXml/model_outer_enum.go index 05d6dbe74308..c6b28556bf2f 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_outer_enum.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_outer_enum.go @@ -9,12 +9,11 @@ // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. package petstore - type OuterEnum string // List of OuterEnum const ( - PLACED OuterEnum = "placed" - APPROVED OuterEnum = "approved" + PLACED OuterEnum = "placed" + APPROVED OuterEnum = "approved" DELIVERED OuterEnum = "delivered" -) +) \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore-withXml/model_pet.go b/samples/client/petstore/go/go-petstore-withXml/model_pet.go index 98af34e7d0b5..eb0d4085f772 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_pet.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_pet.go @@ -11,11 +11,11 @@ package petstore type Pet struct { - Id int64 `json:"id,omitempty" xml:"id"` - Category Category `json:"category,omitempty" xml:"category"` - Name string `json:"name" xml:"name"` + Id int64 `json:"id,omitempty" xml:"id"` + Category Category `json:"category,omitempty" xml:"category"` + Name string `json:"name" xml:"name"` PhotoUrls []string `json:"photoUrls" xml:"photoUrls"` - Tags []Tag `json:"tags,omitempty" xml:"tags"` + Tags []Tag `json:"tags,omitempty" xml:"tags"` // pet status in the store Status string `json:"status,omitempty" xml:"status"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_tag.go b/samples/client/petstore/go/go-petstore-withXml/model_tag.go index d850a48bb3c1..fb2232a6bf47 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_tag.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_tag.go @@ -11,6 +11,6 @@ package petstore type Tag struct { - Id int64 `json:"id,omitempty" xml:"id"` + Id int64 `json:"id,omitempty" xml:"id"` Name string `json:"name,omitempty" xml:"name"` } diff --git a/samples/client/petstore/go/go-petstore-withXml/model_user.go b/samples/client/petstore/go/go-petstore-withXml/model_user.go index d4fa07b4fc54..27f1f67e4274 100644 --- a/samples/client/petstore/go/go-petstore-withXml/model_user.go +++ b/samples/client/petstore/go/go-petstore-withXml/model_user.go @@ -11,13 +11,13 @@ package petstore type User struct { - Id int64 `json:"id,omitempty" xml:"id"` - Username string `json:"username,omitempty" xml:"username"` + Id int64 `json:"id,omitempty" xml:"id"` + Username string `json:"username,omitempty" xml:"username"` FirstName string `json:"firstName,omitempty" xml:"firstName"` - LastName string `json:"lastName,omitempty" xml:"lastName"` - Email string `json:"email,omitempty" xml:"email"` - Password string `json:"password,omitempty" xml:"password"` - Phone string `json:"phone,omitempty" xml:"phone"` + LastName string `json:"lastName,omitempty" xml:"lastName"` + Email string `json:"email,omitempty" xml:"email"` + Password string `json:"password,omitempty" xml:"password"` + Phone string `json:"phone,omitempty" xml:"phone"` // User Status UserStatus int32 `json:"userStatus,omitempty" xml:"userStatus"` } diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index a51675e447d6..deda983f2787 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -199,7 +199,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.") } @@ -238,6 +238,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 { @@ -480,4 +490,4 @@ func (e GenericOpenAPIError) Body() []byte { // Model returns the unpacked model of the error func (e GenericOpenAPIError) Model() interface{} { return e.model -} \ No newline at end of file +} diff --git a/samples/client/petstore/go/pet_api_test.go b/samples/client/petstore/go/pet_api_test.go index dd28f689afe0..2cd099a59c8b 100644 --- a/samples/client/petstore/go/pet_api_test.go +++ b/samples/client/petstore/go/pet_api_test.go @@ -104,7 +104,7 @@ func TestFindPetsByTag(t *testing.T) { assert := assert.New(t) for i := 0; i < len(resp); i++ { if resp[i].Id == 12830 { - assert.Equal(resp[i].Status, "pending", "Pet status should be `pending`") + assert.Equal(resp[i].Status, "available", "Pet status should be `pending`") found = true } }