diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index fc2a254585ba..415912c4ae79 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -800,6 +800,9 @@ public ModelsMap postProcessModels(ModelsMap objs) { if (withXml) { goDataTag += " xml:" + "\"" + cp.baseName; + if (cp.isXmlWrapped) { + goDataTag += ">" + ("".equals(cp.xmlName) ? cp.baseName : cp.xmlName); + } if (cp.isXmlAttribute) { goDataTag += ",attr"; } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java index 15140317d543..155af6dd84dc 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java @@ -396,4 +396,26 @@ public void testAdditionalPropertiesWithoutGoMod() throws Exception { Path goSumFile = Paths.get(output + "/go.sum"); TestUtils.assertFileNotExists(goSumFile); } + + @Test + public void testXmlOptionsBeingUsed() throws IOException { + Map properties = new HashMap<>(); + properties.put(GoClientCodegen.STRUCT_PREFIX, true); + properties.put(GoClientCodegen.WITH_XML, true); + + File output = Files.createTempDirectory("test").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("go") + .setAdditionalProperties(properties) + .setInputSpec("src/test/resources/3_0/petstore.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + + TestUtils.assertFileContains(Paths.get(output + "/model_pet.go"), "tags>tag"); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index faed76ea4927..515efb805b7d 100644 --- a/modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1887,6 +1887,25 @@ components: type: array items: $ref: '#/components/schemas/ReadOnlyFirst' + ArrayTestWithWrapped: + type: object + properties: + array_of_string: + type: array + items: + type: string + xml: + wrapped: true + ArrayTestWithWrappedAndName: + type: object + properties: + array_of_string: + type: array + items: + type: string + xml: + name: item + wrapped: true NumberOnly: type: object properties: diff --git a/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES b/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES index e6cac5bc3f30..f10cb891f5b8 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES @@ -22,6 +22,8 @@ docs/AppleReq.md docs/ArrayOfArrayOfNumberOnly.md docs/ArrayOfNumberOnly.md docs/ArrayTest.md +docs/ArrayTestWithWrapped.md +docs/ArrayTestWithWrappedAndName.md docs/Banana.md docs/BananaReq.md docs/Capitalization.md @@ -106,6 +108,8 @@ model_apple_req.go model_array_of_array_of_number_only.go model_array_of_number_only.go model_array_test_.go +model_array_test_with_wrapped.go +model_array_test_with_wrapped_and_name.go model_banana.go model_banana_req.go model_capitalization.go diff --git a/samples/openapi3/client/petstore/go/go-petstore/README.md b/samples/openapi3/client/petstore/go/go-petstore/README.md index 3cddf2bcda66..6a7b01c678b9 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/README.md +++ b/samples/openapi3/client/petstore/go/go-petstore/README.md @@ -139,6 +139,8 @@ Class | Method | HTTP request | Description - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) - [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md) - [ArrayTest](docs/ArrayTest.md) + - [ArrayTestWithWrapped](docs/ArrayTestWithWrapped.md) + - [ArrayTestWithWrappedAndName](docs/ArrayTestWithWrappedAndName.md) - [Banana](docs/Banana.md) - [BananaReq](docs/BananaReq.md) - [Capitalization](docs/Capitalization.md) diff --git a/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml index 2ee0e78cdfb9..5fff70d93fdf 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml @@ -1852,6 +1852,25 @@ components: type: array type: array type: object + ArrayTestWithWrapped: + properties: + array_of_string: + items: + type: string + type: array + xml: + wrapped: true + type: object + ArrayTestWithWrappedAndName: + properties: + array_of_string: + items: + type: string + type: array + xml: + name: item + wrapped: true + type: object NumberOnly: properties: JustNumber: diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/ArrayTestWithWrapped.md b/samples/openapi3/client/petstore/go/go-petstore/docs/ArrayTestWithWrapped.md new file mode 100644 index 000000000000..5fb41f27c348 --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/ArrayTestWithWrapped.md @@ -0,0 +1,56 @@ +# ArrayTestWithWrapped + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**ArrayOfString** | Pointer to **[]string** | | [optional] + +## Methods + +### NewArrayTestWithWrapped + +`func NewArrayTestWithWrapped() *ArrayTestWithWrapped` + +NewArrayTestWithWrapped instantiates a new ArrayTestWithWrapped object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewArrayTestWithWrappedWithDefaults + +`func NewArrayTestWithWrappedWithDefaults() *ArrayTestWithWrapped` + +NewArrayTestWithWrappedWithDefaults instantiates a new ArrayTestWithWrapped object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetArrayOfString + +`func (o *ArrayTestWithWrapped) GetArrayOfString() []string` + +GetArrayOfString returns the ArrayOfString field if non-nil, zero value otherwise. + +### GetArrayOfStringOk + +`func (o *ArrayTestWithWrapped) GetArrayOfStringOk() (*[]string, bool)` + +GetArrayOfStringOk returns a tuple with the ArrayOfString field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetArrayOfString + +`func (o *ArrayTestWithWrapped) SetArrayOfString(v []string)` + +SetArrayOfString sets ArrayOfString field to given value. + +### HasArrayOfString + +`func (o *ArrayTestWithWrapped) HasArrayOfString() bool` + +HasArrayOfString returns a boolean if a field has been set. + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/ArrayTestWithWrappedAndName.md b/samples/openapi3/client/petstore/go/go-petstore/docs/ArrayTestWithWrappedAndName.md new file mode 100644 index 000000000000..592bad04bc53 --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/ArrayTestWithWrappedAndName.md @@ -0,0 +1,56 @@ +# ArrayTestWithWrappedAndName + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**ArrayOfString** | Pointer to **[]string** | | [optional] + +## Methods + +### NewArrayTestWithWrappedAndName + +`func NewArrayTestWithWrappedAndName() *ArrayTestWithWrappedAndName` + +NewArrayTestWithWrappedAndName instantiates a new ArrayTestWithWrappedAndName object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewArrayTestWithWrappedAndNameWithDefaults + +`func NewArrayTestWithWrappedAndNameWithDefaults() *ArrayTestWithWrappedAndName` + +NewArrayTestWithWrappedAndNameWithDefaults instantiates a new ArrayTestWithWrappedAndName object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + +### GetArrayOfString + +`func (o *ArrayTestWithWrappedAndName) GetArrayOfString() []string` + +GetArrayOfString returns the ArrayOfString field if non-nil, zero value otherwise. + +### GetArrayOfStringOk + +`func (o *ArrayTestWithWrappedAndName) GetArrayOfStringOk() (*[]string, bool)` + +GetArrayOfStringOk returns a tuple with the ArrayOfString field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetArrayOfString + +`func (o *ArrayTestWithWrappedAndName) SetArrayOfString(v []string)` + +SetArrayOfString sets ArrayOfString field to given value. + +### HasArrayOfString + +`func (o *ArrayTestWithWrappedAndName) HasArrayOfString() bool` + +HasArrayOfString returns a boolean if a field has been set. + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_array_test_with_wrapped.go b/samples/openapi3/client/petstore/go/go-petstore/model_array_test_with_wrapped.go new file mode 100644 index 000000000000..4ca83977f23c --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/model_array_test_with_wrapped.go @@ -0,0 +1,155 @@ +/* +OpenAPI 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: \" \\ + +API version: 1.0.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package petstore + +import ( + "encoding/json" +) + +// checks if the ArrayTestWithWrapped type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ArrayTestWithWrapped{} + +// ArrayTestWithWrapped struct for ArrayTestWithWrapped +type ArrayTestWithWrapped struct { + ArrayOfString []string `json:"array_of_string,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _ArrayTestWithWrapped ArrayTestWithWrapped + +// NewArrayTestWithWrapped instantiates a new ArrayTestWithWrapped object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewArrayTestWithWrapped() *ArrayTestWithWrapped { + this := ArrayTestWithWrapped{} + return &this +} + +// NewArrayTestWithWrappedWithDefaults instantiates a new ArrayTestWithWrapped object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewArrayTestWithWrappedWithDefaults() *ArrayTestWithWrapped { + this := ArrayTestWithWrapped{} + return &this +} + +// GetArrayOfString returns the ArrayOfString field value if set, zero value otherwise. +func (o *ArrayTestWithWrapped) GetArrayOfString() []string { + if o == nil || IsNil(o.ArrayOfString) { + var ret []string + return ret + } + return o.ArrayOfString +} + +// GetArrayOfStringOk returns a tuple with the ArrayOfString field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ArrayTestWithWrapped) GetArrayOfStringOk() ([]string, bool) { + if o == nil || IsNil(o.ArrayOfString) { + return nil, false + } + return o.ArrayOfString, true +} + +// HasArrayOfString returns a boolean if a field has been set. +func (o *ArrayTestWithWrapped) HasArrayOfString() bool { + if o != nil && !IsNil(o.ArrayOfString) { + return true + } + + return false +} + +// SetArrayOfString gets a reference to the given []string and assigns it to the ArrayOfString field. +func (o *ArrayTestWithWrapped) SetArrayOfString(v []string) { + o.ArrayOfString = v +} + +func (o ArrayTestWithWrapped) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ArrayTestWithWrapped) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.ArrayOfString) { + toSerialize["array_of_string"] = o.ArrayOfString + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ArrayTestWithWrapped) UnmarshalJSON(data []byte) (err error) { + varArrayTestWithWrapped := _ArrayTestWithWrapped{} + + err = json.Unmarshal(data, &varArrayTestWithWrapped) + + if err != nil { + return err + } + + *o = ArrayTestWithWrapped(varArrayTestWithWrapped) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "array_of_string") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableArrayTestWithWrapped struct { + value *ArrayTestWithWrapped + isSet bool +} + +func (v NullableArrayTestWithWrapped) Get() *ArrayTestWithWrapped { + return v.value +} + +func (v *NullableArrayTestWithWrapped) Set(val *ArrayTestWithWrapped) { + v.value = val + v.isSet = true +} + +func (v NullableArrayTestWithWrapped) IsSet() bool { + return v.isSet +} + +func (v *NullableArrayTestWithWrapped) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableArrayTestWithWrapped(val *ArrayTestWithWrapped) *NullableArrayTestWithWrapped { + return &NullableArrayTestWithWrapped{value: val, isSet: true} +} + +func (v NullableArrayTestWithWrapped) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableArrayTestWithWrapped) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_array_test_with_wrapped_and_name.go b/samples/openapi3/client/petstore/go/go-petstore/model_array_test_with_wrapped_and_name.go new file mode 100644 index 000000000000..786d573d0796 --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/model_array_test_with_wrapped_and_name.go @@ -0,0 +1,155 @@ +/* +OpenAPI 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: \" \\ + +API version: 1.0.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package petstore + +import ( + "encoding/json" +) + +// checks if the ArrayTestWithWrappedAndName type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ArrayTestWithWrappedAndName{} + +// ArrayTestWithWrappedAndName struct for ArrayTestWithWrappedAndName +type ArrayTestWithWrappedAndName struct { + ArrayOfString []string `json:"array_of_string,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _ArrayTestWithWrappedAndName ArrayTestWithWrappedAndName + +// NewArrayTestWithWrappedAndName instantiates a new ArrayTestWithWrappedAndName object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewArrayTestWithWrappedAndName() *ArrayTestWithWrappedAndName { + this := ArrayTestWithWrappedAndName{} + return &this +} + +// NewArrayTestWithWrappedAndNameWithDefaults instantiates a new ArrayTestWithWrappedAndName object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewArrayTestWithWrappedAndNameWithDefaults() *ArrayTestWithWrappedAndName { + this := ArrayTestWithWrappedAndName{} + return &this +} + +// GetArrayOfString returns the ArrayOfString field value if set, zero value otherwise. +func (o *ArrayTestWithWrappedAndName) GetArrayOfString() []string { + if o == nil || IsNil(o.ArrayOfString) { + var ret []string + return ret + } + return o.ArrayOfString +} + +// GetArrayOfStringOk returns a tuple with the ArrayOfString field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ArrayTestWithWrappedAndName) GetArrayOfStringOk() ([]string, bool) { + if o == nil || IsNil(o.ArrayOfString) { + return nil, false + } + return o.ArrayOfString, true +} + +// HasArrayOfString returns a boolean if a field has been set. +func (o *ArrayTestWithWrappedAndName) HasArrayOfString() bool { + if o != nil && !IsNil(o.ArrayOfString) { + return true + } + + return false +} + +// SetArrayOfString gets a reference to the given []string and assigns it to the ArrayOfString field. +func (o *ArrayTestWithWrappedAndName) SetArrayOfString(v []string) { + o.ArrayOfString = v +} + +func (o ArrayTestWithWrappedAndName) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ArrayTestWithWrappedAndName) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.ArrayOfString) { + toSerialize["array_of_string"] = o.ArrayOfString + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ArrayTestWithWrappedAndName) UnmarshalJSON(data []byte) (err error) { + varArrayTestWithWrappedAndName := _ArrayTestWithWrappedAndName{} + + err = json.Unmarshal(data, &varArrayTestWithWrappedAndName) + + if err != nil { + return err + } + + *o = ArrayTestWithWrappedAndName(varArrayTestWithWrappedAndName) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "array_of_string") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableArrayTestWithWrappedAndName struct { + value *ArrayTestWithWrappedAndName + isSet bool +} + +func (v NullableArrayTestWithWrappedAndName) Get() *ArrayTestWithWrappedAndName { + return v.value +} + +func (v *NullableArrayTestWithWrappedAndName) Set(val *ArrayTestWithWrappedAndName) { + v.value = val + v.isSet = true +} + +func (v NullableArrayTestWithWrappedAndName) IsSet() bool { + return v.isSet +} + +func (v *NullableArrayTestWithWrappedAndName) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableArrayTestWithWrappedAndName(val *ArrayTestWithWrappedAndName) *NullableArrayTestWithWrappedAndName { + return &NullableArrayTestWithWrappedAndName{value: val, isSet: true} +} + +func (v NullableArrayTestWithWrappedAndName) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableArrayTestWithWrappedAndName) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +