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 9ed104ab2839..dbe8e953130d 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 @@ -2125,6 +2125,12 @@ components: type: array items: type: string + AnyOfPrimitiveType: + anyOf: + - $ref: '#/components/schemas/OneOfPrimitiveTypeChild' + - type: integer + format: int32 + - $ref: '#/components/schemas/OneOfArrayOfString' # `dup-prop` is defined in both parent and child models # but not identical: optional vs required DuplicatedPropChild: 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 c63441acc9c0..777edc68ecff 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/go/go-petstore/.openapi-generator/FILES @@ -15,6 +15,7 @@ docs/AdditionalPropertiesClass.md docs/AllOfPrimitiveTypes.md docs/Animal.md docs/AnotherFakeAPI.md +docs/AnyOfPrimitiveType.md docs/ApiResponse.md docs/Apple.md docs/AppleReq.md @@ -91,6 +92,7 @@ model__special_model_name_.go model_additional_properties_class.go model_all_of_primitive_types.go model_animal.go +model_any_of_primitive_type.go model_api_response.go model_apple.go model_apple_req.go diff --git a/samples/openapi3/client/petstore/go/go-petstore/README.md b/samples/openapi3/client/petstore/go/go-petstore/README.md index 685baa5ce8e0..63d469ba163d 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/README.md +++ b/samples/openapi3/client/petstore/go/go-petstore/README.md @@ -130,6 +130,7 @@ Class | Method | HTTP request | Description - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [AllOfPrimitiveTypes](docs/AllOfPrimitiveTypes.md) - [Animal](docs/Animal.md) + - [AnyOfPrimitiveType](docs/AnyOfPrimitiveType.md) - [ApiResponse](docs/ApiResponse.md) - [Apple](docs/Apple.md) - [AppleReq](docs/AppleReq.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 426ad28a116e..a3ddc1ab44b4 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml @@ -2113,6 +2113,12 @@ components: items: type: string type: array + AnyOfPrimitiveType: + anyOf: + - $ref: '#/components/schemas/OneOfPrimitiveTypeChild' + - format: int32 + type: integer + - $ref: '#/components/schemas/OneOfArrayOfString' DuplicatedPropChild: allOf: - $ref: '#/components/schemas/DuplicatedPropParent' diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/AnyOfPrimitiveType.md b/samples/openapi3/client/petstore/go/go-petstore/docs/AnyOfPrimitiveType.md new file mode 100644 index 000000000000..fadb3bf985ea --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/AnyOfPrimitiveType.md @@ -0,0 +1,56 @@ +# AnyOfPrimitiveType + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Name** | Pointer to **string** | | [optional] + +## Methods + +### NewAnyOfPrimitiveType + +`func NewAnyOfPrimitiveType() *AnyOfPrimitiveType` + +NewAnyOfPrimitiveType instantiates a new AnyOfPrimitiveType 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 + +### NewAnyOfPrimitiveTypeWithDefaults + +`func NewAnyOfPrimitiveTypeWithDefaults() *AnyOfPrimitiveType` + +NewAnyOfPrimitiveTypeWithDefaults instantiates a new AnyOfPrimitiveType 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 + +### GetName + +`func (o *AnyOfPrimitiveType) GetName() string` + +GetName returns the Name field if non-nil, zero value otherwise. + +### GetNameOk + +`func (o *AnyOfPrimitiveType) GetNameOk() (*string, bool)` + +GetNameOk returns a tuple with the Name field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetName + +`func (o *AnyOfPrimitiveType) SetName(v string)` + +SetName sets Name field to given value. + +### HasName + +`func (o *AnyOfPrimitiveType) HasName() bool` + +HasName 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_any_of_primitive_type.go b/samples/openapi3/client/petstore/go/go-petstore/model_any_of_primitive_type.go new file mode 100644 index 000000000000..aa60b47e5cce --- /dev/null +++ b/samples/openapi3/client/petstore/go/go-petstore/model_any_of_primitive_type.go @@ -0,0 +1,123 @@ +/* +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" + "fmt" +) + +// AnyOfPrimitiveType struct for AnyOfPrimitiveType +type AnyOfPrimitiveType struct { + OneOfPrimitiveTypeChild *OneOfPrimitiveTypeChild + ArrayOfString *[]string + Int32 *int32 +} + +// Unmarshal JSON data into any of the pointers in the struct +func (dst *AnyOfPrimitiveType) UnmarshalJSON(data []byte) error { + var err error + // try to unmarshal JSON data into OneOfPrimitiveTypeChild + err = json.Unmarshal(data, &dst.OneOfPrimitiveTypeChild); + if err == nil { + jsonOneOfPrimitiveTypeChild, _ := json.Marshal(dst.OneOfPrimitiveTypeChild) + if string(jsonOneOfPrimitiveTypeChild) == "{}" { // empty struct + dst.OneOfPrimitiveTypeChild = nil + } else { + return nil // data stored in dst.OneOfPrimitiveTypeChild, return on the first match + } + } else { + dst.OneOfPrimitiveTypeChild = nil + } + + // try to unmarshal JSON data into ArrayOfString + err = json.Unmarshal(data, &dst.ArrayOfString); + if err == nil { + jsonArrayOfString, _ := json.Marshal(dst.ArrayOfString) + if string(jsonArrayOfString) == "{}" { // empty struct + dst.ArrayOfString = nil + } else { + return nil // data stored in dst.ArrayOfString, return on the first match + } + } else { + dst.ArrayOfString = nil + } + + // try to unmarshal JSON data into Int32 + err = json.Unmarshal(data, &dst.Int32); + if err == nil { + jsonInt32, _ := json.Marshal(dst.Int32) + if string(jsonInt32) == "{}" { // empty struct + dst.Int32 = nil + } else { + return nil // data stored in dst.Int32, return on the first match + } + } else { + dst.Int32 = nil + } + + return fmt.Errorf("data failed to match schemas in anyOf(AnyOfPrimitiveType)") +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src *AnyOfPrimitiveType) MarshalJSON() ([]byte, error) { + if src.OneOfPrimitiveTypeChild != nil { + return json.Marshal(&src.OneOfPrimitiveTypeChild) + } + + if src.ArrayOfString != nil { + return json.Marshal(&src.ArrayOfString) + } + + if src.Int32 != nil { + return json.Marshal(&src.Int32) + } + + return nil, nil // no data in anyOf schemas +} + +type NullableAnyOfPrimitiveType struct { + value *AnyOfPrimitiveType + isSet bool +} + +func (v NullableAnyOfPrimitiveType) Get() *AnyOfPrimitiveType { + return v.value +} + +func (v *NullableAnyOfPrimitiveType) Set(val *AnyOfPrimitiveType) { + v.value = val + v.isSet = true +} + +func (v NullableAnyOfPrimitiveType) IsSet() bool { + return v.isSet +} + +func (v *NullableAnyOfPrimitiveType) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAnyOfPrimitiveType(val *AnyOfPrimitiveType) *NullableAnyOfPrimitiveType { + return &NullableAnyOfPrimitiveType{value: val, isSet: true} +} + +func (v NullableAnyOfPrimitiveType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAnyOfPrimitiveType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +