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 d436a01c42f1..a72ca4a6f35a 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 @@ -634,9 +634,6 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege List inheritedProperties = new ArrayList<>(); if (model.getComposedSchemas() != null) { - if (model.getComposedSchemas().getAllOf() != null) { - inheritedProperties.addAll(model.getComposedSchemas().getAllOf()); - } if (model.getComposedSchemas().getAnyOf() != null) { inheritedProperties.addAll(model.getComposedSchemas().getAnyOf()); } @@ -646,22 +643,18 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege } List codegenProperties = new ArrayList<>(); - if(model.getIsModel() || model.getComposedSchemas() == null) { - // If the model is a model, use model.vars as it only - // contains properties the generated struct will own itself. - // If model is no model and it has no composed schemas use - // model.vars. + if(model.getComposedSchemas() == null || (model.getComposedSchemas() != null && model.getComposedSchemas().getAllOf() != null)) { + // If the model is an allOf or does not have any composed schemas, then we can use the model's properties. codegenProperties.addAll(model.vars); } else { // If the model is no model, but is a - // allOf, anyOf or oneOf, add all first level options - // from allOf, anyOf or oneOf. + // anyOf or oneOf, add all first level options + // from anyOf or oneOf. codegenProperties.addAll(inheritedProperties); } for (CodegenProperty cp : codegenProperties) { - if (!addedTimeImport && ("time.Time".equals(cp.dataType) || - (cp.items != null && "time.Time".equals(cp.items.dataType)))) { + if (!addedTimeImport && ("time.Time".equals(cp.dataType) || (cp.items != null && "time.Time".equals(cp.items.dataType)))) { imports.add(createMapping("import", "time")); addedTimeImport = true; } @@ -671,16 +664,10 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege addedOSImport = true; } } - if (this instanceof GoClientCodegen && model.isEnum) { imports.add(createMapping("import", "fmt")); } - // if oneOf contains "time.Time" type - if (!addedTimeImport && model.oneOf != null && model.oneOf.contains("time.Time")) { - imports.add(createMapping("import", "time")); - } - // if oneOf contains "null" type if (model.oneOf != null && !model.oneOf.isEmpty() && model.oneOf.contains("nil")) { model.isNullable = true; 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 faeced45bffa..fca36be3c897 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 @@ -2051,3 +2051,10 @@ components: - type: string - format: date-time type: string + AllOfPrimitiveTypes: + allOf: + - type: object + properties: + test: + type: string + format: date-time 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 30c2ee9992b3..a2abad6179b7 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES @@ -12,6 +12,8 @@ api_user.go client.go configuration.go docs/AdditionalPropertiesClass.md +docs/AllOfPrimitiveTypes.md +docs/AllOfPrimitiveTypesAllOf.md docs/Animal.md docs/AnotherFakeApi.md docs/ApiResponse.md @@ -88,6 +90,8 @@ model_200_response.go model__foo_get_default_response.go model__special_model_name_.go model_additional_properties_class.go +model_all_of_primitive_types.go +model_all_of_primitive_types_all_of.go model_animal.go model_api_response.go model_apple.go diff --git a/samples/openapi3/client/petstore/go/go-petstore/README.md b/samples/openapi3/client/petstore/go/go-petstore/README.md index 59c5053315f9..16700f869b2b 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/README.md +++ b/samples/openapi3/client/petstore/go/go-petstore/README.md @@ -123,6 +123,8 @@ Class | Method | HTTP request | Description ## Documentation For Models - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) + - [AllOfPrimitiveTypes](docs/AllOfPrimitiveTypes.md) + - [AllOfPrimitiveTypesAllOf](docs/AllOfPrimitiveTypesAllOf.md) - [Animal](docs/Animal.md) - [ApiResponse](docs/ApiResponse.md) - [Apple](docs/Apple.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 5ed83d56fc97..37418ea83700 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml @@ -2014,6 +2014,9 @@ components: - type: string - format: date-time type: string + AllOfPrimitiveTypes: + allOf: + - $ref: '#/components/schemas/AllOfPrimitiveTypes_allOf' _foo_get_default_response: example: string: @@ -2176,6 +2179,13 @@ components: type: string type: object example: null + AllOfPrimitiveTypes_allOf: + properties: + test: + format: date-time + type: string + type: object + example: null securitySchemes: petstore_auth: flows: diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/AllOfPrimitiveTypes.md b/samples/openapi3/client/petstore/go/go-petstore/docs/AllOfPrimitiveTypes.md new file mode 100644 index 000000000000..d831ed87c10b --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/AllOfPrimitiveTypes.md @@ -0,0 +1,56 @@ +# AllOfPrimitiveTypes + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Test** | Pointer to **time.Time** | | [optional] + +## Methods + +### NewAllOfPrimitiveTypes + +`func NewAllOfPrimitiveTypes() *AllOfPrimitiveTypes` + +NewAllOfPrimitiveTypes instantiates a new AllOfPrimitiveTypes 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 + +### NewAllOfPrimitiveTypesWithDefaults + +`func NewAllOfPrimitiveTypesWithDefaults() *AllOfPrimitiveTypes` + +NewAllOfPrimitiveTypesWithDefaults instantiates a new AllOfPrimitiveTypes 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 + +### GetTest + +`func (o *AllOfPrimitiveTypes) GetTest() time.Time` + +GetTest returns the Test field if non-nil, zero value otherwise. + +### GetTestOk + +`func (o *AllOfPrimitiveTypes) GetTestOk() (*time.Time, bool)` + +GetTestOk returns a tuple with the Test field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetTest + +`func (o *AllOfPrimitiveTypes) SetTest(v time.Time)` + +SetTest sets Test field to given value. + +### HasTest + +`func (o *AllOfPrimitiveTypes) HasTest() bool` + +HasTest 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/AllOfPrimitiveTypesAllOf.md b/samples/openapi3/client/petstore/go/go-petstore/docs/AllOfPrimitiveTypesAllOf.md new file mode 100644 index 000000000000..498e63a84383 --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/AllOfPrimitiveTypesAllOf.md @@ -0,0 +1,56 @@ +# AllOfPrimitiveTypesAllOf + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Test** | Pointer to **time.Time** | | [optional] + +## Methods + +### NewAllOfPrimitiveTypesAllOf + +`func NewAllOfPrimitiveTypesAllOf() *AllOfPrimitiveTypesAllOf` + +NewAllOfPrimitiveTypesAllOf instantiates a new AllOfPrimitiveTypesAllOf 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 + +### NewAllOfPrimitiveTypesAllOfWithDefaults + +`func NewAllOfPrimitiveTypesAllOfWithDefaults() *AllOfPrimitiveTypesAllOf` + +NewAllOfPrimitiveTypesAllOfWithDefaults instantiates a new AllOfPrimitiveTypesAllOf 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 + +### GetTest + +`func (o *AllOfPrimitiveTypesAllOf) GetTest() time.Time` + +GetTest returns the Test field if non-nil, zero value otherwise. + +### GetTestOk + +`func (o *AllOfPrimitiveTypesAllOf) GetTestOk() (*time.Time, bool)` + +GetTestOk returns a tuple with the Test field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetTest + +`func (o *AllOfPrimitiveTypesAllOf) SetTest(v time.Time)` + +SetTest sets Test field to given value. + +### HasTest + +`func (o *AllOfPrimitiveTypesAllOf) HasTest() bool` + +HasTest 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_all_of_primitive_types.go b/samples/openapi3/client/petstore/go/go-petstore/model_all_of_primitive_types.go new file mode 100644 index 000000000000..8f4a4ca59170 --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/model_all_of_primitive_types.go @@ -0,0 +1,152 @@ +/* +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" + "time" +) + +// checks if the AllOfPrimitiveTypes type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &AllOfPrimitiveTypes{} + +// AllOfPrimitiveTypes struct for AllOfPrimitiveTypes +type AllOfPrimitiveTypes struct { + Test *time.Time `json:"test,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _AllOfPrimitiveTypes AllOfPrimitiveTypes + +// NewAllOfPrimitiveTypes instantiates a new AllOfPrimitiveTypes 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 NewAllOfPrimitiveTypes() *AllOfPrimitiveTypes { + this := AllOfPrimitiveTypes{} + return &this +} + +// NewAllOfPrimitiveTypesWithDefaults instantiates a new AllOfPrimitiveTypes 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 NewAllOfPrimitiveTypesWithDefaults() *AllOfPrimitiveTypes { + this := AllOfPrimitiveTypes{} + return &this +} + +// GetTest returns the Test field value if set, zero value otherwise. +func (o *AllOfPrimitiveTypes) GetTest() time.Time { + if o == nil || isNil(o.Test) { + var ret time.Time + return ret + } + return *o.Test +} + +// GetTestOk returns a tuple with the Test field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *AllOfPrimitiveTypes) GetTestOk() (*time.Time, bool) { + if o == nil || isNil(o.Test) { + return nil, false + } + return o.Test, true +} + +// HasTest returns a boolean if a field has been set. +func (o *AllOfPrimitiveTypes) HasTest() bool { + if o != nil && !isNil(o.Test) { + return true + } + + return false +} + +// SetTest gets a reference to the given time.Time and assigns it to the Test field. +func (o *AllOfPrimitiveTypes) SetTest(v time.Time) { + o.Test = &v +} + +func (o AllOfPrimitiveTypes) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o AllOfPrimitiveTypes) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !isNil(o.Test) { + toSerialize["test"] = o.Test + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *AllOfPrimitiveTypes) UnmarshalJSON(bytes []byte) (err error) { + varAllOfPrimitiveTypes := _AllOfPrimitiveTypes{} + + if err = json.Unmarshal(bytes, &varAllOfPrimitiveTypes); err == nil { + *o = AllOfPrimitiveTypes(varAllOfPrimitiveTypes) + } + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "test") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableAllOfPrimitiveTypes struct { + value *AllOfPrimitiveTypes + isSet bool +} + +func (v NullableAllOfPrimitiveTypes) Get() *AllOfPrimitiveTypes { + return v.value +} + +func (v *NullableAllOfPrimitiveTypes) Set(val *AllOfPrimitiveTypes) { + v.value = val + v.isSet = true +} + +func (v NullableAllOfPrimitiveTypes) IsSet() bool { + return v.isSet +} + +func (v *NullableAllOfPrimitiveTypes) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAllOfPrimitiveTypes(val *AllOfPrimitiveTypes) *NullableAllOfPrimitiveTypes { + return &NullableAllOfPrimitiveTypes{value: val, isSet: true} +} + +func (v NullableAllOfPrimitiveTypes) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAllOfPrimitiveTypes) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_all_of_primitive_types_all_of.go b/samples/openapi3/client/petstore/go/go-petstore/model_all_of_primitive_types_all_of.go new file mode 100644 index 000000000000..279a8e2eef1b --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/model_all_of_primitive_types_all_of.go @@ -0,0 +1,152 @@ +/* +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" + "time" +) + +// checks if the AllOfPrimitiveTypesAllOf type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &AllOfPrimitiveTypesAllOf{} + +// AllOfPrimitiveTypesAllOf struct for AllOfPrimitiveTypesAllOf +type AllOfPrimitiveTypesAllOf struct { + Test *time.Time `json:"test,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _AllOfPrimitiveTypesAllOf AllOfPrimitiveTypesAllOf + +// NewAllOfPrimitiveTypesAllOf instantiates a new AllOfPrimitiveTypesAllOf 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 NewAllOfPrimitiveTypesAllOf() *AllOfPrimitiveTypesAllOf { + this := AllOfPrimitiveTypesAllOf{} + return &this +} + +// NewAllOfPrimitiveTypesAllOfWithDefaults instantiates a new AllOfPrimitiveTypesAllOf 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 NewAllOfPrimitiveTypesAllOfWithDefaults() *AllOfPrimitiveTypesAllOf { + this := AllOfPrimitiveTypesAllOf{} + return &this +} + +// GetTest returns the Test field value if set, zero value otherwise. +func (o *AllOfPrimitiveTypesAllOf) GetTest() time.Time { + if o == nil || isNil(o.Test) { + var ret time.Time + return ret + } + return *o.Test +} + +// GetTestOk returns a tuple with the Test field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *AllOfPrimitiveTypesAllOf) GetTestOk() (*time.Time, bool) { + if o == nil || isNil(o.Test) { + return nil, false + } + return o.Test, true +} + +// HasTest returns a boolean if a field has been set. +func (o *AllOfPrimitiveTypesAllOf) HasTest() bool { + if o != nil && !isNil(o.Test) { + return true + } + + return false +} + +// SetTest gets a reference to the given time.Time and assigns it to the Test field. +func (o *AllOfPrimitiveTypesAllOf) SetTest(v time.Time) { + o.Test = &v +} + +func (o AllOfPrimitiveTypesAllOf) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o AllOfPrimitiveTypesAllOf) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !isNil(o.Test) { + toSerialize["test"] = o.Test + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *AllOfPrimitiveTypesAllOf) UnmarshalJSON(bytes []byte) (err error) { + varAllOfPrimitiveTypesAllOf := _AllOfPrimitiveTypesAllOf{} + + if err = json.Unmarshal(bytes, &varAllOfPrimitiveTypesAllOf); err == nil { + *o = AllOfPrimitiveTypesAllOf(varAllOfPrimitiveTypesAllOf) + } + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "test") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableAllOfPrimitiveTypesAllOf struct { + value *AllOfPrimitiveTypesAllOf + isSet bool +} + +func (v NullableAllOfPrimitiveTypesAllOf) Get() *AllOfPrimitiveTypesAllOf { + return v.value +} + +func (v *NullableAllOfPrimitiveTypesAllOf) Set(val *AllOfPrimitiveTypesAllOf) { + v.value = val + v.isSet = true +} + +func (v NullableAllOfPrimitiveTypesAllOf) IsSet() bool { + return v.isSet +} + +func (v *NullableAllOfPrimitiveTypesAllOf) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAllOfPrimitiveTypesAllOf(val *AllOfPrimitiveTypesAllOf) *NullableAllOfPrimitiveTypesAllOf { + return &NullableAllOfPrimitiveTypesAllOf{value: val, isSet: true} +} + +func (v NullableAllOfPrimitiveTypesAllOf) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAllOfPrimitiveTypesAllOf) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +