diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java index 7ce6d2e191c7..b7bd85aa43a7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java @@ -464,7 +464,7 @@ private String constructExampleCode(CodegenParameter codegenParameter, HashMap modelMaps, HashMap processedModelMap) { if (codegenProperty.isListContainer) { // array - return codegenProperty.dataType + "{" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + ")"; + return codegenProperty.dataType + "{" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}"; } else if (codegenProperty.isMap) { // map - return "map[string]string{ \"Key\" = \"Value\" }"; + return codegenProperty.dataType + "{ \"key\": " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}"; } else if (codegenProperty.isPrimitiveType) { // primitive type if (codegenProperty.isString) { if (StringUtils.isEmpty(codegenProperty.example)) { @@ -519,7 +519,7 @@ private String constructExampleCode(CodegenProperty codegenProperty, HashMap propertyExamples = new ArrayList<>(); - for (CodegenProperty codegenProperty : codegenModel.allVars) { - propertyExamples.add(codegenProperty.name + ": " + constructExampleCode(codegenProperty, modelMaps, processedModelMap)); + for (CodegenProperty codegenProperty : codegenModel.requiredVars) { + propertyExamples.add(constructExampleCode(codegenProperty, modelMaps, processedModelMap)); } - example += StringUtils.join(propertyExamples, ", "); - example += "}"; - return example; + return "*" + goImportAlias + ".New" + codegenModel.name + "(" + StringUtils.join(propertyExamples, ", ") + ")"; } } diff --git a/samples/client/petstore/go/go-petstore/docs/AnotherFakeApi.md b/samples/client/petstore/go/go-petstore/docs/AnotherFakeApi.md index 34b688fc734f..6243abe3c4d7 100644 --- a/samples/client/petstore/go/go-petstore/docs/AnotherFakeApi.md +++ b/samples/client/petstore/go/go-petstore/docs/AnotherFakeApi.md @@ -29,7 +29,7 @@ import ( ) func main() { - body := openapiclient.Client{Client: "Client_example"} // Client | client model + body := *openapiclient.NewClient() // Client | client model configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/client/petstore/go/go-petstore/docs/FakeApi.md b/samples/client/petstore/go/go-petstore/docs/FakeApi.md index 6a627902f9b5..0b26ad9d210b 100644 --- a/samples/client/petstore/go/go-petstore/docs/FakeApi.md +++ b/samples/client/petstore/go/go-petstore/docs/FakeApi.md @@ -42,7 +42,7 @@ import ( ) func main() { - xmlItem := openapiclient.XmlItem{AttributeString: "AttributeString_example", AttributeNumber: 123, AttributeInteger: 123, AttributeBoolean: true, WrappedArray: []int32{123), NameString: "NameString_example", NameNumber: 123, NameInteger: 123, NameBoolean: true, NameArray: []int32{123), NameWrappedArray: []int32{123), PrefixString: "PrefixString_example", PrefixNumber: 123, PrefixInteger: 123, PrefixBoolean: true, PrefixArray: []int32{123), PrefixWrappedArray: []int32{123), NamespaceString: "NamespaceString_example", NamespaceNumber: 123, NamespaceInteger: 123, NamespaceBoolean: true, NamespaceArray: []int32{123), NamespaceWrappedArray: []int32{123), PrefixNsString: "PrefixNsString_example", PrefixNsNumber: 123, PrefixNsInteger: 123, PrefixNsBoolean: true, PrefixNsArray: []int32{123), PrefixNsWrappedArray: []int32{123)} // XmlItem | XmlItem Body + xmlItem := *openapiclient.NewXmlItem() // XmlItem | XmlItem Body configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -172,7 +172,7 @@ import ( ) func main() { - body := openapiclient.OuterComposite{MyNumber: 123, MyString: "MyString_example", MyBoolean: false} // OuterComposite | Input composite as post body (optional) + body := *openapiclient.NewOuterComposite() // OuterComposite | Input composite as post body (optional) configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -370,7 +370,7 @@ import ( ) func main() { - body := openapiclient.FileSchemaTestClass{File: openapiclient.File{SourceURI: "SourceURI_example"}, Files: []File{openapiclient.File{SourceURI: "SourceURI_example"})} // FileSchemaTestClass | + body := *openapiclient.NewFileSchemaTestClass() // FileSchemaTestClass | configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -433,7 +433,7 @@ import ( func main() { query := "query_example" // string | - body := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123} // User | + body := *openapiclient.NewUser() // User | configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -498,7 +498,7 @@ import ( ) func main() { - body := openapiclient.Client{Client: "Client_example"} // Client | client model + body := *openapiclient.NewClient() // Client | client model configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -574,8 +574,8 @@ func main() { float := 987 // float32 | None (optional) string_ := "string__example" // string | None (optional) binary := 987 // *os.File | None (optional) - date := Get-Date // string | None (optional) - dateTime := Get-Date // time.Time | None (optional) + date := time.Now() // string | None (optional) + dateTime := time.Now() // time.Time | None (optional) password := "password_example" // string | None (optional) callback := "callback_example" // string | None (optional) @@ -804,7 +804,7 @@ import ( ) func main() { - param := map[string]string{ "Key" = "Value" } // map[string]string | request body + param := map[string]string{ "key": "Inner_example"} // map[string]string | request body configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md b/samples/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md index 2bc39f0bcb68..b206d05d09c7 100644 --- a/samples/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md +++ b/samples/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md @@ -29,7 +29,7 @@ import ( ) func main() { - body := openapiclient.Client{Client: "Client_example"} // Client | client model + body := *openapiclient.NewClient() // Client | client model configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/client/petstore/go/go-petstore/docs/PetApi.md b/samples/client/petstore/go/go-petstore/docs/PetApi.md index e94f6bfa28a2..0eee7dd8be77 100644 --- a/samples/client/petstore/go/go-petstore/docs/PetApi.md +++ b/samples/client/petstore/go/go-petstore/docs/PetApi.md @@ -35,7 +35,7 @@ import ( ) func main() { - body := openapiclient.Pet{Id: int64(123), Category: openapiclient.Category{Id: int64(123), Name: "Name_example"}, Name: "Name_example", PhotoUrls: []string{"PhotoUrls_example"), Tags: []Tag{openapiclient.Tag{Id: int64(123), Name: "Name_example"}), Status: "Status_example"} // Pet | Pet object that needs to be added to the store + body := *openapiclient.NewPet("Name_example", []string{"PhotoUrls_example"}) // Pet | Pet object that needs to be added to the store configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -367,7 +367,7 @@ import ( ) func main() { - body := openapiclient.Pet{Id: int64(123), Category: openapiclient.Category{Id: int64(123), Name: "Name_example"}, Name: "Name_example", PhotoUrls: []string{"PhotoUrls_example"), Tags: []Tag{openapiclient.Tag{Id: int64(123), Name: "Name_example"}), Status: "Status_example"} // Pet | Pet object that needs to be added to the store + body := *openapiclient.NewPet("Name_example", []string{"PhotoUrls_example"}) // Pet | Pet object that needs to be added to the store configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/client/petstore/go/go-petstore/docs/StoreApi.md b/samples/client/petstore/go/go-petstore/docs/StoreApi.md index bc0ac9b80294..0e9c4a8ec558 100644 --- a/samples/client/petstore/go/go-petstore/docs/StoreApi.md +++ b/samples/client/petstore/go/go-petstore/docs/StoreApi.md @@ -229,7 +229,7 @@ import ( ) func main() { - body := openapiclient.Order{Id: int64(123), PetId: int64(123), Quantity: 123, ShipDate: "TODO", Status: "Status_example", Complete: false} // Order | order placed for purchasing the pet + body := *openapiclient.NewOrder() // Order | order placed for purchasing the pet configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/client/petstore/go/go-petstore/docs/UserApi.md b/samples/client/petstore/go/go-petstore/docs/UserApi.md index 5df5e7335898..9eccb9144d03 100644 --- a/samples/client/petstore/go/go-petstore/docs/UserApi.md +++ b/samples/client/petstore/go/go-petstore/docs/UserApi.md @@ -36,7 +36,7 @@ import ( ) func main() { - body := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123} // User | Created user object + body := *openapiclient.NewUser() // User | Created user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -98,7 +98,7 @@ import ( ) func main() { - body := []User{openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123}} // []User | List of user object + body := []User{*openapiclient.NewUser()} // []User | List of user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/AnotherFakeApi.md b/samples/openapi3/client/petstore/go/go-petstore/docs/AnotherFakeApi.md index 90e9fe7f08eb..cd383de7c66c 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/AnotherFakeApi.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/AnotherFakeApi.md @@ -29,7 +29,7 @@ import ( ) func main() { - client := openapiclient.Client{Client: "Client_example"} // Client | client model + client := *openapiclient.NewClient() // Client | client model configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/FakeApi.md b/samples/openapi3/client/petstore/go/go-petstore/docs/FakeApi.md index 76e258a8da8f..2380fafb0dd0 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/FakeApi.md @@ -167,7 +167,7 @@ import ( ) func main() { - outerComposite := openapiclient.OuterComposite{MyNumber: 123, MyString: "MyString_example", MyBoolean: false} // OuterComposite | Input composite as post body (optional) + outerComposite := *openapiclient.NewOuterComposite() // OuterComposite | Input composite as post body (optional) configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -365,7 +365,7 @@ import ( ) func main() { - fileSchemaTestClass := openapiclient.FileSchemaTestClass{File: openapiclient.File{SourceURI: "SourceURI_example"}, Files: []File{openapiclient.File{SourceURI: "SourceURI_example"})} // FileSchemaTestClass | + fileSchemaTestClass := *openapiclient.NewFileSchemaTestClass() // FileSchemaTestClass | configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -428,7 +428,7 @@ import ( func main() { query := "query_example" // string | - user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ArbitraryObject: 123, ArbitraryNullableObject: 123, ArbitraryTypeValue: 123, ArbitraryNullableTypeValue: 123} // User | + user := *openapiclient.NewUser() // User | configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -493,7 +493,7 @@ import ( ) func main() { - client := openapiclient.Client{Client: "Client_example"} // Client | client model + client := *openapiclient.NewClient() // Client | client model configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -569,8 +569,8 @@ func main() { float := 987 // float32 | None (optional) string_ := "string__example" // string | None (optional) binary := 987 // *os.File | None (optional) - date := Get-Date // string | None (optional) - dateTime := Get-Date // time.Time | None (optional) + date := time.Now() // string | None (optional) + dateTime := time.Now() // time.Time | None (optional) password := "password_example" // string | None (optional) callback := "callback_example" // string | None (optional) @@ -799,7 +799,7 @@ import ( ) func main() { - requestBody := map[string]string{ "Key" = "Value" } // map[string]string | request body + requestBody := map[string]string{ "key": "Inner_example"} // map[string]string | request body configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md b/samples/openapi3/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md index aaadff4ad114..27a260ff8130 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/FakeClassnameTags123Api.md @@ -29,7 +29,7 @@ import ( ) func main() { - client := openapiclient.Client{Client: "Client_example"} // Client | client model + client := *openapiclient.NewClient() // Client | client model configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/PetApi.md b/samples/openapi3/client/petstore/go/go-petstore/docs/PetApi.md index b4ad71ad07cf..8e9728e0d2bd 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/PetApi.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/PetApi.md @@ -35,7 +35,7 @@ import ( ) func main() { - pet := openapiclient.Pet{Id: int64(123), Category: openapiclient.Category{Id: int64(123), Name: "Name_example"}, Name: "Name_example", PhotoUrls: []string{"PhotoUrls_example"), Tags: []Tag{openapiclient.Tag{Id: int64(123), Name: "Name_example"}), Status: "Status_example"} // Pet | Pet object that needs to be added to the store + pet := *openapiclient.NewPet("Name_example", []string{"PhotoUrls_example"}) // Pet | Pet object that needs to be added to the store configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -367,7 +367,7 @@ import ( ) func main() { - pet := openapiclient.Pet{Id: int64(123), Category: openapiclient.Category{Id: int64(123), Name: "Name_example"}, Name: "Name_example", PhotoUrls: []string{"PhotoUrls_example"), Tags: []Tag{openapiclient.Tag{Id: int64(123), Name: "Name_example"}), Status: "Status_example"} // Pet | Pet object that needs to be added to the store + pet := *openapiclient.NewPet("Name_example", []string{"PhotoUrls_example"}) // Pet | Pet object that needs to be added to the store configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/StoreApi.md b/samples/openapi3/client/petstore/go/go-petstore/docs/StoreApi.md index 1702bf74223d..097fac90ec99 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/StoreApi.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/StoreApi.md @@ -229,7 +229,7 @@ import ( ) func main() { - order := openapiclient.Order{Id: int64(123), PetId: int64(123), Quantity: 123, ShipDate: "TODO", Status: "Status_example", Complete: false} // Order | order placed for purchasing the pet + order := *openapiclient.NewOrder() // Order | order placed for purchasing the pet configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/UserApi.md b/samples/openapi3/client/petstore/go/go-petstore/docs/UserApi.md index 8354066eab4b..4c89c0be9276 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/UserApi.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/UserApi.md @@ -36,7 +36,7 @@ import ( ) func main() { - user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ArbitraryObject: 123, ArbitraryNullableObject: 123, ArbitraryTypeValue: 123, ArbitraryNullableTypeValue: 123} // User | Created user object + user := *openapiclient.NewUser() // User | Created user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -98,7 +98,7 @@ import ( ) func main() { - user := []User{openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ArbitraryObject: 123, ArbitraryNullableObject: 123, ArbitraryTypeValue: 123, ArbitraryNullableTypeValue: 123}} // []User | List of user object + user := []User{*openapiclient.NewUser()} // []User | List of user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration)