From a6bf956df5bd0b5eae0b7f70c1e6c044845eb798 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 4 Jun 2020 11:33:21 +0800 Subject: [PATCH] [Go][Experimental] Support additionalProperties (#6525) * support additonal properties in go * support additonal properties marshal in go exp * update go samples --- .../GoClientExperimentalCodegen.java | 7 +++- .../go-experimental/model_simple.mustache | 37 ++++++++++++++++++- ...odels-for-testing-with-http-signature.yaml | 1 + .../go-petstore/model_200_response.go | 1 + .../model_additional_properties_any_type.go | 26 +++++++++++++ .../model_additional_properties_array.go | 1 + .../model_additional_properties_boolean.go | 1 + .../model_additional_properties_class.go | 1 + .../model_additional_properties_integer.go | 1 + .../model_additional_properties_number.go | 1 + .../model_additional_properties_object.go | 1 + .../model_additional_properties_string.go | 1 + .../go-petstore/model_animal.go | 1 + .../go-petstore/model_api_response.go | 1 + .../model_array_of_array_of_number_only.go | 1 + .../go-petstore/model_array_of_number_only.go | 1 + .../go-petstore/model_array_test_.go | 1 + .../go-petstore/model_big_cat.go | 1 + .../go-petstore/model_big_cat_all_of.go | 1 + .../go-petstore/model_capitalization.go | 1 + .../go-experimental/go-petstore/model_cat.go | 1 + .../go-petstore/model_cat_all_of.go | 1 + .../go-petstore/model_category.go | 1 + .../go-petstore/model_class_model.go | 1 + .../go-petstore/model_client.go | 1 + .../go-experimental/go-petstore/model_dog.go | 1 + .../go-petstore/model_dog_all_of.go | 1 + .../go-petstore/model_enum_arrays.go | 1 + .../go-petstore/model_enum_test_.go | 1 + .../go-experimental/go-petstore/model_file.go | 1 + .../model_file_schema_test_class.go | 1 + .../go-petstore/model_format_test_.go | 1 + .../go-petstore/model_has_only_read_only.go | 1 + .../go-experimental/go-petstore/model_list.go | 1 + .../go-petstore/model_map_test_.go | 1 + ...perties_and_additional_properties_class.go | 1 + .../go-experimental/go-petstore/model_name.go | 1 + .../go-petstore/model_number_only.go | 1 + .../go-petstore/model_order.go | 1 + .../go-petstore/model_outer_composite.go | 1 + .../go-experimental/go-petstore/model_pet.go | 1 + .../go-petstore/model_read_only_first.go | 1 + .../go-petstore/model_return.go | 1 + .../go-petstore/model_special_model_name.go | 1 + .../go-experimental/go-petstore/model_tag.go | 1 + .../go-petstore/model_type_holder_default.go | 1 + .../go-petstore/model_type_holder_example.go | 1 + .../go-experimental/go-petstore/model_user.go | 1 + .../go-petstore/model_xml_item.go | 1 + .../go-petstore/api/openapi.yaml | 1 + .../go-petstore/model_200_response.go | 1 + .../go-petstore/model__special_model_name_.go | 1 + .../model_additional_properties_class.go | 1 + .../go-petstore/model_animal.go | 1 + .../go-petstore/model_api_response.go | 1 + .../go-petstore/model_apple.go | 1 + .../go-petstore/model_apple_req.go | 1 + .../model_array_of_array_of_number_only.go | 1 + .../go-petstore/model_array_of_number_only.go | 1 + .../go-petstore/model_array_test_.go | 1 + .../go-petstore/model_banana.go | 26 +++++++++++++ .../go-petstore/model_banana_req.go | 1 + .../go-petstore/model_capitalization.go | 1 + .../go-experimental/go-petstore/model_cat.go | 1 + .../go-petstore/model_cat_all_of.go | 1 + .../go-petstore/model_category.go | 1 + .../go-petstore/model_class_model.go | 1 + .../go-petstore/model_client.go | 1 + .../go-experimental/go-petstore/model_dog.go | 1 + .../go-petstore/model_dog_all_of.go | 1 + .../go-petstore/model_enum_arrays.go | 1 + .../go-petstore/model_enum_test_.go | 1 + .../go-experimental/go-petstore/model_file.go | 1 + .../model_file_schema_test_class.go | 1 + .../go-experimental/go-petstore/model_foo.go | 1 + .../go-petstore/model_format_test_.go | 1 + .../go-petstore/model_has_only_read_only.go | 1 + .../go-petstore/model_health_check_result.go | 1 + .../go-petstore/model_inline_object.go | 1 + .../go-petstore/model_inline_object_1.go | 1 + .../go-petstore/model_inline_object_2.go | 1 + .../go-petstore/model_inline_object_3.go | 1 + .../go-petstore/model_inline_object_4.go | 1 + .../go-petstore/model_inline_object_5.go | 1 + .../model_inline_response_default.go | 1 + .../go-experimental/go-petstore/model_list.go | 1 + .../go-petstore/model_map_test_.go | 1 + ...perties_and_additional_properties_class.go | 1 + .../go-experimental/go-petstore/model_name.go | 1 + .../go-petstore/model_nullable_class.go | 37 +++++++++++++++++++ .../go-petstore/model_number_only.go | 1 + .../go-petstore/model_order.go | 1 + .../go-petstore/model_outer_composite.go | 1 + .../go-experimental/go-petstore/model_pet.go | 1 + .../go-petstore/model_read_only_first.go | 1 + .../go-petstore/model_return.go | 1 + .../go-experimental/go-petstore/model_tag.go | 1 + .../go-experimental/go-petstore/model_user.go | 1 + .../go-petstore/model_whale.go | 1 + .../go-petstore/model_zebra.go | 1 + .../petstore/go-experimental/model_test.go | 34 +++++++++++++++++ 101 files changed, 259 insertions(+), 3 deletions(-) create mode 100644 samples/openapi3/client/petstore/go-experimental/model_test.go 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 ddb10684f2a0..b9e9fbedbec2 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 @@ -222,9 +222,12 @@ public Map postProcessModels(Map objs) { if (model.anyOf != null && !model.anyOf.isEmpty()) { imports.add(createMapping("import", "fmt")); } - } - + // add x-additional-properties + if ("map[string]map[string]interface{}".equals(model.parent)) { + model.vendorExtensions.put("x-additional-properties", true); + } + } } return objs; } diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache index 1078787c86dd..c4d8d5f684f3 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache @@ -13,8 +13,15 @@ type {{classname}} struct { {{/description}} {{name}} {{^required}}{{^isNullable}}*{{/isNullable}}{{/required}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` {{/vars}} +{{#vendorExtensions.x-additional-properties}} + AdditionalProperties map[string]interface{} +{{/vendorExtensions.x-additional-properties}} } +{{#vendorExtensions.x-additional-properties}} +type _{{{classname}}} {{{classname}}} + +{{/vendorExtensions.x-additional-properties}} // New{{classname}} instantiates a new {{classname}} 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 @@ -246,7 +253,35 @@ func (o {{classname}}) MarshalJSON() ([]byte, error) { } {{/isNullable}} {{/vars}} + {{#vendorExtensions.x-additional-properties}} + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + {{/vendorExtensions.x-additional-properties}} return json.Marshal(toSerialize) } -{{>nullable_model}} \ No newline at end of file +{{#vendorExtensions.x-additional-properties}} +func (o *{{{classname}}}) UnmarshalJSON(bytes []byte) (err error) { + var{{{classname}}} := _{{{classname}}}{} + + if err = json.Unmarshal(bytes, &var{{{classname}}}); err == nil { + *o = {{{classname}}}(var{{{classname}}}) + } + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + {{#vars}} + delete(additionalProperties, "{{{baseName}}}") + {{/vars}} + o.AdditionalProperties = additionalProperties + } + + return err +} + +{{/vendorExtensions.x-additional-properties}} +{{>nullable_model}} diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 74598c6ce709..81c4cf697c09 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1810,6 +1810,7 @@ components: type: string banana: type: object + additionalProperties: true properties: lengthCm: type: number diff --git a/samples/client/petstore/go-experimental/go-petstore/model_200_response.go b/samples/client/petstore/go-experimental/go-petstore/model_200_response.go index 0eea6ec0447c..c23c13c54c2b 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_200_response.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_200_response.go @@ -147,3 +147,4 @@ func (v *NullableModel200Response) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_any_type.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_any_type.go index 9618b3d2a26b..59e7a4dec0ae 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_any_type.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_any_type.go @@ -16,8 +16,11 @@ import ( // AdditionalPropertiesAnyType struct for AdditionalPropertiesAnyType type AdditionalPropertiesAnyType struct { Name *string `json:"name,omitempty"` + AdditionalProperties map[string]interface{} } +type _AdditionalPropertiesAnyType AdditionalPropertiesAnyType + // NewAdditionalPropertiesAnyType instantiates a new AdditionalPropertiesAnyType 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 @@ -72,9 +75,31 @@ func (o AdditionalPropertiesAnyType) MarshalJSON() ([]byte, error) { if o.Name != nil { toSerialize["name"] = o.Name } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return json.Marshal(toSerialize) } +func (o *AdditionalPropertiesAnyType) UnmarshalJSON(bytes []byte) (err error) { + varAdditionalPropertiesAnyType := _AdditionalPropertiesAnyType{} + + if err = json.Unmarshal(bytes, &varAdditionalPropertiesAnyType); err == nil { + *o = AdditionalPropertiesAnyType(varAdditionalPropertiesAnyType) + } + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "name") + o.AdditionalProperties = additionalProperties + } + + return err +} + type NullableAdditionalPropertiesAnyType struct { value *AdditionalPropertiesAnyType isSet bool @@ -111,3 +136,4 @@ func (v *NullableAdditionalPropertiesAnyType) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_array.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_array.go index 32b38620ad44..7952e9cd56ab 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_array.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_array.go @@ -111,3 +111,4 @@ func (v *NullableAdditionalPropertiesArray) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_boolean.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_boolean.go index 098e83c9c42f..f64d9633a475 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_boolean.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_boolean.go @@ -111,3 +111,4 @@ func (v *NullableAdditionalPropertiesBoolean) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go index 046e91b90752..d60a6889b740 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go @@ -471,3 +471,4 @@ func (v *NullableAdditionalPropertiesClass) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_integer.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_integer.go index dfedb1bc5453..eeb60fc08db4 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_integer.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_integer.go @@ -111,3 +111,4 @@ func (v *NullableAdditionalPropertiesInteger) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_number.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_number.go index 10428e020c06..bd385cbe0885 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_number.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_number.go @@ -111,3 +111,4 @@ func (v *NullableAdditionalPropertiesNumber) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_object.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_object.go index 6f16a067a4a7..69fb5e310444 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_object.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_object.go @@ -111,3 +111,4 @@ func (v *NullableAdditionalPropertiesObject) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_string.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_string.go index b3f971dd13a8..54928c3a1c9f 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_string.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_string.go @@ -111,3 +111,4 @@ func (v *NullableAdditionalPropertiesString) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_animal.go b/samples/client/petstore/go-experimental/go-petstore/model_animal.go index a1a7f99db9d0..5aa1f60f02fa 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_animal.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_animal.go @@ -144,3 +144,4 @@ func (v *NullableAnimal) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_api_response.go b/samples/client/petstore/go-experimental/go-petstore/model_api_response.go index f66dd2b120d1..17bf558d1c9f 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_api_response.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_api_response.go @@ -183,3 +183,4 @@ func (v *NullableApiResponse) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go b/samples/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go index 27cc790083db..6b81323ac4dc 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go @@ -111,3 +111,4 @@ func (v *NullableArrayOfArrayOfNumberOnly) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go b/samples/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go index ba3cdec1ddea..f43bffc1c874 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go @@ -111,3 +111,4 @@ func (v *NullableArrayOfNumberOnly) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_array_test_.go b/samples/client/petstore/go-experimental/go-petstore/model_array_test_.go index bcb080671627..42e2be66d629 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_array_test_.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_array_test_.go @@ -183,3 +183,4 @@ func (v *NullableArrayTest) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_big_cat.go b/samples/client/petstore/go-experimental/go-petstore/model_big_cat.go index f4457f7a83c1..27b8085b241b 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_big_cat.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_big_cat.go @@ -120,3 +120,4 @@ func (v *NullableBigCat) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_big_cat_all_of.go b/samples/client/petstore/go-experimental/go-petstore/model_big_cat_all_of.go index f55948719449..6434cd11d7cf 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_big_cat_all_of.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_big_cat_all_of.go @@ -111,3 +111,4 @@ func (v *NullableBigCatAllOf) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_capitalization.go b/samples/client/petstore/go-experimental/go-petstore/model_capitalization.go index 782bbab9b1fe..7f2c90863e0c 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_capitalization.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_capitalization.go @@ -292,3 +292,4 @@ func (v *NullableCapitalization) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_cat.go b/samples/client/petstore/go-experimental/go-petstore/model_cat.go index 6f7425873cdb..d6573c99bac3 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_cat.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_cat.go @@ -120,3 +120,4 @@ func (v *NullableCat) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_cat_all_of.go b/samples/client/petstore/go-experimental/go-petstore/model_cat_all_of.go index 2efc62d2022d..643ba03973f4 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_cat_all_of.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_cat_all_of.go @@ -111,3 +111,4 @@ func (v *NullableCatAllOf) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_category.go b/samples/client/petstore/go-experimental/go-petstore/model_category.go index e00cc7ba84bc..0c4628895331 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_category.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_category.go @@ -142,3 +142,4 @@ func (v *NullableCategory) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_class_model.go b/samples/client/petstore/go-experimental/go-petstore/model_class_model.go index 5213ad9d8791..7236de0ee071 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_class_model.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_class_model.go @@ -111,3 +111,4 @@ func (v *NullableClassModel) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_client.go b/samples/client/petstore/go-experimental/go-petstore/model_client.go index d1b9ffcc2876..edfdde067ef6 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_client.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_client.go @@ -111,3 +111,4 @@ func (v *NullableClient) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_dog.go b/samples/client/petstore/go-experimental/go-petstore/model_dog.go index 12a5bee4876f..ebbedeec53e8 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_dog.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_dog.go @@ -120,3 +120,4 @@ func (v *NullableDog) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_dog_all_of.go b/samples/client/petstore/go-experimental/go-petstore/model_dog_all_of.go index a5a791e50f0a..c13aa2b2cd57 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_dog_all_of.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_dog_all_of.go @@ -111,3 +111,4 @@ func (v *NullableDogAllOf) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_enum_arrays.go b/samples/client/petstore/go-experimental/go-petstore/model_enum_arrays.go index 1fbadb34e715..b18984ce7306 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_enum_arrays.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_enum_arrays.go @@ -147,3 +147,4 @@ func (v *NullableEnumArrays) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_enum_test_.go b/samples/client/petstore/go-experimental/go-petstore/model_enum_test_.go index 852dd860739c..c39d045e5a6b 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_enum_test_.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_enum_test_.go @@ -248,3 +248,4 @@ func (v *NullableEnumTest) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_file.go b/samples/client/petstore/go-experimental/go-petstore/model_file.go index d7a50dc683a7..43ec19f86383 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_file.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_file.go @@ -112,3 +112,4 @@ func (v *NullableFile) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go b/samples/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go index 887cd35c752f..626a3765173a 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go @@ -147,3 +147,4 @@ func (v *NullableFileSchemaTestClass) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_format_test_.go b/samples/client/petstore/go-experimental/go-petstore/model_format_test_.go index dbccde98dc46..aa1889aedda1 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_format_test_.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_format_test_.go @@ -553,3 +553,4 @@ func (v *NullableFormatTest) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go b/samples/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go index 0aa39e6de8ca..3400c73dca67 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go @@ -147,3 +147,4 @@ func (v *NullableHasOnlyReadOnly) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_list.go b/samples/client/petstore/go-experimental/go-petstore/model_list.go index 7966d7b337ca..f49afaa71f33 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_list.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_list.go @@ -111,3 +111,4 @@ func (v *NullableList) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_map_test_.go b/samples/client/petstore/go-experimental/go-petstore/model_map_test_.go index 42724f8d8758..4fc2c0b47991 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_map_test_.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_map_test_.go @@ -219,3 +219,4 @@ func (v *NullableMapTest) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go b/samples/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go index 21b7cb60ab4c..69cc134169e7 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go @@ -184,3 +184,4 @@ func (v *NullableMixedPropertiesAndAdditionalPropertiesClass) UnmarshalJSON(src return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_name.go b/samples/client/petstore/go-experimental/go-petstore/model_name.go index f910dc37c0c4..82e49591874b 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_name.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_name.go @@ -212,3 +212,4 @@ func (v *NullableName) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_number_only.go b/samples/client/petstore/go-experimental/go-petstore/model_number_only.go index 6307b2871e96..efa8b66a5bcc 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_number_only.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_number_only.go @@ -111,3 +111,4 @@ func (v *NullableNumberOnly) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_order.go b/samples/client/petstore/go-experimental/go-petstore/model_order.go index 797c8e9236f4..b20a14298482 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_order.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_order.go @@ -297,3 +297,4 @@ func (v *NullableOrder) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_outer_composite.go b/samples/client/petstore/go-experimental/go-petstore/model_outer_composite.go index 88049de0dac0..9a76c753b644 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_outer_composite.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_outer_composite.go @@ -183,3 +183,4 @@ func (v *NullableOuterComposite) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_pet.go b/samples/client/petstore/go-experimental/go-petstore/model_pet.go index 876af8724d73..8bc4457fc372 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_pet.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_pet.go @@ -278,3 +278,4 @@ func (v *NullablePet) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_read_only_first.go b/samples/client/petstore/go-experimental/go-petstore/model_read_only_first.go index af6291b4c820..dd00212c1d04 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_read_only_first.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_read_only_first.go @@ -147,3 +147,4 @@ func (v *NullableReadOnlyFirst) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_return.go b/samples/client/petstore/go-experimental/go-petstore/model_return.go index e6350da030cb..2ed729e12eca 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_return.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_return.go @@ -111,3 +111,4 @@ func (v *NullableReturn) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_special_model_name.go b/samples/client/petstore/go-experimental/go-petstore/model_special_model_name.go index e50eb5d32d14..bbef383b796a 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_special_model_name.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_special_model_name.go @@ -111,3 +111,4 @@ func (v *NullableSpecialModelName) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_tag.go b/samples/client/petstore/go-experimental/go-petstore/model_tag.go index 0f8157a6b7a8..99135ba946be 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_tag.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_tag.go @@ -147,3 +147,4 @@ func (v *NullableTag) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_type_holder_default.go b/samples/client/petstore/go-experimental/go-petstore/model_type_holder_default.go index 3ff4e709be14..d45748bf769e 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_type_holder_default.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_type_holder_default.go @@ -224,3 +224,4 @@ func (v *NullableTypeHolderDefault) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_type_holder_example.go b/samples/client/petstore/go-experimental/go-petstore/model_type_holder_example.go index 4996f734edc5..3f74c433f715 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_type_holder_example.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_type_holder_example.go @@ -249,3 +249,4 @@ func (v *NullableTypeHolderExample) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_user.go b/samples/client/petstore/go-experimental/go-petstore/model_user.go index 29f2e3f26526..7dff4e8b36b9 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_user.go @@ -364,3 +364,4 @@ func (v *NullableUser) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_xml_item.go b/samples/client/petstore/go-experimental/go-petstore/model_xml_item.go index 1d78601f0609..8bf7f3ef7073 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_xml_item.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_xml_item.go @@ -1119,3 +1119,4 @@ func (v *NullableXmlItem) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml index f7bec5630719..7e77947b7a74 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml @@ -1925,6 +1925,7 @@ components: type: string type: object banana: + additionalProperties: true properties: lengthCm: type: number 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 0eea6ec0447c..c23c13c54c2b 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 @@ -147,3 +147,4 @@ func (v *NullableModel200Response) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 e50eb5d32d14..bbef383b796a 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 @@ -111,3 +111,4 @@ func (v *NullableSpecialModelName) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 941f00027dbb..2ac0b72cfa23 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 @@ -147,3 +147,4 @@ func (v *NullableAdditionalPropertiesClass) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 a1a7f99db9d0..5aa1f60f02fa 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 @@ -144,3 +144,4 @@ func (v *NullableAnimal) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 f66dd2b120d1..17bf558d1c9f 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 @@ -183,3 +183,4 @@ func (v *NullableApiResponse) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple.go index d6800b1ad0aa..97b0b94f3e9e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple.go @@ -111,3 +111,4 @@ func (v *NullableApple) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple_req.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple_req.go index f5f4cbad71e0..3879864cf14e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple_req.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple_req.go @@ -140,3 +140,4 @@ func (v *NullableAppleReq) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 27cc790083db..6b81323ac4dc 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 @@ -111,3 +111,4 @@ func (v *NullableArrayOfArrayOfNumberOnly) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 ba3cdec1ddea..f43bffc1c874 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 @@ -111,3 +111,4 @@ func (v *NullableArrayOfNumberOnly) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 bcb080671627..42e2be66d629 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 @@ -183,3 +183,4 @@ func (v *NullableArrayTest) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana.go index a4fb1e386409..f375a8b8f9c0 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana.go @@ -16,8 +16,11 @@ import ( // Banana struct for Banana type Banana struct { LengthCm *float32 `json:"lengthCm,omitempty"` + AdditionalProperties map[string]interface{} } +type _Banana Banana + // NewBanana instantiates a new Banana 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 @@ -72,9 +75,31 @@ func (o Banana) MarshalJSON() ([]byte, error) { if o.LengthCm != nil { toSerialize["lengthCm"] = o.LengthCm } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return json.Marshal(toSerialize) } +func (o *Banana) UnmarshalJSON(bytes []byte) (err error) { + varBanana := _Banana{} + + if err = json.Unmarshal(bytes, &varBanana); err == nil { + *o = Banana(varBanana) + } + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "lengthCm") + o.AdditionalProperties = additionalProperties + } + + return err +} + type NullableBanana struct { value *Banana isSet bool @@ -111,3 +136,4 @@ func (v *NullableBanana) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana_req.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana_req.go index eb0d40c61d96..ed874ef2e6fd 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana_req.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana_req.go @@ -140,3 +140,4 @@ func (v *NullableBananaReq) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 782bbab9b1fe..7f2c90863e0c 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 @@ -292,3 +292,4 @@ func (v *NullableCapitalization) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 6f7425873cdb..d6573c99bac3 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 @@ -120,3 +120,4 @@ func (v *NullableCat) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 2efc62d2022d..643ba03973f4 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 @@ -111,3 +111,4 @@ func (v *NullableCatAllOf) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 e00cc7ba84bc..0c4628895331 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 @@ -142,3 +142,4 @@ func (v *NullableCategory) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 5213ad9d8791..7236de0ee071 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 @@ -111,3 +111,4 @@ func (v *NullableClassModel) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 d1b9ffcc2876..edfdde067ef6 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 @@ -111,3 +111,4 @@ func (v *NullableClient) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 12a5bee4876f..ebbedeec53e8 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 @@ -120,3 +120,4 @@ func (v *NullableDog) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 a5a791e50f0a..c13aa2b2cd57 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 @@ -111,3 +111,4 @@ func (v *NullableDogAllOf) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 1fbadb34e715..b18984ce7306 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 @@ -147,3 +147,4 @@ func (v *NullableEnumArrays) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 f9c20efe677c..d6da2e58bf99 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 @@ -374,3 +374,4 @@ func (v *NullableEnumTest) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 d7a50dc683a7..43ec19f86383 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 @@ -112,3 +112,4 @@ func (v *NullableFile) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 887cd35c752f..626a3765173a 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 @@ -147,3 +147,4 @@ func (v *NullableFileSchemaTestClass) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 825b2761c1c1..723deec46aa4 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 @@ -115,3 +115,4 @@ func (v *NullableFoo) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 bcc0289a0914..67f0c80c72e5 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 @@ -591,3 +591,4 @@ func (v *NullableFormatTest) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 0aa39e6de8ca..3400c73dca67 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 @@ -147,3 +147,4 @@ func (v *NullableHasOnlyReadOnly) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 af5a5b94a1ec..70874db5605e 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 @@ -121,3 +121,4 @@ func (v *NullableHealthCheckResult) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 ec6a571e8eb5..35df941a0d62 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 @@ -149,3 +149,4 @@ func (v *NullableInlineObject) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 d95ad59790ab..a400eda20e36 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 @@ -150,3 +150,4 @@ func (v *NullableInlineObject1) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 d3029a8e77b0..a80ba9b9e5c5 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 @@ -153,3 +153,4 @@ func (v *NullableInlineObject2) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 c51c19956f50..9dcc233d034d 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 @@ -567,3 +567,4 @@ func (v *NullableInlineObject3) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 b4fcf5fa1f0b..783556ef23cc 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 @@ -135,3 +135,4 @@ func (v *NullableInlineObject4) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 974844007a74..055f4ff8fe28 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 @@ -143,3 +143,4 @@ func (v *NullableInlineObject5) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 19fb6bcd8a80..3c8ca5deafeb 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 @@ -111,3 +111,4 @@ func (v *NullableInlineResponseDefault) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 7966d7b337ca..f49afaa71f33 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 @@ -111,3 +111,4 @@ func (v *NullableList) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 42724f8d8758..4fc2c0b47991 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 @@ -219,3 +219,4 @@ func (v *NullableMapTest) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 21b7cb60ab4c..69cc134169e7 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 @@ -184,3 +184,4 @@ func (v *NullableMixedPropertiesAndAdditionalPropertiesClass) UnmarshalJSON(src return json.Unmarshal(src, &v.value) } + 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 f910dc37c0c4..82e49591874b 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 @@ -212,3 +212,4 @@ func (v *NullableName) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 0f3e7fb3a419..d2eb6062f6e8 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 @@ -28,8 +28,11 @@ type NullableClass struct { 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"` + AdditionalProperties map[string]interface{} } +type _NullableClass NullableClass + // NewNullableClass instantiates a new NullableClass 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 @@ -533,9 +536,42 @@ func (o NullableClass) MarshalJSON() ([]byte, error) { if o.ObjectItemsNullable != nil { toSerialize["object_items_nullable"] = o.ObjectItemsNullable } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return json.Marshal(toSerialize) } +func (o *NullableClass) UnmarshalJSON(bytes []byte) (err error) { + varNullableClass := _NullableClass{} + + if err = json.Unmarshal(bytes, &varNullableClass); err == nil { + *o = NullableClass(varNullableClass) + } + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "integer_prop") + delete(additionalProperties, "number_prop") + delete(additionalProperties, "boolean_prop") + delete(additionalProperties, "string_prop") + delete(additionalProperties, "date_prop") + delete(additionalProperties, "datetime_prop") + delete(additionalProperties, "array_nullable_prop") + delete(additionalProperties, "array_and_items_nullable_prop") + delete(additionalProperties, "array_items_nullable") + delete(additionalProperties, "object_nullable_prop") + delete(additionalProperties, "object_and_items_nullable_prop") + delete(additionalProperties, "object_items_nullable") + o.AdditionalProperties = additionalProperties + } + + return err +} + type NullableNullableClass struct { value *NullableClass isSet bool @@ -572,3 +608,4 @@ func (v *NullableNullableClass) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 6307b2871e96..efa8b66a5bcc 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 @@ -111,3 +111,4 @@ func (v *NullableNumberOnly) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 797c8e9236f4..b20a14298482 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 @@ -297,3 +297,4 @@ func (v *NullableOrder) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 88049de0dac0..9a76c753b644 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 @@ -183,3 +183,4 @@ func (v *NullableOuterComposite) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 876af8724d73..8bc4457fc372 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 @@ -278,3 +278,4 @@ func (v *NullablePet) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 af6291b4c820..dd00212c1d04 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 @@ -147,3 +147,4 @@ func (v *NullableReadOnlyFirst) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 e6350da030cb..2ed729e12eca 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 @@ -111,3 +111,4 @@ func (v *NullableReturn) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 0f8157a6b7a8..99135ba946be 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 @@ -147,3 +147,4 @@ func (v *NullableTag) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + 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 f9824d767f22..ce40d756100f 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 @@ -515,3 +515,4 @@ func (v *NullableUser) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_whale.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_whale.go index faeb81870214..0b81bcfa7ad4 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_whale.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_whale.go @@ -176,3 +176,4 @@ func (v *NullableWhale) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_zebra.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_zebra.go index b28b9d7d1dbe..82854d088349 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_zebra.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_zebra.go @@ -140,3 +140,4 @@ func (v *NullableZebra) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/model_test.go b/samples/openapi3/client/petstore/go-experimental/model_test.go new file mode 100644 index 000000000000..46012d009e62 --- /dev/null +++ b/samples/openapi3/client/petstore/go-experimental/model_test.go @@ -0,0 +1,34 @@ +package main + +import ( + "testing" + "encoding/json" + "github.com/stretchr/testify/assert" + sw "./go-petstore" +) + +func TestBanana(t *testing.T) { + assert := assert.New(t) + + lengthCm := float32(2.3) + lengthCm2 := float32(2.4) + newBanana := (sw.Banana{LengthCm: &lengthCm}) + newBanana.LengthCm = &lengthCm2 + assert.Equal(newBanana.LengthCm, &lengthCm2, "Banana LengthCm should be equal") + + // test additioanl properties + jsonBanana:= `{"fruits":["apple","peach"],"lengthCm":3.1}` + jsonMap := make(map[string]interface{}) + json.Unmarshal([]byte(jsonBanana), &jsonMap) + + newBanana2 := (sw.Banana{}) + lengthCm3 := float32(3.1) + json.Unmarshal([]byte(jsonBanana), &newBanana2) + assert.Equal(newBanana2.LengthCm, &lengthCm3, "Banana2 LengthCm should be equal") + assert.Equal(newBanana2.AdditionalProperties["fruits"], jsonMap["fruits"], "Banana2 AdditonalProperties should be equal") + + newBanana2Json, _ := json.Marshal(newBanana2) + assert.Equal(string(newBanana2Json), jsonBanana, "Banana2 JSON string should be equal") + +} +