diff --git a/bin/openapi3/go-experimental-petstore.sh b/bin/openapi3/go-experimental-petstore.sh index db24ff5d6c8..46c7841a280 100755 --- a/bin/openapi3/go-experimental-petstore.sh +++ b/bin/openapi3/go-experimental-petstore.sh @@ -34,6 +34,8 @@ rm -rf $STUB_DIR # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/$GENERATOR -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstore $@" +ags="generate -t modules/openapi-generator/src/main/resources/$GENERATOR -i $SPEC -g $GENERATOR -o $STUB_DIR" +ags="$ags --additional-properties enumClassPrefix=true,packageName=petstore" +ags="$ags $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/go-petstore.sh b/bin/openapi3/go-petstore.sh index ad921deae9c..f67ecfbbb6d 100755 --- a/bin/openapi3/go-petstore.sh +++ b/bin/openapi3/go-petstore.sh @@ -34,6 +34,8 @@ rm -rf $STUB_DIR # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/go -i $SPEC -g $GENERATOR -o $STUB_DIR --additional-properties packageName=petstore $@" +ags="generate -t modules/openapi-generator/src/main/resources/go -i $SPEC -g $GENERATOR -o $STUB_DIR" +ags="$ags --additional-properties enumClassPrefix=true,packageName=petstore" +ags="$ags $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/utils/ensure-up-to-date b/bin/utils/ensure-up-to-date index 4bb9ee79b4f..b2a8c19ab4a 100755 --- a/bin/utils/ensure-up-to-date +++ b/bin/utils/ensure-up-to-date @@ -66,6 +66,7 @@ declare -a samples=( "${root}/bin/csharp-netcore-petstore-all.sh" "${root}/bin/elixir-petstore.sh" "${root}/bin/openapi3/go-petstore.sh" +"${root}/bin/openapi3/go-experimental-petstore.sh" "${root}/bin/go-experimental-petstore.sh" "${root}/bin/go-petstore.sh" "${root}/bin/go-petstore-withxml.sh" diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java index 37a1230f98c..36557914bb1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java @@ -24,8 +24,16 @@ import java.util.*; @JsonIgnoreProperties({"parentModel", "interfaceModels"}) public class CodegenModel implements IJsonSchemaValidationProperties { + // The parent model name from the schemas. The parent is determined by inspecting the allOf, anyOf and + // oneOf attributes in the OAS. First codegen inspects 'allOf', then 'anyOf', then 'oneOf'. + // If there are multiple object references in the attribute ('allOf', 'anyOf', 'oneOf'), and one of the + // object is a discriminator, that object is set as the parent. If no discriminator is specified, + // codegen returns the first one in the list, i.e. there is no obvious parent in the OpenAPI specification. + // When possible, the mustache templates should use 'allParents' to handle multiple parents. public String parent, parentSchema; public List interfaces; + // The list of parent model name from the schemas. In order of preference, the parent is obtained + // from the 'allOf' attribute, then 'anyOf', and finally 'oneOf'. public List allParents; // References to parent and interface CodegenModels. Only set when code generator supports inheritance. diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java index da32ae09c53..d2f0a5ee3b1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java @@ -70,8 +70,8 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti public boolean isBinary; public boolean isFile; public boolean isBoolean; - public boolean isDate; - public boolean isDateTime; + public boolean isDate; // full-date notation as defined by RFC 3339, section 5.6, for example, 2017-07-21 + public boolean isDateTime; // the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z public boolean isUuid; public boolean isUri; public boolean isEmail; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java index 29e7f558602..5edabbefbd1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java @@ -71,7 +71,6 @@ public class GoClientExperimentalCodegen extends GoClientCodegen { @Override public Map postProcessModels(Map objs) { - objs = super.postProcessModels(objs); List> models = (List>) objs.get("models"); for (Map m : models) { @@ -83,16 +82,27 @@ public class GoClientExperimentalCodegen extends GoClientCodegen { } for (CodegenProperty param : model.vars) { - if (!param.isNullable) { + if (!param.isNullable || param.isMapContainer || param.isListContainer) { continue; } - - param.dataType = "Nullable" + Character.toUpperCase(param.dataType.charAt(0)) + if (param.isDateTime) { + // Note this could have been done by adding the following line in processOpts(), + // however, we only want to represent the DateTime object as NullableTime if + // it's marked as nullable in the spec. + // typeMapping.put("DateTime", "NullableTime"); + param.dataType = "NullableTime"; + } else { + param.dataType = "Nullable" + Character.toUpperCase(param.dataType.charAt(0)) + param.dataType.substring(1); + } } } } + // The superclass determines the list of required golang imports. The actual list of imports + // depends on which types are used, which is done in the code above. So super.postProcessModels + // must be invoked at the end of this method. + objs = super.postProcessModels(objs); return objs; } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index 08c878b21c6..cf2ca082caa 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -921,7 +921,8 @@ public class ModelUtils { } /** - * Get the the parent model name from the schemas (allOf, anyOf, oneOf) + * Get the parent model name from the schemas (allOf, anyOf, oneOf). + * If there are multiple parents, return the first one. * * @param composedSchema schema (alias or direct reference) * @param allSchemas all schemas @@ -965,6 +966,14 @@ public class ModelUtils { return null; } + /** + * Get the list of parent model names from the schemas (allOf, anyOf, oneOf). + * + * @param composedSchema schema (alias or direct reference) + * @param allSchemas all schemas + * @param includeAncestors if true, include the indirect ancestors in the return value. If false, return the direct parents. + * @return the name of the parent model + */ public static List getAllParentsName(ComposedSchema composedSchema, Map allSchemas, boolean includeAncestors) { List interfaces = getInterfaces(composedSchema); List names = new ArrayList(); diff --git a/modules/openapi-generator/src/main/resources/go-experimental/README.mustache b/modules/openapi-generator/src/main/resources/go-experimental/README.mustache index cdb72d59099..777abc5d06e 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/README.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/README.mustache @@ -25,7 +25,6 @@ Install the following dependencies: go get github.com/stretchr/testify/assert go get golang.org/x/oauth2 go get golang.org/x/net/context -go get github.com/antihax/optional ``` Put the package under your project folder and add the following in import: diff --git a/modules/openapi-generator/src/main/resources/go-experimental/go.mod.mustache b/modules/openapi-generator/src/main/resources/go-experimental/go.mod.mustache index d7aeada7577..3b7d202ac4f 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/go.mod.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/go.mod.mustache @@ -3,6 +3,5 @@ module {{gitHost}}/{{gitUserId}}/{{gitRepoId}}{{#isGoSubmodule}}/{{packageName}} go 1.13 require ( - github.com/antihax/optional v1.0.0 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 ) diff --git a/modules/openapi-generator/src/main/resources/go/api.mustache b/modules/openapi-generator/src/main/resources/go/api.mustache index 503e3fcac4c..a59dfd8a46e 100644 --- a/modules/openapi-generator/src/main/resources/go/api.mustache +++ b/modules/openapi-generator/src/main/resources/go/api.mustache @@ -135,14 +135,16 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx _context.Context{{#hasParams {{#queryParams}} {{#required}} {{#isCollectionFormatMulti}} - t:={{paramName}} - if reflect.TypeOf(t).Kind() == reflect.Slice { - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("{{baseName}}", parameterToString(s.Index(i), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) + { + t:={{paramName}} + if reflect.TypeOf(t).Kind() == reflect.Slice { + s := reflect.ValueOf(t) + for i := 0; i < s.Len(); i++ { + localVarQueryParams.Add("{{baseName}}", parameterToString(s.Index(i), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) + } + } else { + localVarQueryParams.Add("{{baseName}}", parameterToString(t, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) } - } else { - localVarQueryParams.Add("{{baseName}}", parameterToString(t, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")) } {{/isCollectionFormatMulti}} {{^isCollectionFormatMulti}} diff --git a/pom.xml b/pom.xml index 5f3b845c7ce..c4fb85ca131 100644 --- a/pom.xml +++ b/pom.xml @@ -1087,6 +1087,8 @@ samples/client/petstore/go samples/client/petstore/go-experimental + samples/openapi3/client/petstore/go-experimental + samples/openapi3/client/petstore/go samples/client/petstore/scala-httpclient diff --git a/samples/client/petstore/go-experimental/go-petstore/README.md b/samples/client/petstore/go-experimental/go-petstore/README.md index 9ce303bc885..ad2c0aa80de 100644 --- a/samples/client/petstore/go-experimental/go-petstore/README.md +++ b/samples/client/petstore/go-experimental/go-petstore/README.md @@ -17,7 +17,6 @@ Install the following dependencies: go get github.com/stretchr/testify/assert go get golang.org/x/oauth2 go get golang.org/x/net/context -go get github.com/antihax/optional ``` Put the package under your project folder and add the following in import: diff --git a/samples/client/petstore/go-experimental/go-petstore/go.mod b/samples/client/petstore/go-experimental/go-petstore/go.mod index b80383b722c..f9811556cc5 100644 --- a/samples/client/petstore/go-experimental/go-petstore/go.mod +++ b/samples/client/petstore/go-experimental/go-petstore/go.mod @@ -3,6 +3,5 @@ module github.com/GIT_USER_ID/GIT_REPO_ID go 1.13 require ( - github.com/antihax/optional v1.0.0 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 ) diff --git a/samples/client/petstore/go-experimental/pet_api_test.go b/samples/client/petstore/go-experimental/pet_api_test.go index 6cc33a62e1c..57afd2923c5 100644 --- a/samples/client/petstore/go-experimental/pet_api_test.go +++ b/samples/client/petstore/go-experimental/pet_api_test.go @@ -139,7 +139,10 @@ func TestFindPetsByStatus(t *testing.T) { } func TestUploadFile(t *testing.T) { - file, _ := os.Open("../python/testfiles/foo.png") + file, err1 := os.Open("testfiles/foo.png") + if err1 != nil { + t.Fatalf("Error opening file: %v", err1) + } _, r, err := client.PetApi.UploadFile(context.Background(), 12830).AdditionalMetadata("golang").File(file).Execute() @@ -154,7 +157,10 @@ func TestUploadFile(t *testing.T) { func TestUploadFileRequired(t *testing.T) { return // remove when server supports this endpoint - file, _ := os.Open("../python/testfiles/foo.png") + file, err1 := os.Open("testfiles/foo.png") + if err1 != nil { + t.Fatalf("Error opening file: %v", err1) + } _, r, err := client.PetApi.UploadFileWithRequiredFile(context.Background(), 12830).RequiredFile(file).AdditionalMetadata("golang").Execute() diff --git a/samples/client/petstore/go-experimental/pom.xml b/samples/client/petstore/go-experimental/pom.xml index 91e3da8c34b..9c62bbb9554 100644 --- a/samples/client/petstore/go-experimental/pom.xml +++ b/samples/client/petstore/go-experimental/pom.xml @@ -68,20 +68,6 @@ - - go-get-optional - pre-integration-test - - exec - - - go - - get - github.com/antihax/optional - - - go-test integration-test diff --git a/samples/client/petstore/go-experimental/testfiles/foo.png b/samples/client/petstore/go-experimental/testfiles/foo.png new file mode 100644 index 00000000000..a9b12cf5927 Binary files /dev/null and b/samples/client/petstore/go-experimental/testfiles/foo.png differ 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 264c49951e3..bad36447bd8 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api_fake.go +++ b/samples/client/petstore/go/go-petstore-withXml/api_fake.go @@ -1217,14 +1217,16 @@ func (a *FakeApiService) TestQueryParameterCollectionFormat(ctx _context.Context localVarQueryParams.Add("ioutil", parameterToString(ioutil, "csv")) localVarQueryParams.Add("http", parameterToString(http, "space")) localVarQueryParams.Add("url", parameterToString(url, "csv")) - t:=context - if reflect.TypeOf(t).Kind() == reflect.Slice { - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("context", parameterToString(s.Index(i), "multi")) + { + t:=context + if reflect.TypeOf(t).Kind() == reflect.Slice { + s := reflect.ValueOf(t) + for i := 0; i < s.Len(); i++ { + localVarQueryParams.Add("context", parameterToString(s.Index(i), "multi")) + } + } else { + localVarQueryParams.Add("context", parameterToString(t, "multi")) } - } else { - localVarQueryParams.Add("context", parameterToString(t, "multi")) } // to determine the Content-Type header localVarHTTPContentTypes := []string{} diff --git a/samples/client/petstore/go/go-petstore/api_fake.go b/samples/client/petstore/go/go-petstore/api_fake.go index 9c23b7d5023..61f9d2ed9ec 100644 --- a/samples/client/petstore/go/go-petstore/api_fake.go +++ b/samples/client/petstore/go/go-petstore/api_fake.go @@ -1216,14 +1216,16 @@ func (a *FakeApiService) TestQueryParameterCollectionFormat(ctx _context.Context localVarQueryParams.Add("ioutil", parameterToString(ioutil, "csv")) localVarQueryParams.Add("http", parameterToString(http, "space")) localVarQueryParams.Add("url", parameterToString(url, "csv")) - t:=context - if reflect.TypeOf(t).Kind() == reflect.Slice { - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("context", parameterToString(s.Index(i), "multi")) + { + t:=context + if reflect.TypeOf(t).Kind() == reflect.Slice { + s := reflect.ValueOf(t) + for i := 0; i < s.Len(); i++ { + localVarQueryParams.Add("context", parameterToString(s.Index(i), "multi")) + } + } else { + localVarQueryParams.Add("context", parameterToString(t, "multi")) } - } else { - localVarQueryParams.Add("context", parameterToString(t, "multi")) } // to determine the Content-Type header localVarHTTPContentTypes := []string{} diff --git a/samples/client/petstore/go/pet_api_test.go b/samples/client/petstore/go/pet_api_test.go index 969fab1f667..cda4f457855 100644 --- a/samples/client/petstore/go/pet_api_test.go +++ b/samples/client/petstore/go/pet_api_test.go @@ -142,7 +142,10 @@ func TestFindPetsByStatus(t *testing.T) { } func TestUploadFile(t *testing.T) { - file, _ := os.Open("../python/testfiles/foo.png") + file, err1 := os.Open("testfiles/foo.png") + if err1 != nil { + t.Fatalf("Error opening file: %v", err1) + } _, r, err := client.PetApi.UploadFile(context.Background(), 12830, &sw.UploadFileOpts{ AdditionalMetadata: optional.NewString("golang"), @@ -160,7 +163,10 @@ func TestUploadFile(t *testing.T) { func TestUploadFileRequired(t *testing.T) { return // remove when server supports this endpoint - file, _ := os.Open("../python/testfiles/foo.png") + file, err1 := os.Open("testfiles/foo.png") + if err1 != nil { + t.Fatalf("Error opening file: %v", err1) + } _, r, err := client.PetApi.UploadFileWithRequiredFile(context.Background(), 12830, file, diff --git a/samples/client/petstore/go/testfiles/foo.png b/samples/client/petstore/go/testfiles/foo.png new file mode 100644 index 00000000000..a9b12cf5927 Binary files /dev/null and b/samples/client/petstore/go/testfiles/foo.png differ diff --git a/samples/openapi3/client/petstore/go-experimental/auth_test.go b/samples/openapi3/client/petstore/go-experimental/auth_test.go new file mode 100644 index 00000000000..aec544c2f26 --- /dev/null +++ b/samples/openapi3/client/petstore/go-experimental/auth_test.go @@ -0,0 +1,259 @@ +package main + +import ( + "context" + "net/http" + "net/http/httputil" + "strings" + "testing" + "time" + + "golang.org/x/oauth2" + + sw "./go-petstore" +) + +func TestOAuth2(t *testing.T) { + // Setup some fake oauth2 configuration + cfg := &oauth2.Config{ + ClientID: "1234567", + ClientSecret: "SuperSecret", + Endpoint: oauth2.Endpoint{ + AuthURL: "https://devnull", + TokenURL: "https://devnull", + }, + RedirectURL: "https://devnull", + } + + // and a fake token + tok := oauth2.Token{ + AccessToken: "FAKE", + RefreshToken: "So Fake", + Expiry: time.Now().Add(time.Hour * 100000), + TokenType: "Bearer", + } + + // then a fake tokenSource + tokenSource := cfg.TokenSource(createContext(nil), &tok) + auth := context.WithValue(context.Background(), sw.ContextOAuth2, tokenSource) + + newPet := (sw.Pet{Id: sw.PtrInt64(12992), Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"), + Tags: &[]sw.Tag{sw.Tag{Id: sw.PtrInt64(1), Name: sw.PtrString("tag2")}}}) + + r, err := client.PetApi.AddPet(context.Background()).Pet(newPet).Execute() + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + r, err = client.PetApi.DeletePet(auth, 12992).Execute() + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + reqb, _ := httputil.DumpRequest(r.Request, true) + + if !strings.Contains((string)(reqb), "Authorization: Bearer FAKE") { + t.Errorf("OAuth2 Authentication is missing") + } +} + +func TestBasicAuth(t *testing.T) { + + auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{ + UserName: "fakeUser", + Password: "f4k3p455", + }) + + newPet := (sw.Pet{Id: sw.PtrInt64(12992), Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"), + Tags: &[]sw.Tag{sw.Tag{Id: sw.PtrInt64(1), Name: sw.PtrString("tag2")}}}) + + r, err := client.PetApi.AddPet(auth).Pet(newPet).Execute() + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + r, err = client.PetApi.DeletePet(auth, 12992).Execute() + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Authorization: Basic ZmFrZVVzZXI6ZjRrM3A0NTU") { + t.Errorf("Basic Authentication is missing") + } +} + +func TestAccessToken(t *testing.T) { + auth := context.WithValue(context.Background(), sw.ContextAccessToken, "TESTFAKEACCESSTOKENISFAKE") + + newPet := (sw.Pet{Id: sw.PtrInt64(12992), Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"), + Tags: &[]sw.Tag{sw.Tag{Id: sw.PtrInt64(1), Name: sw.PtrString("tag2")}}}) + + r, err := client.PetApi.AddPet(nil).Pet(newPet).Execute() + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + r, err = client.PetApi.DeletePet(auth, 12992).Execute() + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Authorization: Bearer TESTFAKEACCESSTOKENISFAKE") { + t.Errorf("AccessToken Authentication is missing") + } +} + +func TestAPIKeyNoPrefix(t *testing.T) { + auth := context.WithValue(context.Background(), sw.ContextAPIKeys, map[string]sw.APIKey{"api_key": sw.APIKey{Key: "TEST123"}}) + + newPet := (sw.Pet{Id: sw.PtrInt64(12992), Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"), + Tags: &[]sw.Tag{sw.Tag{Id: sw.PtrInt64(1), Name: sw.PtrString("tag2")}}}) + + r, err := client.PetApi.AddPet(context.Background()).Pet(newPet).Execute() + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + _, r, err = client.PetApi.GetPetById(auth, 12992).Execute() + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Api_key: TEST123") { + t.Errorf("APIKey Authentication is missing") + } + + r, err = client.PetApi.DeletePet(auth, 12992).Execute() + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestAPIKeyWithPrefix(t *testing.T) { + auth := context.WithValue(context.Background(), sw.ContextAPIKeys, map[string]sw.APIKey{"api_key": sw.APIKey{Key: "TEST123", Prefix: "Bearer"}}) + + newPet := (sw.Pet{Id: sw.PtrInt64(12992), Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"), + Tags: &[]sw.Tag{sw.Tag{Id: sw.PtrInt64(1), Name: sw.PtrString("tag2")}}}) + + r, err := client.PetApi.AddPet(nil).Pet(newPet).Execute() + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + _, r, err = client.PetApi.GetPetById(auth, 12992).Execute() + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Api_key: Bearer TEST123") { + t.Errorf("APIKey Authentication is missing") + } + + r, err = client.PetApi.DeletePet(auth, 12992).Execute() + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestDefaultHeader(t *testing.T) { + newPet := (sw.Pet{Id: sw.PtrInt64(12992), Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"), + Tags: &[]sw.Tag{sw.Tag{Id: sw.PtrInt64(1), Name: sw.PtrString("tag2")}}}) + + r, err := client.PetApi.AddPet(context.Background()).Pet(newPet).Execute() + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + r, err = client.PetApi.DeletePet(context.Background(), 12992).Execute() + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Testheader: testvalue") { + t.Errorf("Default Header is missing") + } +} + +func TestHostOverride(t *testing.T) { + _, r, err := client.PetApi.FindPetsByStatus(context.Background()).Status(nil).Execute() + + if err != nil { + t.Fatalf("Error while finding pets by status: %v", err) + } + + if r.Request.URL.Host != testHost { + t.Errorf("Request Host is %v, expected %v", r.Request.Host, testHost) + } +} + +func TestSchemeOverride(t *testing.T) { + _, r, err := client.PetApi.FindPetsByStatus(context.Background()).Status(nil).Execute() + + if err != nil { + t.Fatalf("Error while finding pets by status: %v", err) + } + + if r.Request.URL.Scheme != testScheme { + t.Errorf("Request Scheme is %v, expected %v", r.Request.URL.Scheme, testScheme) + } +} + +// Add custom clients to the context. +func createContext(httpClient *http.Client) context.Context { + parent := oauth2.NoContext + ctx := context.WithValue(parent, oauth2.HTTPClient, httpClient) + return ctx +} diff --git a/samples/openapi3/client/petstore/go-experimental/fake_api_test.go b/samples/openapi3/client/petstore/go-experimental/fake_api_test.go new file mode 100644 index 00000000000..97910bf3cf7 --- /dev/null +++ b/samples/openapi3/client/petstore/go-experimental/fake_api_test.go @@ -0,0 +1,28 @@ +package main + +import ( + "context" + "testing" + + sw "./go-petstore" +) + +// TestPutBodyWithFileSchema ensures a model with the name 'File' +// gets converted properly to the petstore.File struct vs. *os.File +// as specified in typeMapping for 'File'. +func TestPutBodyWithFileSchema(t *testing.T) { + return // early return to test compilation + + schema := sw.FileSchemaTestClass{ + File: &sw.File{SourceURI: sw.PtrString("https://example.com/image.png")}, + Files: &[]sw.File{{SourceURI: sw.PtrString("https://example.com/image.png")}}} + + r, err := client.FakeApi.TestBodyWithFileSchema(context.Background()).FileSchemaTestClass(schema).Execute() + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/README.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/README.md index d030bad9835..9c0050a2352 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/README.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/README.md @@ -1,4 +1,4 @@ -# Go API client for openapi +# Go API client for petstore This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ @@ -17,13 +17,12 @@ Install the following dependencies: go get github.com/stretchr/testify/assert go get golang.org/x/oauth2 go get golang.org/x/net/context -go get github.com/antihax/optional ``` Put the package under your project folder and add the following in import: ```golang -import sw "./openapi" +import sw "./petstore" ``` ## Configuration of Server URL diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_another_fake.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_another_fake.go index 16dc072e967..c9d4a11585e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_another_fake.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_another_fake.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( _context "context" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_default.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_default.go index 6fce4e6b2eb..68147dc1782 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_default.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_default.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( _context "context" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_fake.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_fake.go index 11699dfe9af..a0fd91dcc8d 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_fake.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_fake.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( _context "context" @@ -1767,26 +1767,30 @@ func (r apiTestQueryParameterCollectionFormatRequest) Execute() (*_nethttp.Respo return nil, reportError("context is required and must be specified") } - t := *r.pipe - if reflect.TypeOf(t).Kind() == reflect.Slice { - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("pipe", parameterToString(s.Index(i), "multi")) + { + t := *r.pipe + if reflect.TypeOf(t).Kind() == reflect.Slice { + s := reflect.ValueOf(t) + for i := 0; i < s.Len(); i++ { + localVarQueryParams.Add("pipe", parameterToString(s.Index(i), "multi")) + } + } else { + localVarQueryParams.Add("pipe", parameterToString(t, "multi")) } - } else { - localVarQueryParams.Add("pipe", parameterToString(t, "multi")) } localVarQueryParams.Add("ioutil", parameterToString(*r.ioutil, "csv")) localVarQueryParams.Add("http", parameterToString(*r.http, "space")) localVarQueryParams.Add("url", parameterToString(*r.url, "csv")) - t := *r.context - if reflect.TypeOf(t).Kind() == reflect.Slice { - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("context", parameterToString(s.Index(i), "multi")) + { + t := *r.context + if reflect.TypeOf(t).Kind() == reflect.Slice { + s := reflect.ValueOf(t) + for i := 0; i < s.Len(); i++ { + localVarQueryParams.Add("context", parameterToString(s.Index(i), "multi")) + } + } else { + localVarQueryParams.Add("context", parameterToString(t, "multi")) } - } else { - localVarQueryParams.Add("context", parameterToString(t, "multi")) } // to determine the Content-Type header localVarHTTPContentTypes := []string{} diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_fake_classname_tags123.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_fake_classname_tags123.go index d305d41b1e4..aa8378a85e4 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_fake_classname_tags123.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_fake_classname_tags123.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( _context "context" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_pet.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_pet.go index d3043440519..664c9f0df4c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_pet.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_pet.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( _context "context" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_store.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_store.go index 3e82fd51a70..3b29aa69730 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_store.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_store.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( _context "context" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_user.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_user.go index 318759017aa..e877bf7d265 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api_user.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api_user.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( _context "context" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/client.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/client.go index 6b2ddc386d5..01ee73b79ec 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/client.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/client.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/configuration.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/configuration.go index 58f47a49687..a6bbfbeff96 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/configuration.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/configuration.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "context" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md index 5b8efc3fd89..0aed469d7c7 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md @@ -9,12 +9,12 @@ Name | Type | Description | Notes **BooleanProp** | Pointer to **NullableBool** | | [optional] **StringProp** | Pointer to **NullableString** | | [optional] **DateProp** | Pointer to **NullableString** | | [optional] -**DatetimeProp** | Pointer to [**NullableTime.Time**](time.Time.md) | | [optional] -**ArrayNullableProp** | Pointer to [**Nullable[]map[string]interface{}**](map[string]interface{}.md) | | [optional] -**ArrayAndItemsNullableProp** | Pointer to [**Nullable[]map[string]interface{}**](map[string]interface{}.md) | | [optional] +**DatetimeProp** | Pointer to [**NullableTime**](time.Time.md) | | [optional] +**ArrayNullableProp** | Pointer to [**[]map[string]interface{}**](map[string]interface{}.md) | | [optional] +**ArrayAndItemsNullableProp** | Pointer to [**[]map[string]interface{}**](map[string]interface{}.md) | | [optional] **ArrayItemsNullable** | Pointer to [**[]map[string]interface{}**](map[string]interface{}.md) | | [optional] -**ObjectNullableProp** | Pointer to [**NullableMap[string]map[string]interface{}**](map[string]interface{}.md) | | [optional] -**ObjectAndItemsNullableProp** | Pointer to [**NullableMap[string]map[string]interface{}**](map[string]interface{}.md) | | [optional] +**ObjectNullableProp** | Pointer to [**map[string]map[string]interface{}**](map[string]interface{}.md) | | [optional] +**ObjectAndItemsNullableProp** | Pointer to [**map[string]map[string]interface{}**](map[string]interface{}.md) | | [optional] **ObjectItemsNullable** | Pointer to [**map[string]map[string]interface{}**](map[string]interface{}.md) | | [optional] ## Methods @@ -181,13 +181,13 @@ when serializing to JSON (pass true as argument to set this, false to unset) The DateProp value is set to nil even if false is passed ### GetDatetimeProp -`func (o *NullableClass) GetDatetimeProp() NullableTime.Time` +`func (o *NullableClass) GetDatetimeProp() NullableTime` GetDatetimeProp returns the DatetimeProp field if non-nil, zero value otherwise. ### GetDatetimePropOk -`func (o *NullableClass) GetDatetimePropOk() (NullableTime.Time, bool)` +`func (o *NullableClass) GetDatetimePropOk() (NullableTime, bool)` GetDatetimePropOk returns a tuple with the DatetimeProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. @@ -200,9 +200,9 @@ HasDatetimeProp returns a boolean if a field has been set. ### SetDatetimeProp -`func (o *NullableClass) SetDatetimeProp(v NullableTime.Time)` +`func (o *NullableClass) SetDatetimeProp(v NullableTime)` -SetDatetimeProp gets a reference to the given NullableTime.Time and assigns it to the DatetimeProp field. +SetDatetimeProp gets a reference to the given NullableTime and assigns it to the DatetimeProp field. ### SetDatetimePropExplicitNull @@ -213,13 +213,13 @@ when serializing to JSON (pass true as argument to set this, false to unset) The DatetimeProp value is set to nil even if false is passed ### GetArrayNullableProp -`func (o *NullableClass) GetArrayNullableProp() Nullable[]map[string]interface{}` +`func (o *NullableClass) GetArrayNullableProp() []map[string]interface{}` GetArrayNullableProp returns the ArrayNullableProp field if non-nil, zero value otherwise. ### GetArrayNullablePropOk -`func (o *NullableClass) GetArrayNullablePropOk() (Nullable[]map[string]interface{}, bool)` +`func (o *NullableClass) GetArrayNullablePropOk() ([]map[string]interface{}, bool)` GetArrayNullablePropOk returns a tuple with the ArrayNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. @@ -232,9 +232,9 @@ HasArrayNullableProp returns a boolean if a field has been set. ### SetArrayNullableProp -`func (o *NullableClass) SetArrayNullableProp(v Nullable[]map[string]interface{})` +`func (o *NullableClass) SetArrayNullableProp(v []map[string]interface{})` -SetArrayNullableProp gets a reference to the given Nullable[]map[string]interface{} and assigns it to the ArrayNullableProp field. +SetArrayNullableProp gets a reference to the given []map[string]interface{} and assigns it to the ArrayNullableProp field. ### SetArrayNullablePropExplicitNull @@ -245,13 +245,13 @@ when serializing to JSON (pass true as argument to set this, false to unset) The ArrayNullableProp value is set to nil even if false is passed ### GetArrayAndItemsNullableProp -`func (o *NullableClass) GetArrayAndItemsNullableProp() Nullable[]map[string]interface{}` +`func (o *NullableClass) GetArrayAndItemsNullableProp() []map[string]interface{}` GetArrayAndItemsNullableProp returns the ArrayAndItemsNullableProp field if non-nil, zero value otherwise. ### GetArrayAndItemsNullablePropOk -`func (o *NullableClass) GetArrayAndItemsNullablePropOk() (Nullable[]map[string]interface{}, bool)` +`func (o *NullableClass) GetArrayAndItemsNullablePropOk() ([]map[string]interface{}, bool)` GetArrayAndItemsNullablePropOk returns a tuple with the ArrayAndItemsNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. @@ -264,9 +264,9 @@ HasArrayAndItemsNullableProp returns a boolean if a field has been set. ### SetArrayAndItemsNullableProp -`func (o *NullableClass) SetArrayAndItemsNullableProp(v Nullable[]map[string]interface{})` +`func (o *NullableClass) SetArrayAndItemsNullableProp(v []map[string]interface{})` -SetArrayAndItemsNullableProp gets a reference to the given Nullable[]map[string]interface{} and assigns it to the ArrayAndItemsNullableProp field. +SetArrayAndItemsNullableProp gets a reference to the given []map[string]interface{} and assigns it to the ArrayAndItemsNullableProp field. ### SetArrayAndItemsNullablePropExplicitNull @@ -302,13 +302,13 @@ SetArrayItemsNullable gets a reference to the given []map[string]interface{} and ### GetObjectNullableProp -`func (o *NullableClass) GetObjectNullableProp() NullableMap[string]map[string]interface{}` +`func (o *NullableClass) GetObjectNullableProp() map[string]map[string]interface{}` GetObjectNullableProp returns the ObjectNullableProp field if non-nil, zero value otherwise. ### GetObjectNullablePropOk -`func (o *NullableClass) GetObjectNullablePropOk() (NullableMap[string]map[string]interface{}, bool)` +`func (o *NullableClass) GetObjectNullablePropOk() (map[string]map[string]interface{}, bool)` GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. @@ -321,9 +321,9 @@ HasObjectNullableProp returns a boolean if a field has been set. ### SetObjectNullableProp -`func (o *NullableClass) SetObjectNullableProp(v NullableMap[string]map[string]interface{})` +`func (o *NullableClass) SetObjectNullableProp(v map[string]map[string]interface{})` -SetObjectNullableProp gets a reference to the given NullableMap[string]map[string]interface{} and assigns it to the ObjectNullableProp field. +SetObjectNullableProp gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectNullableProp field. ### SetObjectNullablePropExplicitNull @@ -334,13 +334,13 @@ when serializing to JSON (pass true as argument to set this, false to unset) The ObjectNullableProp value is set to nil even if false is passed ### GetObjectAndItemsNullableProp -`func (o *NullableClass) GetObjectAndItemsNullableProp() NullableMap[string]map[string]interface{}` +`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]map[string]interface{}` GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field if non-nil, zero value otherwise. ### GetObjectAndItemsNullablePropOk -`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (NullableMap[string]map[string]interface{}, bool)` +`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (map[string]map[string]interface{}, bool)` GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. @@ -353,9 +353,9 @@ HasObjectAndItemsNullableProp returns a boolean if a field has been set. ### SetObjectAndItemsNullableProp -`func (o *NullableClass) SetObjectAndItemsNullableProp(v NullableMap[string]map[string]interface{})` +`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]map[string]interface{})` -SetObjectAndItemsNullableProp gets a reference to the given NullableMap[string]map[string]interface{} and assigns it to the ObjectAndItemsNullableProp field. +SetObjectAndItemsNullableProp gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectAndItemsNullableProp field. ### SetObjectAndItemsNullablePropExplicitNull diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod b/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod index b80383b722c..f9811556cc5 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod @@ -3,6 +3,5 @@ module github.com/GIT_USER_ID/GIT_REPO_ID go 1.13 require ( - github.com/antihax/optional v1.0.0 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 ) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_200_response.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_200_response.go index f746eb97c50..b4e9becc59c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_200_response.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_200_response.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model__special_model_name_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model__special_model_name_.go index a327da2f86f..e1827cee896 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model__special_model_name_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model__special_model_name_.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go index 2448275032b..d224074b290 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_animal.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_animal.go index bec70d7337a..b54f59dbe61 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_animal.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_animal.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_api_response.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_api_response.go index 94b4983c8b3..0b9eab9f759 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_api_response.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_api_response.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go index 02cbaaae246..f2dbbb1f21e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go index dca9e7022ab..9268a2ae608 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_test_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_test_.go index b4566967aaf..84123ef137b 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_test_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_test_.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_capitalization.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_capitalization.go index a4489cc259c..8288d903b7b 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_capitalization.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_capitalization.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat.go index 952bf040204..a9f83cc8c40 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat_all_of.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat_all_of.go index 53da305ec11..60ba5b0259f 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat_all_of.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat_all_of.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_category.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_category.go index f942863971d..0bf8c0a2fd2 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_category.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_category.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_class_model.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_class_model.go index 9ac228a5eba..1621fc4acbd 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_class_model.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_class_model.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_client.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_client.go index 5d959e49a77..45f3fce18b4 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_client.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_client.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog.go index 9cf3882d97c..eb2d7f05d41 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog_all_of.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog_all_of.go index 19e81717139..c88dfaca2e0 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog_all_of.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog_all_of.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_arrays.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_arrays.go index 104d4a22b39..181a9287220 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_arrays.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_arrays.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_class.go index 4f97b16b8ef..826172fc39b 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_class.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" @@ -19,9 +19,9 @@ type EnumClass string // List of EnumClass const ( - ABC EnumClass = "_abc" - EFG EnumClass = "-efg" - XYZ EnumClass = "(xyz)" + ENUMCLASS_ABC EnumClass = "_abc" + ENUMCLASS_EFG EnumClass = "-efg" + ENUMCLASS_XYZ EnumClass = "(xyz)" ) type NullableEnumClass struct { diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_test_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_test_.go index 426a4bfe988..e17990e0e8a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_test_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_test_.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file.go index 72ba963d094..23da628abcc 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go index 6520daf2599..50145af1223 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_foo.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_foo.go index 7aed18852c6..4d62649a7fc 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_foo.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_foo.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_format_test_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_format_test_.go index 55d40bd04b7..9bf313a01f6 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_format_test_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_format_test_.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go index ba4d6b6bc0f..5394aa4007d 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_health_check_result.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_health_check_result.go index d6b450bb910..ad87c93a74c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_health_check_result.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_health_check_result.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object.go index 05152802669..c789be40281 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_1.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_1.go index b718912b270..f4ad400f832 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_1.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_1.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_2.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_2.go index fe7e129e3f5..2734be44f5d 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_2.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_2.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_3.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_3.go index e840bc4d75c..dece4ad604b 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_3.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_3.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_4.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_4.go index 8a17ec87e22..837e8f423bf 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_4.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_4.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_5.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_5.go index 8f4553ae280..6673d413276 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_5.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_5.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_response_default.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_response_default.go index 9caab8b3791..3d8d72130c5 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_response_default.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_response_default.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_list.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_list.go index 18ef3c182ad..6259d7507a3 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_list.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_list.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_map_test_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_map_test_.go index f4e3ea57c90..820f2641347 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_map_test_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_map_test_.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go index 1a0d83380c7..c4a7dba8182 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_name.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_name.go index 6256aa5c2b3..2f3716aad24 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_name.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_name.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go index 74d39932b11..2a51bd6a123 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go @@ -7,12 +7,11 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" "encoding/json" - "time" ) // NullableClass struct for NullableClass @@ -22,12 +21,12 @@ type NullableClass struct { BooleanProp *NullableBool `json:"boolean_prop,omitempty"` StringProp *NullableString `json:"string_prop,omitempty"` DateProp *NullableString `json:"date_prop,omitempty"` - DatetimeProp *NullableTime.Time `json:"datetime_prop,omitempty"` - ArrayNullableProp *Nullable[]map[string]interface{} `json:"array_nullable_prop,omitempty"` - ArrayAndItemsNullableProp *Nullable[]map[string]interface{} `json:"array_and_items_nullable_prop,omitempty"` + DatetimeProp *NullableTime `json:"datetime_prop,omitempty"` + ArrayNullableProp *[]map[string]interface{} `json:"array_nullable_prop,omitempty"` + ArrayAndItemsNullableProp *[]map[string]interface{} `json:"array_and_items_nullable_prop,omitempty"` ArrayItemsNullable *[]map[string]interface{} `json:"array_items_nullable,omitempty"` - ObjectNullableProp *NullableMap[string]map[string]interface{} `json:"object_nullable_prop,omitempty"` - ObjectAndItemsNullableProp *NullableMap[string]map[string]interface{} `json:"object_and_items_nullable_prop,omitempty"` + ObjectNullableProp *map[string]map[string]interface{} `json:"object_nullable_prop,omitempty"` + ObjectAndItemsNullableProp *map[string]map[string]interface{} `json:"object_and_items_nullable_prop,omitempty"` ObjectItemsNullable *map[string]map[string]interface{} `json:"object_items_nullable,omitempty"` } @@ -197,9 +196,9 @@ func (o *NullableClass) SetDateProp(v NullableString) { } // GetDatetimeProp returns the DatetimeProp field value if set, zero value otherwise. -func (o *NullableClass) GetDatetimeProp() NullableTime.Time { +func (o *NullableClass) GetDatetimeProp() NullableTime { if o == nil || o.DatetimeProp == nil { - var ret NullableTime.Time + var ret NullableTime return ret } return *o.DatetimeProp @@ -207,9 +206,9 @@ func (o *NullableClass) GetDatetimeProp() NullableTime.Time { // GetDatetimePropOk returns a tuple with the DatetimeProp field value if set, zero value otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetDatetimePropOk() (NullableTime.Time, bool) { +func (o *NullableClass) GetDatetimePropOk() (NullableTime, bool) { if o == nil || o.DatetimeProp == nil { - var ret NullableTime.Time + var ret NullableTime return ret, false } return *o.DatetimeProp, true @@ -224,15 +223,15 @@ func (o *NullableClass) HasDatetimeProp() bool { return false } -// SetDatetimeProp gets a reference to the given NullableTime.Time and assigns it to the DatetimeProp field. -func (o *NullableClass) SetDatetimeProp(v NullableTime.Time) { +// SetDatetimeProp gets a reference to the given NullableTime and assigns it to the DatetimeProp field. +func (o *NullableClass) SetDatetimeProp(v NullableTime) { o.DatetimeProp = &v } // GetArrayNullableProp returns the ArrayNullableProp field value if set, zero value otherwise. -func (o *NullableClass) GetArrayNullableProp() Nullable[]map[string]interface{} { +func (o *NullableClass) GetArrayNullableProp() []map[string]interface{} { if o == nil || o.ArrayNullableProp == nil { - var ret Nullable[]map[string]interface{} + var ret []map[string]interface{} return ret } return *o.ArrayNullableProp @@ -240,9 +239,9 @@ func (o *NullableClass) GetArrayNullableProp() Nullable[]map[string]interface{} // GetArrayNullablePropOk returns a tuple with the ArrayNullableProp field value if set, zero value otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetArrayNullablePropOk() (Nullable[]map[string]interface{}, bool) { +func (o *NullableClass) GetArrayNullablePropOk() ([]map[string]interface{}, bool) { if o == nil || o.ArrayNullableProp == nil { - var ret Nullable[]map[string]interface{} + var ret []map[string]interface{} return ret, false } return *o.ArrayNullableProp, true @@ -257,15 +256,15 @@ func (o *NullableClass) HasArrayNullableProp() bool { return false } -// SetArrayNullableProp gets a reference to the given Nullable[]map[string]interface{} and assigns it to the ArrayNullableProp field. -func (o *NullableClass) SetArrayNullableProp(v Nullable[]map[string]interface{}) { +// SetArrayNullableProp gets a reference to the given []map[string]interface{} and assigns it to the ArrayNullableProp field. +func (o *NullableClass) SetArrayNullableProp(v []map[string]interface{}) { o.ArrayNullableProp = &v } // GetArrayAndItemsNullableProp returns the ArrayAndItemsNullableProp field value if set, zero value otherwise. -func (o *NullableClass) GetArrayAndItemsNullableProp() Nullable[]map[string]interface{} { +func (o *NullableClass) GetArrayAndItemsNullableProp() []map[string]interface{} { if o == nil || o.ArrayAndItemsNullableProp == nil { - var ret Nullable[]map[string]interface{} + var ret []map[string]interface{} return ret } return *o.ArrayAndItemsNullableProp @@ -273,9 +272,9 @@ func (o *NullableClass) GetArrayAndItemsNullableProp() Nullable[]map[string]inte // GetArrayAndItemsNullablePropOk returns a tuple with the ArrayAndItemsNullableProp field value if set, zero value otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetArrayAndItemsNullablePropOk() (Nullable[]map[string]interface{}, bool) { +func (o *NullableClass) GetArrayAndItemsNullablePropOk() ([]map[string]interface{}, bool) { if o == nil || o.ArrayAndItemsNullableProp == nil { - var ret Nullable[]map[string]interface{} + var ret []map[string]interface{} return ret, false } return *o.ArrayAndItemsNullableProp, true @@ -290,8 +289,8 @@ func (o *NullableClass) HasArrayAndItemsNullableProp() bool { return false } -// SetArrayAndItemsNullableProp gets a reference to the given Nullable[]map[string]interface{} and assigns it to the ArrayAndItemsNullableProp field. -func (o *NullableClass) SetArrayAndItemsNullableProp(v Nullable[]map[string]interface{}) { +// SetArrayAndItemsNullableProp gets a reference to the given []map[string]interface{} and assigns it to the ArrayAndItemsNullableProp field. +func (o *NullableClass) SetArrayAndItemsNullableProp(v []map[string]interface{}) { o.ArrayAndItemsNullableProp = &v } @@ -329,9 +328,9 @@ func (o *NullableClass) SetArrayItemsNullable(v []map[string]interface{}) { } // GetObjectNullableProp returns the ObjectNullableProp field value if set, zero value otherwise. -func (o *NullableClass) GetObjectNullableProp() NullableMap[string]map[string]interface{} { +func (o *NullableClass) GetObjectNullableProp() map[string]map[string]interface{} { if o == nil || o.ObjectNullableProp == nil { - var ret NullableMap[string]map[string]interface{} + var ret map[string]map[string]interface{} return ret } return *o.ObjectNullableProp @@ -339,9 +338,9 @@ func (o *NullableClass) GetObjectNullableProp() NullableMap[string]map[string]in // GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field value if set, zero value otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetObjectNullablePropOk() (NullableMap[string]map[string]interface{}, bool) { +func (o *NullableClass) GetObjectNullablePropOk() (map[string]map[string]interface{}, bool) { if o == nil || o.ObjectNullableProp == nil { - var ret NullableMap[string]map[string]interface{} + var ret map[string]map[string]interface{} return ret, false } return *o.ObjectNullableProp, true @@ -356,15 +355,15 @@ func (o *NullableClass) HasObjectNullableProp() bool { return false } -// SetObjectNullableProp gets a reference to the given NullableMap[string]map[string]interface{} and assigns it to the ObjectNullableProp field. -func (o *NullableClass) SetObjectNullableProp(v NullableMap[string]map[string]interface{}) { +// SetObjectNullableProp gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectNullableProp field. +func (o *NullableClass) SetObjectNullableProp(v map[string]map[string]interface{}) { o.ObjectNullableProp = &v } // GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field value if set, zero value otherwise. -func (o *NullableClass) GetObjectAndItemsNullableProp() NullableMap[string]map[string]interface{} { +func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]map[string]interface{} { if o == nil || o.ObjectAndItemsNullableProp == nil { - var ret NullableMap[string]map[string]interface{} + var ret map[string]map[string]interface{} return ret } return *o.ObjectAndItemsNullableProp @@ -372,9 +371,9 @@ func (o *NullableClass) GetObjectAndItemsNullableProp() NullableMap[string]map[s // GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field value if set, zero value otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetObjectAndItemsNullablePropOk() (NullableMap[string]map[string]interface{}, bool) { +func (o *NullableClass) GetObjectAndItemsNullablePropOk() (map[string]map[string]interface{}, bool) { if o == nil || o.ObjectAndItemsNullableProp == nil { - var ret NullableMap[string]map[string]interface{} + var ret map[string]map[string]interface{} return ret, false } return *o.ObjectAndItemsNullableProp, true @@ -389,8 +388,8 @@ func (o *NullableClass) HasObjectAndItemsNullableProp() bool { return false } -// SetObjectAndItemsNullableProp gets a reference to the given NullableMap[string]map[string]interface{} and assigns it to the ObjectAndItemsNullableProp field. -func (o *NullableClass) SetObjectAndItemsNullableProp(v NullableMap[string]map[string]interface{}) { +// SetObjectAndItemsNullableProp gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectAndItemsNullableProp field. +func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]map[string]interface{}) { o.ObjectAndItemsNullableProp = &v } diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_number_only.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_number_only.go index db549197413..afa9c1b403a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_number_only.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_number_only.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_order.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_order.go index b90caa6101e..448d6a975a4 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_order.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_order.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_composite.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_composite.go index cd40b710988..423d3e5ad37 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_composite.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_composite.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum.go index 8e7b562c1e5..b24d4b48d71 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" @@ -19,9 +19,9 @@ type OuterEnum string // List of OuterEnum const ( - PLACED OuterEnum = "placed" - APPROVED OuterEnum = "approved" - DELIVERED OuterEnum = "delivered" + OUTERENUM_PLACED OuterEnum = "placed" + OUTERENUM_APPROVED OuterEnum = "approved" + OUTERENUM_DELIVERED OuterEnum = "delivered" ) type NullableOuterEnum struct { diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_default_value.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_default_value.go index 3305aa215fe..a9514cdfaf9 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_default_value.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_default_value.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" @@ -19,9 +19,9 @@ type OuterEnumDefaultValue string // List of OuterEnumDefaultValue const ( - PLACED OuterEnumDefaultValue = "placed" - APPROVED OuterEnumDefaultValue = "approved" - DELIVERED OuterEnumDefaultValue = "delivered" + OUTERENUMDEFAULTVALUE_PLACED OuterEnumDefaultValue = "placed" + OUTERENUMDEFAULTVALUE_APPROVED OuterEnumDefaultValue = "approved" + OUTERENUMDEFAULTVALUE_DELIVERED OuterEnumDefaultValue = "delivered" ) type NullableOuterEnumDefaultValue struct { diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer.go index 2d144b70d55..6555f0a9822 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" @@ -19,9 +19,9 @@ type OuterEnumInteger int32 // List of OuterEnumInteger const ( - _0 OuterEnumInteger = 0 - _1 OuterEnumInteger = 1 - _2 OuterEnumInteger = 2 + OUTERENUMINTEGER__0 OuterEnumInteger = 0 + OUTERENUMINTEGER__1 OuterEnumInteger = 1 + OUTERENUMINTEGER__2 OuterEnumInteger = 2 ) type NullableOuterEnumInteger struct { diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer_default_value.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer_default_value.go index d7290302094..022dd527ec0 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer_default_value.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer_default_value.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" @@ -19,9 +19,9 @@ type OuterEnumIntegerDefaultValue int32 // List of OuterEnumIntegerDefaultValue const ( - _0 OuterEnumIntegerDefaultValue = 0 - _1 OuterEnumIntegerDefaultValue = 1 - _2 OuterEnumIntegerDefaultValue = 2 + OUTERENUMINTEGERDEFAULTVALUE__0 OuterEnumIntegerDefaultValue = 0 + OUTERENUMINTEGERDEFAULTVALUE__1 OuterEnumIntegerDefaultValue = 1 + OUTERENUMINTEGERDEFAULTVALUE__2 OuterEnumIntegerDefaultValue = 2 ) type NullableOuterEnumIntegerDefaultValue struct { diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_pet.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_pet.go index 0986a674066..7c1228c8b61 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_pet.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_pet.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_read_only_first.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_read_only_first.go index 24f821d7bdf..424ef8b81f3 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_read_only_first.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_read_only_first.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_return.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_return.go index c5b2d1aaecc..785303c992d 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_return.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_return.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_tag.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_tag.go index f50a11101e4..bcb30265ab2 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_tag.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_tag.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go index dc7234de91b..a427f7f7c24 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/response.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/response.go index 77346c8c1e3..c16f181f4e9 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/response.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/response.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "net/http" diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go index 2bfa04d4e48..3a3303b2445 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go @@ -7,7 +7,7 @@ * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ -package openapi +package petstore import ( "bytes" diff --git a/samples/openapi3/client/petstore/go-experimental/pet_api_test.go b/samples/openapi3/client/petstore/go-experimental/pet_api_test.go new file mode 100644 index 00000000000..9f0a154f96a --- /dev/null +++ b/samples/openapi3/client/petstore/go-experimental/pet_api_test.go @@ -0,0 +1,292 @@ +package main + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/stretchr/testify/assert" + + sw "./go-petstore" +) + +var client *sw.APIClient + +const testHost = "petstore.swagger.io:80" +const testScheme = "http" + +func TestMain(m *testing.M) { + cfg := sw.NewConfiguration() + cfg.AddDefaultHeader("testheader", "testvalue") + cfg.Host = testHost + cfg.Scheme = testScheme + client = sw.NewAPIClient(cfg) + retCode := m.Run() + os.Exit(retCode) +} + +func TestAddPet(t *testing.T) { + newPet := (sw.Pet{Id: sw.PtrInt64(12830), Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"), + Tags: &[]sw.Tag{sw.Tag{Id: sw.PtrInt64(1), Name: sw.PtrString("tag2")}}}) + + r, err := client.PetApi.AddPet(context.Background()).Pet(newPet).Execute() + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestFindPetsByStatusWithMissingParam(t *testing.T) { + _, r, err := client.PetApi.FindPetsByStatus(context.Background()).Status(nil).Execute() + + if err != nil { + t.Fatalf("Error while testing TestFindPetsByStatusWithMissingParam: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestGetPetById(t *testing.T) { + isPetCorrect(t, 12830, "gopher", "pending") +} + +func TestGetPetByIdWithInvalidID(t *testing.T) { + resp, r, err := client.PetApi.GetPetById(context.Background(), 999999999).Execute() + if r != nil && r.StatusCode == 404 { + assertedError, ok := err.(sw.GenericOpenAPIError) + a := assert.New(t) + a.True(ok) + a.Contains(string(assertedError.Body()), "type") + + a.Contains(assertedError.Error(), "Not Found") + } else if err != nil { + t.Fatalf("Error while getting pet by invalid id: %v", err) + t.Log(r) + } else { + t.Log(resp) + } +} + +func TestUpdatePetWithForm(t *testing.T) { + r, err := client.PetApi.UpdatePetWithForm(context.Background(), 12830).Name("golang").Status("available").Execute() + if err != nil { + t.Fatalf("Error while updating pet by id: %v", err) + t.Log(r) + } + if r.StatusCode != 200 { + t.Log(r) + } + + // get the pet with id 12830 from server to verify the update + isPetCorrect(t, 12830, "golang", "available") +} + +func TestFindPetsByTag(t *testing.T) { + var found = false + resp, r, err := client.PetApi.FindPetsByTags(context.Background()).Tags([]string{"tag2"}).Execute() + if err != nil { + t.Fatalf("Error while getting pet by tag: %v", err) + t.Log(r) + } else { + if len(resp) == 0 { + t.Errorf("Error no pets returned") + } else { + + assert := assert.New(t) + for i := 0; i < len(resp); i++ { + if *resp[i].Id == 12830 { + assert.Equal(*resp[i].Status, "available", "Pet status should be `pending`") + found = true + } + } + } + + if found == false { + t.Errorf("Error while getting pet by tag could not find 12830") + } + + if r.StatusCode != 200 { + t.Log(r) + } + } +} + +func TestFindPetsByStatus(t *testing.T) { + resp, r, err := client.PetApi.FindPetsByStatus(context.Background()).Status([]string{"available"}).Execute() + if err != nil { + t.Fatalf("Error while getting pet by id: %v", err) + t.Log(r) + } else { + if len(resp) == 0 { + t.Errorf("Error no pets returned") + } else { + assert := assert.New(t) + for i := 0; i < len(resp); i++ { + assert.Equal(*resp[i].Status, "available", "Pet status should be `available`") + } + } + + if r.StatusCode != 200 { + t.Log(r) + } + } +} + +func TestUploadFile(t *testing.T) { + file, err1 := os.Open("testfiles/foo.png") + if err1 != nil { + t.Fatalf("Error opening file: %v", err1) + } + + _, r, err := client.PetApi.UploadFile(context.Background(), 12830).AdditionalMetadata("golang").File(file).Execute() + + if err != nil { + t.Fatalf("Error while uploading file: %v", err) + } + + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestUploadFileRequired(t *testing.T) { + return // remove when server supports this endpoint + file, err1 := os.Open("testfiles/foo.png") + if err1 != nil { + t.Fatalf("Error opening file: %v", err1) + } + + _, r, err := client.PetApi.UploadFileWithRequiredFile(context.Background(), 12830).RequiredFile(file).AdditionalMetadata("golang").Execute() + + if err != nil { + t.Fatalf("Error while uploading file: %v", err) + } + + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestDeletePet(t *testing.T) { + r, err := client.PetApi.DeletePet(context.Background(), 12830).Execute() + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +/* +// Test we can concurrently create, retrieve, update, and delete. +func TestConcurrency(t *testing.T) { + errc := make(chan error) + + newPets := []sw.Pet{ + sw.Pet{Id: 912345, Name: "gopherFred", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"}, + sw.Pet{Id: 912346, Name: "gopherDan", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "active"}, + sw.Pet{Id: 912347, Name: "gopherRick", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "mia"}, + sw.Pet{Id: 912348, Name: "gopherJohn", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "active"}, + sw.Pet{Id: 912349, Name: "gopherAlf", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"}, + sw.Pet{Id: 912350, Name: "gopherRob", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"}, + sw.Pet{Id: 912351, Name: "gopherIan", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "active"}, + } + + // Add the pets. + for _, pet := range newPets { + go func(newPet sw.Pet) { + r, err := client.PetApi.AddPet(nil, newPet) + if r.StatusCode != 200 { + t.Log(r) + } + errc <- err + }(pet) + } + waitOnFunctions(t, errc, len(newPets)) + + // Verify they are correct. + for _, pet := range newPets { + go func(pet sw.Pet) { + isPetCorrect(t, pet.Id, pet.Name, pet.Status) + errc <- nil + }(pet) + } + + waitOnFunctions(t, errc, len(newPets)) + + // Update all to active with the name gopherDan + for _, pet := range newPets { + go func(id int64) { + r, err := client.PetApi.UpdatePet(nil, sw.Pet{Id: (int64)(id), Name: "gopherDan", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "active"}) + if r.StatusCode != 200 { + t.Log(r) + } + errc <- err + }(pet.Id) + } + waitOnFunctions(t, errc, len(newPets)) + + // Verify they are correct. + for _, pet := range newPets { + go func(pet sw.Pet) { + isPetCorrect(t, pet.Id, "gopherDan", "active") + errc <- nil + }(pet) + } + + waitOnFunctions(t, errc, len(newPets)) + + // Delete them all. + for _, pet := range newPets { + go func(id int64) { + deletePet(t, (int64)(id)) + errc <- nil + }(pet.Id) + } + waitOnFunctions(t, errc, len(newPets)) +} +*/ + +func waitOnFunctions(t *testing.T, errc chan error, n int) { + for i := 0; i < n; i++ { + err := <-errc + if err != nil { + t.Fatalf("Error performing concurrent test: %v", err) + } + } +} + +func deletePet(t *testing.T, id int64) { + r, err := client.PetApi.DeletePet(context.Background(), id).Execute() + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func isPetCorrect(t *testing.T, id int64, name string, status string) { + assert := assert.New(t) + resp, r, err := client.PetApi.GetPetById(context.Background(), id).Execute() + if err != nil { + t.Fatalf("Error while getting pet by id: %v", err) + } else { + assert.Equal(*resp.Id, int64(id), "Pet id should be equal") + assert.Equal(resp.Name, name, fmt.Sprintf("Pet name should be %s", name)) + assert.Equal(*resp.Status, status, fmt.Sprintf("Pet status should be %s", status)) + + //t.Log(resp) + } + if r.StatusCode != 200 { + t.Log(r) + } +} diff --git a/samples/openapi3/client/petstore/go-experimental/pom.xml b/samples/openapi3/client/petstore/go-experimental/pom.xml new file mode 100644 index 00000000000..2f84e8bbfe7 --- /dev/null +++ b/samples/openapi3/client/petstore/go-experimental/pom.xml @@ -0,0 +1,89 @@ + + 4.0.0 + org.openapitools + GoExperimentalOAS3Petstore + pom + 1.0.0 + Go Experimental OpenAPI3 Petstore Client + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + go-get-testify + pre-integration-test + + exec + + + go + + get + github.com/stretchr/testify/assert + + + + + go-get-oauth2 + pre-integration-test + + exec + + + go + + get + golang.org/x/oauth2 + + + + + go-get-context + pre-integration-test + + exec + + + go + + get + golang.org/x/net/context + + + + + go-test + integration-test + + exec + + + go + + test + -v + + + + + + + + diff --git a/samples/openapi3/client/petstore/go-experimental/store_api_test.go b/samples/openapi3/client/petstore/go-experimental/store_api_test.go new file mode 100644 index 00000000000..fc0cdec9699 --- /dev/null +++ b/samples/openapi3/client/petstore/go-experimental/store_api_test.go @@ -0,0 +1,37 @@ +package main + +import ( + "context" + "regexp" + "testing" + "time" + + sw "./go-petstore" +) + +func TestPlaceOrder(t *testing.T) { + newOrder := sw.Order{ + Id: sw.PtrInt64(0), + PetId: sw.PtrInt64(0), + Quantity: sw.PtrInt32(0), + ShipDate: sw.PtrTime(time.Now().UTC()), + Status: sw.PtrString("placed"), + Complete: sw.PtrBool(false)} + + _, r, err := client.StoreApi.PlaceOrder(context.Background()).Order(newOrder).Execute() + + if err != nil { + // Skip parsing time error due to error in Petstore Test Server + // https://github.com/OpenAPITools/openapi-generator/issues/1292 + if regexp. + MustCompile(`^parsing time.+cannot parse "\+0000"" as "Z07:00"$`). + MatchString(err.Error()) { + t.Log("Skipping error for parsing time with `+0000` UTC offset as Petstore Test Server does not return valid RFC 3339 datetime") + } else { + t.Fatalf("Error while placing order: %v", err) + } + } + if r.StatusCode != 200 { + t.Log(r) + } +} diff --git a/samples/openapi3/client/petstore/go-experimental/testfiles/foo.png b/samples/openapi3/client/petstore/go-experimental/testfiles/foo.png new file mode 100644 index 00000000000..a9b12cf5927 Binary files /dev/null and b/samples/openapi3/client/petstore/go-experimental/testfiles/foo.png differ diff --git a/samples/openapi3/client/petstore/go-experimental/user_api_test.go b/samples/openapi3/client/petstore/go-experimental/user_api_test.go new file mode 100644 index 00000000000..f7652aea456 --- /dev/null +++ b/samples/openapi3/client/petstore/go-experimental/user_api_test.go @@ -0,0 +1,153 @@ +package main + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + + sw "./go-petstore" +) + +func TestCreateUser(t *testing.T) { + newUser := sw.User{ + Id: sw.PtrInt64(1000), + FirstName: sw.PtrString("gopher"), + LastName: sw.PtrString("lang"), + Username: sw.PtrString("gopher"), + Password: sw.PtrString("lang"), + Email: sw.PtrString("lang@test.com"), + Phone: sw.PtrString("5101112222"), + UserStatus: sw.PtrInt32(1)} + + apiResponse, err := client.UserApi.CreateUser(context.Background()).User(newUser).Execute() + + if err != nil { + t.Fatalf("Error while adding user: %v", err) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } +} + +//adding x to skip the test, currently it is failing +func TestCreateUsersWithArrayInput(t *testing.T) { + newUsers := []sw.User{ + sw.User{ + Id: sw.PtrInt64(1001), + FirstName: sw.PtrString("gopher1"), + LastName: sw.PtrString("lang1"), + Username: sw.PtrString("gopher1"), + Password: sw.PtrString("lang1"), + Email: sw.PtrString("lang1@test.com"), + Phone: sw.PtrString("5101112222"), + UserStatus: sw.PtrInt32(1), + }, + sw.User{ + Id: sw.PtrInt64(1002), + FirstName: sw.PtrString("gopher2"), + LastName: sw.PtrString("lang2"), + Username: sw.PtrString("gopher2"), + Password: sw.PtrString("lang2"), + Email: sw.PtrString("lang2@test.com"), + Phone: sw.PtrString("5101112222"), + UserStatus: sw.PtrInt32(1), + }, + } + + apiResponse, err := client.UserApi.CreateUsersWithArrayInput(context.Background()).User(newUsers).Execute() + if err != nil { + t.Fatalf("Error while adding users: %v", err) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } + + //tear down + _, err1 := client.UserApi.DeleteUser(context.Background(), "gopher1").Execute() + if err1 != nil { + t.Errorf("Error while deleting user") + t.Log(err1) + } + + _, err2 := client.UserApi.DeleteUser(context.Background(), "gopher2").Execute() + if err2 != nil { + t.Errorf("Error while deleting user") + t.Log(err2) + } +} + +func TestGetUserByName(t *testing.T) { + assert := assert.New(t) + + resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "gopher").Execute() + if err != nil { + t.Fatalf("Error while getting user by id: %v", err) + } else { + assert.Equal(*resp.Id, int64(1000), "User id should be equal") + assert.Equal(*resp.Username, "gopher", "User name should be gopher") + assert.Equal(*resp.LastName, "lang", "Last name should be lang") + //t.Log(resp) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } +} + +func TestGetUserByNameWithInvalidID(t *testing.T) { + resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "999999999").Execute() + if apiResponse != nil && apiResponse.StatusCode == 404 { + return // This is a pass condition. API will return with a 404 error. + } else if err != nil { + t.Fatalf("Error while getting user by invalid id: %v", err) + t.Log(apiResponse) + } else { + t.Log(resp) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } +} + +func TestUpdateUser(t *testing.T) { + assert := assert.New(t) + + newUser := sw.User{ + Id: sw.PtrInt64(1000), + FirstName: sw.PtrString("gopher20"), + LastName: sw.PtrString("lang20"), + Username: sw.PtrString("gopher"), + Password: sw.PtrString("lang"), + Email: sw.PtrString("lang@test.com"), + Phone: sw.PtrString("5101112222"), + UserStatus: sw.PtrInt32(1)} + + apiResponse, err := client.UserApi.UpdateUser(context.Background(), "gopher").User(newUser).Execute() + if err != nil { + t.Fatalf("Error while deleting user by id: %v", err) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } + + //verify changings are correct + resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "gopher").Execute() + if err != nil { + t.Fatalf("Error while getting user by id: %v", err) + } else { + assert.Equal(*resp.Id, int64(1000), "User id should be equal") + assert.Equal(*resp.FirstName, "gopher20", "User name should be gopher") + assert.Equal(*resp.Password, "lang", "User name should be the same") + } +} + +func TestDeleteUser(t *testing.T) { + apiResponse, err := client.UserApi.DeleteUser(context.Background(), "gopher").Execute() + + if err != nil { + t.Fatalf("Error while deleting user: %v", err) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } +} diff --git a/samples/openapi3/client/petstore/go/auth_test.go b/samples/openapi3/client/petstore/go/auth_test.go new file mode 100644 index 00000000000..5f817703a88 --- /dev/null +++ b/samples/openapi3/client/petstore/go/auth_test.go @@ -0,0 +1,254 @@ +package main + +import ( + "context" + "net/http" + "net/http/httputil" + "strings" + "testing" + "time" + + "golang.org/x/oauth2" + + sw "./go-petstore" +) + +func TestOAuth2(t *testing.T) { + // Setup some fake oauth2 configuration + cfg := &oauth2.Config{ + ClientID: "1234567", + ClientSecret: "SuperSecret", + Endpoint: oauth2.Endpoint{ + AuthURL: "https://devnull", + TokenURL: "https://devnull", + }, + RedirectURL: "https://devnull", + } + + // and a fake token + tok := oauth2.Token{ + AccessToken: "FAKE", + RefreshToken: "So Fake", + Expiry: time.Now().Add(time.Hour * 100000), + TokenType: "Bearer", + } + + // then a fake tokenSource + tokenSource := cfg.TokenSource(createContext(nil), &tok) + auth := context.WithValue(context.Background(), sw.ContextOAuth2, tokenSource) + + newPet := (sw.Pet{Id: 12992, Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending", Tags: []sw.Tag{sw.Tag{Id: 1, Name: "tag2"}}}) + + r, err := client.PetApi.AddPet(context.Background(), newPet) + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + r, err = client.PetApi.DeletePet(auth, 12992, nil) + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + reqb, _ := httputil.DumpRequest(r.Request, true) + + if !strings.Contains((string)(reqb), "Authorization: Bearer FAKE") { + t.Errorf("OAuth2 Authentication is missing") + } +} + +func TestBasicAuth(t *testing.T) { + + auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{ + UserName: "fakeUser", + Password: "f4k3p455", + }) + + newPet := (sw.Pet{Id: 12992, Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending", Tags: []sw.Tag{sw.Tag{Id: 1, Name: "tag2"}}}) + + r, err := client.PetApi.AddPet(auth, newPet) + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + r, err = client.PetApi.DeletePet(auth, 12992, nil) + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Authorization: Basic ZmFrZVVzZXI6ZjRrM3A0NTU") { + t.Errorf("Basic Authentication is missing") + } +} + +func TestAccessToken(t *testing.T) { + auth := context.WithValue(context.Background(), sw.ContextAccessToken, "TESTFAKEACCESSTOKENISFAKE") + + newPet := (sw.Pet{Id: 12992, Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending", Tags: []sw.Tag{sw.Tag{Id: 1, Name: "tag2"}}}) + + r, err := client.PetApi.AddPet(nil, newPet) + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + r, err = client.PetApi.DeletePet(auth, 12992, nil) + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Authorization: Bearer TESTFAKEACCESSTOKENISFAKE") { + t.Errorf("AccessToken Authentication is missing") + } +} + +func TestAPIKeyNoPrefix(t *testing.T) { + auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{Key: "TEST123"}) + + newPet := (sw.Pet{Id: 12992, Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending", Tags: []sw.Tag{sw.Tag{Id: 1, Name: "tag2"}}}) + + r, err := client.PetApi.AddPet(context.Background(), newPet) + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + _, r, err = client.PetApi.GetPetById(auth, 12992) + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Api_key: TEST123") { + t.Errorf("APIKey Authentication is missing") + } + + r, err = client.PetApi.DeletePet(auth, 12992, nil) + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestAPIKeyWithPrefix(t *testing.T) { + auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{Key: "TEST123", Prefix: "Bearer"}) + + newPet := (sw.Pet{Id: 12992, Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending", Tags: []sw.Tag{sw.Tag{Id: 1, Name: "tag2"}}}) + + r, err := client.PetApi.AddPet(nil, newPet) + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + _, r, err = client.PetApi.GetPetById(auth, 12992) + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Api_key: Bearer TEST123") { + t.Errorf("APIKey Authentication is missing") + } + + r, err = client.PetApi.DeletePet(auth, 12992, nil) + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestDefaultHeader(t *testing.T) { + + newPet := (sw.Pet{Id: 12992, Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending", Tags: []sw.Tag{sw.Tag{Id: 1, Name: "tag2"}}}) + + r, err := client.PetApi.AddPet(context.Background(), newPet) + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + + r, err = client.PetApi.DeletePet(context.Background(), 12992, nil) + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } + reqb, _ := httputil.DumpRequest(r.Request, true) + if !strings.Contains((string)(reqb), "Testheader: testvalue") { + t.Errorf("Default Header is missing") + } +} + +func TestHostOverride(t *testing.T) { + _, r, err := client.PetApi.FindPetsByStatus(context.Background(), nil) + + if err != nil { + t.Fatalf("Error while finding pets by status: %v", err) + } + + if r.Request.URL.Host != testHost { + t.Errorf("Request Host is %v, expected %v", r.Request.Host, testHost) + } +} + +func TestSchemeOverride(t *testing.T) { + _, r, err := client.PetApi.FindPetsByStatus(context.Background(), nil) + + if err != nil { + t.Fatalf("Error while finding pets by status: %v", err) + } + + if r.Request.URL.Scheme != testScheme { + t.Errorf("Request Scheme is %v, expected %v", r.Request.URL.Scheme, testScheme) + } +} + +// Add custom clients to the context. +func createContext(httpClient *http.Client) context.Context { + parent := oauth2.NoContext + ctx := context.WithValue(parent, oauth2.HTTPClient, httpClient) + return ctx +} diff --git a/samples/openapi3/client/petstore/go/fake_api_test.go b/samples/openapi3/client/petstore/go/fake_api_test.go new file mode 100644 index 00000000000..f4242b5048c --- /dev/null +++ b/samples/openapi3/client/petstore/go/fake_api_test.go @@ -0,0 +1,28 @@ +package main + +import ( + "testing" + + sw "./go-petstore" + "golang.org/x/net/context" +) + +// TestPutBodyWithFileSchema ensures a model with the name 'File' +// gets converted properly to the petstore.File struct vs. *os.File +// as specified in typeMapping for 'File'. +func TestPutBodyWithFileSchema(t *testing.T) { + return // early return to test compilation + + schema := sw.FileSchemaTestClass{ + File: sw.File{SourceURI: "https://example.com/image.png"}, + Files: []sw.File{{SourceURI: "https://example.com/image.png"}}} + + r, err := client.FakeApi.TestBodyWithFileSchema(context.Background(), schema) + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} diff --git a/samples/openapi3/client/petstore/go/go-petstore/api_fake.go b/samples/openapi3/client/petstore/go/go-petstore/api_fake.go index b22a4bf9248..387dda7fee6 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/api_fake.go +++ b/samples/openapi3/client/petstore/go/go-petstore/api_fake.go @@ -1236,26 +1236,30 @@ func (a *FakeApiService) TestQueryParameterCollectionFormat(ctx _context.Context localVarQueryParams := _neturl.Values{} localVarFormParams := _neturl.Values{} - t:=pipe - if reflect.TypeOf(t).Kind() == reflect.Slice { - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("pipe", parameterToString(s.Index(i), "multi")) + { + t:=pipe + if reflect.TypeOf(t).Kind() == reflect.Slice { + s := reflect.ValueOf(t) + for i := 0; i < s.Len(); i++ { + localVarQueryParams.Add("pipe", parameterToString(s.Index(i), "multi")) + } + } else { + localVarQueryParams.Add("pipe", parameterToString(t, "multi")) } - } else { - localVarQueryParams.Add("pipe", parameterToString(t, "multi")) } localVarQueryParams.Add("ioutil", parameterToString(ioutil, "csv")) localVarQueryParams.Add("http", parameterToString(http, "space")) localVarQueryParams.Add("url", parameterToString(url, "csv")) - t:=context - if reflect.TypeOf(t).Kind() == reflect.Slice { - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("context", parameterToString(s.Index(i), "multi")) + { + t:=context + if reflect.TypeOf(t).Kind() == reflect.Slice { + s := reflect.ValueOf(t) + for i := 0; i < s.Len(); i++ { + localVarQueryParams.Add("context", parameterToString(s.Index(i), "multi")) + } + } else { + localVarQueryParams.Add("context", parameterToString(t, "multi")) } - } else { - localVarQueryParams.Add("context", parameterToString(t, "multi")) } // to determine the Content-Type header localVarHTTPContentTypes := []string{} diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_enum_class.go b/samples/openapi3/client/petstore/go/go-petstore/model_enum_class.go index 8b7e1ee8959..7470d644d0a 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_enum_class.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_enum_class.go @@ -13,7 +13,7 @@ type EnumClass string // List of EnumClass const ( - ABC EnumClass = "_abc" - EFG EnumClass = "-efg" - XYZ EnumClass = "(xyz)" + ENUMCLASS_ABC EnumClass = "_abc" + ENUMCLASS_EFG EnumClass = "-efg" + ENUMCLASS_XYZ EnumClass = "(xyz)" ) diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum.go b/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum.go index efefaf1b784..b9233fa91df 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum.go @@ -13,7 +13,7 @@ type OuterEnum string // List of OuterEnum const ( - PLACED OuterEnum = "placed" - APPROVED OuterEnum = "approved" - DELIVERED OuterEnum = "delivered" + OUTERENUM_PLACED OuterEnum = "placed" + OUTERENUM_APPROVED OuterEnum = "approved" + OUTERENUM_DELIVERED OuterEnum = "delivered" ) diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_default_value.go b/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_default_value.go index e150f03864f..6ab39166338 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_default_value.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_default_value.go @@ -13,7 +13,7 @@ type OuterEnumDefaultValue string // List of OuterEnumDefaultValue const ( - PLACED OuterEnumDefaultValue = "placed" - APPROVED OuterEnumDefaultValue = "approved" - DELIVERED OuterEnumDefaultValue = "delivered" + OUTERENUMDEFAULTVALUE_PLACED OuterEnumDefaultValue = "placed" + OUTERENUMDEFAULTVALUE_APPROVED OuterEnumDefaultValue = "approved" + OUTERENUMDEFAULTVALUE_DELIVERED OuterEnumDefaultValue = "delivered" ) diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_integer.go b/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_integer.go index bae14df0f7d..d8c4d36926d 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_integer.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_integer.go @@ -13,7 +13,7 @@ type OuterEnumInteger int32 // List of OuterEnumInteger const ( - _0 OuterEnumInteger = 0 - _1 OuterEnumInteger = 1 - _2 OuterEnumInteger = 2 + OUTERENUMINTEGER__0 OuterEnumInteger = 0 + OUTERENUMINTEGER__1 OuterEnumInteger = 1 + OUTERENUMINTEGER__2 OuterEnumInteger = 2 ) diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_integer_default_value.go b/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_integer_default_value.go index b882d7aee2c..27a68a9d6ef 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_integer_default_value.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_integer_default_value.go @@ -13,7 +13,7 @@ type OuterEnumIntegerDefaultValue int32 // List of OuterEnumIntegerDefaultValue const ( - _0 OuterEnumIntegerDefaultValue = 0 - _1 OuterEnumIntegerDefaultValue = 1 - _2 OuterEnumIntegerDefaultValue = 2 + OUTERENUMINTEGERDEFAULTVALUE__0 OuterEnumIntegerDefaultValue = 0 + OUTERENUMINTEGERDEFAULTVALUE__1 OuterEnumIntegerDefaultValue = 1 + OUTERENUMINTEGERDEFAULTVALUE__2 OuterEnumIntegerDefaultValue = 2 ) diff --git a/samples/openapi3/client/petstore/go/pet_api_test.go b/samples/openapi3/client/petstore/go/pet_api_test.go new file mode 100644 index 00000000000..cda4f457855 --- /dev/null +++ b/samples/openapi3/client/petstore/go/pet_api_test.go @@ -0,0 +1,303 @@ +package main + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/antihax/optional" + "github.com/stretchr/testify/assert" + + sw "./go-petstore" +) + +var client *sw.APIClient + +const testHost = "petstore.swagger.io:80" +const testScheme = "http" + +func TestMain(m *testing.M) { + cfg := sw.NewConfiguration() + cfg.AddDefaultHeader("testheader", "testvalue") + cfg.Host = testHost + cfg.Scheme = testScheme + client = sw.NewAPIClient(cfg) + retCode := m.Run() + os.Exit(retCode) +} + +func TestAddPet(t *testing.T) { + newPet := (sw.Pet{Id: 12830, Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending", Tags: []sw.Tag{sw.Tag{Id: 1, Name: "tag2"}}}) + + r, err := client.PetApi.AddPet(context.Background(), newPet) + + if err != nil { + t.Fatalf("Error while adding pet: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestFindPetsByStatusWithMissingParam(t *testing.T) { + _, r, err := client.PetApi.FindPetsByStatus(context.Background(), nil) + + if err != nil { + t.Fatalf("Error while testing TestFindPetsByStatusWithMissingParam: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestGetPetById(t *testing.T) { + isPetCorrect(t, 12830, "gopher", "pending") +} + +func TestGetPetByIdWithInvalidID(t *testing.T) { + resp, r, err := client.PetApi.GetPetById(context.Background(), 999999999) + if r != nil && r.StatusCode == 404 { + assertedError, ok := err.(sw.GenericOpenAPIError) + a := assert.New(t) + a.True(ok) + a.Contains(string(assertedError.Body()), "type") + + a.Contains(assertedError.Error(), "Not Found") + } else if err != nil { + t.Fatalf("Error while getting pet by invalid id: %v", err) + t.Log(r) + } else { + t.Log(resp) + } +} + +func TestUpdatePetWithForm(t *testing.T) { + r, err := client.PetApi.UpdatePetWithForm(context.Background(), 12830, &sw.UpdatePetWithFormOpts{ + Name: optional.NewString("golang"), + Status: optional.NewString("available"), + }) + if err != nil { + t.Fatalf("Error while updating pet by id: %v", err) + t.Log(r) + } + if r.StatusCode != 200 { + t.Log(r) + } + + // get the pet with id 12830 from server to verify the update + isPetCorrect(t, 12830, "golang", "available") +} + +func TestFindPetsByTag(t *testing.T) { + var found = false + resp, r, err := client.PetApi.FindPetsByTags(context.Background(), []string{"tag2"}) + if err != nil { + t.Fatalf("Error while getting pet by tag: %v", err) + t.Log(r) + } else { + if len(resp) == 0 { + t.Errorf("Error no pets returned") + } else { + + assert := assert.New(t) + for i := 0; i < len(resp); i++ { + if resp[i].Id == 12830 { + assert.Equal(resp[i].Status, "available", "Pet status should be `pending`") + found = true + } + } + } + + if found == false { + t.Errorf("Error while getting pet by tag could not find 12830") + } + + if r.StatusCode != 200 { + t.Log(r) + } + } +} + +func TestFindPetsByStatus(t *testing.T) { + resp, r, err := client.PetApi.FindPetsByStatus(context.Background(), []string{"available"}) + if err != nil { + t.Fatalf("Error while getting pet by id: %v", err) + t.Log(r) + } else { + if len(resp) == 0 { + t.Errorf("Error no pets returned") + } else { + assert := assert.New(t) + for i := 0; i < len(resp); i++ { + assert.Equal(resp[i].Status, "available", "Pet status should be `available`") + } + } + + if r.StatusCode != 200 { + t.Log(r) + } + } +} + +func TestUploadFile(t *testing.T) { + file, err1 := os.Open("testfiles/foo.png") + if err1 != nil { + t.Fatalf("Error opening file: %v", err1) + } + + _, r, err := client.PetApi.UploadFile(context.Background(), 12830, &sw.UploadFileOpts{ + AdditionalMetadata: optional.NewString("golang"), + File: optional.NewInterface(file), + }) + + if err != nil { + t.Fatalf("Error while uploading file: %v", err) + } + + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestUploadFileRequired(t *testing.T) { + return // remove when server supports this endpoint + file, err1 := os.Open("testfiles/foo.png") + if err1 != nil { + t.Fatalf("Error opening file: %v", err1) + } + + _, r, err := client.PetApi.UploadFileWithRequiredFile(context.Background(), 12830, + file, + &sw.UploadFileWithRequiredFileOpts{ + AdditionalMetadata: optional.NewString("golang"), + }) + + if err != nil { + t.Fatalf("Error while uploading file: %v", err) + } + + if r.StatusCode != 200 { + t.Log(r) + } +} + +func TestDeletePet(t *testing.T) { + r, err := client.PetApi.DeletePet(context.Background(), 12830, nil) + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +/* +// Test we can concurrently create, retrieve, update, and delete. +func TestConcurrency(t *testing.T) { + errc := make(chan error) + + newPets := []sw.Pet{ + sw.Pet{Id: 912345, Name: "gopherFred", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"}, + sw.Pet{Id: 912346, Name: "gopherDan", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "active"}, + sw.Pet{Id: 912347, Name: "gopherRick", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "mia"}, + sw.Pet{Id: 912348, Name: "gopherJohn", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "active"}, + sw.Pet{Id: 912349, Name: "gopherAlf", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"}, + sw.Pet{Id: 912350, Name: "gopherRob", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"}, + sw.Pet{Id: 912351, Name: "gopherIan", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "active"}, + } + + // Add the pets. + for _, pet := range newPets { + go func(newPet sw.Pet) { + r, err := client.PetApi.AddPet(nil, newPet) + if r.StatusCode != 200 { + t.Log(r) + } + errc <- err + }(pet) + } + waitOnFunctions(t, errc, len(newPets)) + + // Verify they are correct. + for _, pet := range newPets { + go func(pet sw.Pet) { + isPetCorrect(t, pet.Id, pet.Name, pet.Status) + errc <- nil + }(pet) + } + + waitOnFunctions(t, errc, len(newPets)) + + // Update all to active with the name gopherDan + for _, pet := range newPets { + go func(id int64) { + r, err := client.PetApi.UpdatePet(nil, sw.Pet{Id: (int64)(id), Name: "gopherDan", PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "active"}) + if r.StatusCode != 200 { + t.Log(r) + } + errc <- err + }(pet.Id) + } + waitOnFunctions(t, errc, len(newPets)) + + // Verify they are correct. + for _, pet := range newPets { + go func(pet sw.Pet) { + isPetCorrect(t, pet.Id, "gopherDan", "active") + errc <- nil + }(pet) + } + + waitOnFunctions(t, errc, len(newPets)) + + // Delete them all. + for _, pet := range newPets { + go func(id int64) { + deletePet(t, (int64)(id)) + errc <- nil + }(pet.Id) + } + waitOnFunctions(t, errc, len(newPets)) +} +*/ + +func waitOnFunctions(t *testing.T, errc chan error, n int) { + for i := 0; i < n; i++ { + err := <-errc + if err != nil { + t.Fatalf("Error performing concurrent test: %v", err) + } + } +} + +func deletePet(t *testing.T, id int64) { + r, err := client.PetApi.DeletePet(context.Background(), id, nil) + + if err != nil { + t.Fatalf("Error while deleting pet by id: %v", err) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + +func isPetCorrect(t *testing.T, id int64, name string, status string) { + assert := assert.New(t) + resp, r, err := client.PetApi.GetPetById(context.Background(), id) + if err != nil { + t.Fatalf("Error while getting pet by id: %v", err) + } else { + assert.Equal(resp.Id, int64(id), "Pet id should be equal") + assert.Equal(resp.Name, name, fmt.Sprintf("Pet name should be %s", name)) + assert.Equal(resp.Status, status, fmt.Sprintf("Pet status should be %s", status)) + + //t.Log(resp) + } + if r.StatusCode != 200 { + t.Log(r) + } +} + diff --git a/samples/openapi3/client/petstore/go/pom.xml b/samples/openapi3/client/petstore/go/pom.xml new file mode 100644 index 00000000000..222de294b3d --- /dev/null +++ b/samples/openapi3/client/petstore/go/pom.xml @@ -0,0 +1,103 @@ + + 4.0.0 + org.openapitools + GoOAS3Petstore + pom + 1.0.0 + Go OpenAPI3 Petstore Client + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + go-get-testify + pre-integration-test + + exec + + + go + + get + github.com/stretchr/testify/assert + + + + + go-get-oauth2 + pre-integration-test + + exec + + + go + + get + golang.org/x/oauth2 + + + + + go-get-context + pre-integration-test + + exec + + + go + + get + golang.org/x/net/context + + + + + go-get-optional + pre-integration-test + + exec + + + go + + get + github.com/antihax/optional + + + + + go-test + integration-test + + exec + + + go + + test + -v + + + + + + + + diff --git a/samples/openapi3/client/petstore/go/store_api_test.go b/samples/openapi3/client/petstore/go/store_api_test.go new file mode 100644 index 00000000000..3088adf7b40 --- /dev/null +++ b/samples/openapi3/client/petstore/go/store_api_test.go @@ -0,0 +1,37 @@ +package main + +import ( + "context" + "regexp" + "testing" + "time" + + sw "./go-petstore" +) + +func TestPlaceOrder(t *testing.T) { + newOrder := sw.Order{ + Id: 0, + PetId: 0, + Quantity: 0, + ShipDate: time.Now().UTC(), + Status: "placed", + Complete: false} + + _, r, err := client.StoreApi.PlaceOrder(context.Background(), newOrder) + + if err != nil { + // Skip parsing time error due to error in Petstore Test Server + // https://github.com/OpenAPITools/openapi-generator/issues/1292 + if regexp. + MustCompile(`^parsing time.+cannot parse "\+0000"" as "Z07:00"$`). + MatchString(err.Error()) { + t.Log("Skipping error for parsing time with `+0000` UTC offset as Petstore Test Server does not return valid RFC 3339 datetime") + } else { + t.Fatalf("Error while placing order: %v", err) + } + } + if r.StatusCode != 200 { + t.Log(r) + } +} diff --git a/samples/openapi3/client/petstore/go/testfiles/foo.png b/samples/openapi3/client/petstore/go/testfiles/foo.png new file mode 100644 index 00000000000..a9b12cf5927 Binary files /dev/null and b/samples/openapi3/client/petstore/go/testfiles/foo.png differ diff --git a/samples/openapi3/client/petstore/go/user_api_test.go b/samples/openapi3/client/petstore/go/user_api_test.go new file mode 100644 index 00000000000..012c608fab6 --- /dev/null +++ b/samples/openapi3/client/petstore/go/user_api_test.go @@ -0,0 +1,153 @@ +package main + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + + sw "./go-petstore" +) + +func TestCreateUser(t *testing.T) { + newUser := sw.User{ + Id: 1000, + FirstName: "gopher", + LastName: "lang", + Username: "gopher", + Password: "lang", + Email: "lang@test.com", + Phone: "5101112222", + UserStatus: 1} + + apiResponse, err := client.UserApi.CreateUser(context.Background(), newUser) + + if err != nil { + t.Fatalf("Error while adding user: %v", err) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } +} + +//adding x to skip the test, currently it is failing +func TestCreateUsersWithArrayInput(t *testing.T) { + newUsers := []sw.User{ + sw.User{ + Id: int64(1001), + FirstName: "gopher1", + LastName: "lang1", + Username: "gopher1", + Password: "lang1", + Email: "lang1@test.com", + Phone: "5101112222", + UserStatus: int32(1), + }, + sw.User{ + Id: int64(1002), + FirstName: "gopher2", + LastName: "lang2", + Username: "gopher2", + Password: "lang2", + Email: "lang2@test.com", + Phone: "5101112222", + UserStatus: int32(1), + }, + } + + apiResponse, err := client.UserApi.CreateUsersWithArrayInput(context.Background(), newUsers) + if err != nil { + t.Fatalf("Error while adding users: %v", err) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } + + //tear down + _, err1 := client.UserApi.DeleteUser(context.Background(), "gopher1") + if err1 != nil { + t.Errorf("Error while deleting user") + t.Log(err1) + } + + _, err2 := client.UserApi.DeleteUser(context.Background(), "gopher2") + if err2 != nil { + t.Errorf("Error while deleting user") + t.Log(err2) + } +} + +func TestGetUserByName(t *testing.T) { + assert := assert.New(t) + + resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "gopher") + if err != nil { + t.Fatalf("Error while getting user by id: %v", err) + } else { + assert.Equal(resp.Id, int64(1000), "User id should be equal") + assert.Equal(resp.Username, "gopher", "User name should be gopher") + assert.Equal(resp.LastName, "lang", "Last name should be lang") + //t.Log(resp) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } +} + +func TestGetUserByNameWithInvalidID(t *testing.T) { + resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "999999999") + if apiResponse != nil && apiResponse.StatusCode == 404 { + return // This is a pass condition. API will return with a 404 error. + } else if err != nil { + t.Fatalf("Error while getting user by invalid id: %v", err) + t.Log(apiResponse) + } else { + t.Log(resp) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } +} + +func TestUpdateUser(t *testing.T) { + assert := assert.New(t) + + newUser := sw.User{ + Id: 1000, + FirstName: "gopher20", + LastName: "lang20", + Username: "gopher", + Password: "lang", + Email: "lang@test.com", + Phone: "5101112222", + UserStatus: 1} + + apiResponse, err := client.UserApi.UpdateUser(context.Background(), "gopher", newUser) + if err != nil { + t.Fatalf("Error while deleting user by id: %v", err) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } + + //verify changings are correct + resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "gopher") + if err != nil { + t.Fatalf("Error while getting user by id: %v", err) + } else { + assert.Equal(resp.Id, int64(1000), "User id should be equal") + assert.Equal(resp.FirstName, "gopher20", "User name should be gopher") + assert.Equal(resp.Password, "lang", "User name should be the same") + } +} + +func TestDeleteUser(t *testing.T) { + apiResponse, err := client.UserApi.DeleteUser(context.Background(), "gopher") + + if err != nil { + t.Fatalf("Error while deleting user: %v", err) + } + if apiResponse.StatusCode != 200 { + t.Log(apiResponse) + } +}