[Go] Client Models using AllOf, OneOf, or AnyOf Correctly Include time and os imports (Attempt 2) (#14459)

* Currently, if a Model is an allOf the time and os imports are not correctly added to the generated file. This was introduced recently with a fix to not include those imports when the model is a composedSchema #13833. The logic in that fix was just slightly off as an allOf should be treated the same as a standard model.

If a model is an AllOf or does not have any composed schemas at all, the sub-models are in-lined defined in the struct. In this case, the standard logic of including the time and os imports apply.

If a model is a OneOf or AnyOf, the sub-models are included as pointers to the defined model. In this case, do not include those items in the logic of including time and os imports.

* Update example to include a time in an allOf

* Add back the accidentally removed nil check
This commit is contained in:
Ian Cubbon
2023-01-19 10:53:19 -07:00
committed by GitHub
parent 6cd7989e9e
commit 6e780218ad
9 changed files with 444 additions and 18 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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:

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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)
}