diff --git a/.travis.yml b/.travis.yml index 8dad41aea12d..12b482db89f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -93,7 +93,7 @@ after_success: - if [ $DOCKER_HUB_USERNAME ]; then echo "$DOCKER_HUB_PASSWORD" | docker login --username=$DOCKER_HUB_USERNAME --password-stdin && docker build -t $DOCKER_CODEGEN_CLI_IMAGE_NAME ./modules/openapi-generator-cli && if [ ! -z "$TRAVIS_TAG" ]; then docker tag $DOCKER_CODEGEN_CLI_IMAGE_NAME:latest $DOCKER_CODEGEN_CLI_IMAGE_NAME:$TRAVIS_TAG; fi && if [ ! -z "$TRAVIS_TAG" ] || [ "$TRAVIS_BRANCH" = "master" ]; then docker push $DOCKER_CODEGEN_CLI_IMAGE_NAME && echo "Pushed to $DOCKER_CODEGEN_CLI_IMAGE_NAME"; fi; fi # push a snapshot version to maven repo - if [ $SONATYPE_USERNAME ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_BRANCH" = "master" ]; then - mvn clean deploy --settings .travis/settings.xml; + mvn clean deploy --settings CI/settings.xml; echo "Finished mvn clean deploy for $TRAVIS_BRANCH"; fi; diff --git a/.travis/settings.xml b/.travis/settings.xml deleted file mode 100644 index 7fd9d3e70146..000000000000 --- a/.travis/settings.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - sonatype-nexus-snapshots - ${env.SONATYPE_USERNAME} - ${env.SONATYPE_PASSWORD} - - - - - - - diff --git a/CI/settings.xml b/CI/settings.xml new file mode 100644 index 000000000000..ca9d5bd69ebe --- /dev/null +++ b/CI/settings.xml @@ -0,0 +1,18 @@ + + + + + + + + + sonatype-nexus-snapshots + ${env.SONATYPE_USERNAME} + ${env.SONATYPE_PASSWORD} + + + + + + + diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 03182933c8ed..9f68e72f3fd3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -4083,6 +4083,7 @@ public List fromRequestBodyToFormParameters(RequestBody body, CodegenProperty codegenProperty = fromProperty("inner", inner); codegenParameter.items = codegenProperty; codegenParameter.baseType = codegenProperty.datatype; + codegenParameter.isPrimitiveType = false; codegenParameter.isContainer = true; codegenParameter.isListContainer = true; codegenParameter.description = s.getDescription(); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java index 01c66248d741..8425299a0c46 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java @@ -17,11 +17,17 @@ package org.openapitools.codegen.go; -import org.testng.Assert; -import org.testng.annotations.Test; - +import io.swagger.parser.OpenAPIParser; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.parser.core.models.ParseOptions; import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.CodegenOperation; +import org.openapitools.codegen.CodegenParameter; import org.openapitools.codegen.languages.GoClientCodegen; +import org.openapitools.codegen.languages.RubyClientCodegen; +import org.testng.Assert; +import org.testng.annotations.Test; public class GoClientCodegenTest { @@ -54,4 +60,16 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception { Assert.assertEquals(codegen.isHideGenerationTimestamp(), false); } + @Test(description = "test example value for body parameter") + public void bodyParameterTest() { + final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", null, new ParseOptions()).getOpenAPI(); + final GoClientCodegen codegen = new GoClientCodegen(); + final String path = "/fake"; + final Operation p = openAPI.getPaths().get(path).getGet(); + final CodegenOperation op = codegen.fromOperation(path, "post", p, openAPI.getComponents().getSchemas()); + Assert.assertEquals(op.formParams.size(), 2); + CodegenParameter bp = op.formParams.get(0); + Assert.assertFalse(bp.isPrimitiveType); + } + } diff --git a/samples/client/petstore/go/go-petstore/api_fake.go b/samples/client/petstore/go/go-petstore/api_fake.go index 0e2804da3abd..271a39f3613d 100644 --- a/samples/client/petstore/go/go-petstore/api_fake.go +++ b/samples/client/petstore/go/go-petstore/api_fake.go @@ -11,12 +11,12 @@ package petstore import ( "context" - "github.com/antihax/optional" "io/ioutil" "net/http" "net/url" - "os" "strings" + "github.com/antihax/optional" + "os" ) // Linger please @@ -26,7 +26,7 @@ var ( type FakeApiService service -/* +/* FakeApiService Test serialization of outer boolean types * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @@ -36,15 +36,15 @@ Test serialization of outer boolean types */ type FakeOuterBooleanSerializeOpts struct { - Body optional.Bool + Body optional.Bool } func (a *FakeApiService) FakeOuterBooleanSerialize(ctx context.Context, localVarOptionals *FakeOuterBooleanSerializeOpts) (bool, *http.Response, error) { var ( - localVarHttpMethod = strings.ToUpper("Post") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte localVarReturnValue bool ) @@ -95,26 +95,26 @@ func (a *FakeApiService) FakeOuterBooleanSerialize(ctx context.Context, localVar if localVarHttpResponse.StatusCode < 300 { // If we succeed, return the data, otherwise pass on to decode error. - err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err == nil { + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); + if err == nil { return localVarReturnValue, localVarHttpResponse, err } } if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 200 { var v bool - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err != nil { - newErr.error = err.Error() + 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 - } - newErr.model = v - return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, newErr } @@ -122,7 +122,7 @@ func (a *FakeApiService) FakeOuterBooleanSerialize(ctx context.Context, localVar return localVarReturnValue, localVarHttpResponse, nil } -/* +/* FakeApiService Test serialization of object with outer number type * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @@ -132,15 +132,15 @@ Test serialization of object with outer number type */ type FakeOuterCompositeSerializeOpts struct { - OuterComposite optional.Interface + OuterComposite optional.Interface } func (a *FakeApiService) FakeOuterCompositeSerialize(ctx context.Context, localVarOptionals *FakeOuterCompositeSerializeOpts) (OuterComposite, *http.Response, error) { var ( - localVarHttpMethod = strings.ToUpper("Post") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte localVarReturnValue OuterComposite ) @@ -195,26 +195,26 @@ func (a *FakeApiService) FakeOuterCompositeSerialize(ctx context.Context, localV if localVarHttpResponse.StatusCode < 300 { // If we succeed, return the data, otherwise pass on to decode error. - err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err == nil { + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); + if err == nil { return localVarReturnValue, localVarHttpResponse, err } } if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 200 { var v OuterComposite - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err != nil { - newErr.error = err.Error() + 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 - } - newErr.model = v - return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, newErr } @@ -222,7 +222,7 @@ func (a *FakeApiService) FakeOuterCompositeSerialize(ctx context.Context, localV return localVarReturnValue, localVarHttpResponse, nil } -/* +/* FakeApiService Test serialization of outer number types * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @@ -232,15 +232,15 @@ Test serialization of outer number types */ type FakeOuterNumberSerializeOpts struct { - Body optional.Float32 + Body optional.Float32 } func (a *FakeApiService) FakeOuterNumberSerialize(ctx context.Context, localVarOptionals *FakeOuterNumberSerializeOpts) (float32, *http.Response, error) { var ( - localVarHttpMethod = strings.ToUpper("Post") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte localVarReturnValue float32 ) @@ -291,26 +291,26 @@ func (a *FakeApiService) FakeOuterNumberSerialize(ctx context.Context, localVarO if localVarHttpResponse.StatusCode < 300 { // If we succeed, return the data, otherwise pass on to decode error. - err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err == nil { + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); + if err == nil { return localVarReturnValue, localVarHttpResponse, err } } if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 200 { var v float32 - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err != nil { - newErr.error = err.Error() + 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 - } - newErr.model = v - return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, newErr } @@ -318,7 +318,7 @@ func (a *FakeApiService) FakeOuterNumberSerialize(ctx context.Context, localVarO return localVarReturnValue, localVarHttpResponse, nil } -/* +/* FakeApiService Test serialization of outer string types * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @@ -328,15 +328,15 @@ Test serialization of outer string types */ type FakeOuterStringSerializeOpts struct { - Body optional.String + Body optional.String } func (a *FakeApiService) FakeOuterStringSerialize(ctx context.Context, localVarOptionals *FakeOuterStringSerializeOpts) (string, *http.Response, error) { var ( - localVarHttpMethod = strings.ToUpper("Post") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte localVarReturnValue string ) @@ -387,26 +387,26 @@ func (a *FakeApiService) FakeOuterStringSerialize(ctx context.Context, localVarO if localVarHttpResponse.StatusCode < 300 { // If we succeed, return the data, otherwise pass on to decode error. - err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err == nil { + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); + if err == nil { return localVarReturnValue, localVarHttpResponse, err } } if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 200 { var v string - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err != nil { - newErr.error = err.Error() + 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 - } - newErr.model = v - return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, newErr } @@ -414,7 +414,7 @@ func (a *FakeApiService) FakeOuterStringSerialize(ctx context.Context, localVarO return localVarReturnValue, localVarHttpResponse, nil } -/* +/* FakeApiService * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). * @param query @@ -473,7 +473,7 @@ func (a *FakeApiService) TestBodyWithQueryParams(ctx context.Context, query stri if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } return localVarHttpResponse, newErr @@ -482,7 +482,7 @@ func (a *FakeApiService) TestBodyWithQueryParams(ctx context.Context, query stri return localVarHttpResponse, nil } -/* +/* FakeApiService To test \"client\" model To test \"client\" model * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @@ -491,10 +491,10 @@ To test \"client\" model */ func (a *FakeApiService) TestClientModel(ctx context.Context, client Client) (Client, *http.Response, error) { var ( - localVarHttpMethod = strings.ToUpper("Patch") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte + localVarHttpMethod = strings.ToUpper("Patch") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte localVarReturnValue Client ) @@ -542,26 +542,26 @@ func (a *FakeApiService) TestClientModel(ctx context.Context, client Client) (Cl if localVarHttpResponse.StatusCode < 300 { // If we succeed, return the data, otherwise pass on to decode error. - err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err == nil { + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); + if err == nil { return localVarReturnValue, localVarHttpResponse, err } } if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 200 { var v Client - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) - if err != nil { - newErr.error = err.Error() + 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 - } - newErr.model = v - return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, newErr } @@ -569,9 +569,9 @@ func (a *FakeApiService) TestClientModel(ctx context.Context, client Client) (Cl return localVarReturnValue, localVarHttpResponse, nil } -/* -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 @@ -591,16 +591,16 @@ 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 - DateTime optional.Time - Password optional.String - Callback 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 } func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number float32, double float64, patternWithoutDelimiter string, byte_ string, localVarOptionals *TestEndpointParametersOpts) (*http.Response, error) { @@ -671,7 +671,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 { @@ -710,7 +710,7 @@ func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number floa if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } return localVarHttpResponse, newErr @@ -719,7 +719,7 @@ func (a *FakeApiService) TestEndpointParameters(ctx context.Context, number floa return localVarHttpResponse, nil } -/* +/* FakeApiService To test enum parameters To test enum parameters * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @@ -730,19 +730,19 @@ To test enum parameters * @param "EnumQueryString" (optional.String) - Query parameter enum test (string) * @param "EnumQueryInteger" (optional.Int32) - Query parameter enum test (double) * @param "EnumQueryDouble" (optional.Float64) - Query parameter enum test (double) - * @param "EnumFormStringArray" (optional.[]string) - Form parameter enum test (string array) + * @param "EnumFormStringArray" (optional.Interface of []string) - Form parameter enum test (string array) * @param "EnumFormString" (optional.String) - Form parameter enum test (string) */ 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 + EnumHeaderStringArray optional.Interface + 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) { @@ -819,7 +819,7 @@ func (a *FakeApiService) TestEnumParameters(ctx context.Context, localVarOptiona if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } return localVarHttpResponse, newErr @@ -828,7 +828,7 @@ func (a *FakeApiService) TestEnumParameters(ctx context.Context, localVarOptiona return localVarHttpResponse, nil } -/* +/* FakeApiService test inline additionalProperties * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). * @param requestBody request body @@ -885,7 +885,7 @@ func (a *FakeApiService) TestInlineAdditionalProperties(ctx context.Context, req if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } return localVarHttpResponse, newErr @@ -894,7 +894,7 @@ func (a *FakeApiService) TestInlineAdditionalProperties(ctx context.Context, req return localVarHttpResponse, nil } -/* +/* FakeApiService test json serialization of form data * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). * @param param field1 @@ -952,7 +952,7 @@ func (a *FakeApiService) TestJsonFormData(ctx context.Context, param string, par if localVarHttpResponse.StatusCode >= 300 { newErr := GenericOpenAPIError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } return localVarHttpResponse, newErr diff --git a/samples/client/petstore/go/go-petstore/docs/FakeApi.md b/samples/client/petstore/go/go-petstore/docs/FakeApi.md index 783a26a42b34..5cc42304f3ee 100644 --- a/samples/client/petstore/go/go-petstore/docs/FakeApi.md +++ b/samples/client/petstore/go/go-petstore/docs/FakeApi.md @@ -287,7 +287,7 @@ Name | Type | Description | Notes **enumQueryString** | **optional.String**| Query parameter enum test (string) | [default to -efg] **enumQueryInteger** | **optional.Int32**| Query parameter enum test (double) | **enumQueryDouble** | **optional.Float64**| Query parameter enum test (double) | - **enumFormStringArray** | **optional.[]string**| Form parameter enum test (string array) | [default to $] + **enumFormStringArray** | [**optional.Interface of []string**](string.md)| Form parameter enum test (string array) | [default to $] **enumFormString** | **optional.String**| Form parameter enum test (string) | [default to -efg] ### Return type