forked from loafle/openapi-generator-original
add tests for oneOf object (go)
This commit is contained in:
@@ -2145,3 +2145,10 @@ components:
|
||||
type: string
|
||||
type_:
|
||||
type: string
|
||||
IncidentData:
|
||||
oneOf:
|
||||
- type: array
|
||||
items:
|
||||
type: object
|
||||
- type: object
|
||||
- type: "null"
|
||||
|
||||
@@ -47,6 +47,7 @@ docs/FruitReq.md
|
||||
docs/GmFruit.md
|
||||
docs/HasOnlyReadOnly.md
|
||||
docs/HealthCheckResult.md
|
||||
docs/IncidentData.md
|
||||
docs/List.md
|
||||
docs/Mammal.md
|
||||
docs/MapOfFileTest.md
|
||||
@@ -118,6 +119,7 @@ model_fruit_req.go
|
||||
model_gm_fruit.go
|
||||
model_has_only_read_only.go
|
||||
model_health_check_result.go
|
||||
model_incident_data.go
|
||||
model_list.go
|
||||
model_mammal.go
|
||||
model_map_of_file_test_.go
|
||||
|
||||
@@ -157,6 +157,7 @@ Class | Method | HTTP request | Description
|
||||
- [GmFruit](docs/GmFruit.md)
|
||||
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
|
||||
- [HealthCheckResult](docs/HealthCheckResult.md)
|
||||
- [IncidentData](docs/IncidentData.md)
|
||||
- [List](docs/List.md)
|
||||
- [Mammal](docs/Mammal.md)
|
||||
- [MapOfFileTest](docs/MapOfFileTest.md)
|
||||
|
||||
@@ -2122,6 +2122,13 @@ components:
|
||||
type: string
|
||||
type_:
|
||||
type: string
|
||||
IncidentData:
|
||||
nullable: true
|
||||
oneOf:
|
||||
- items:
|
||||
type: object
|
||||
type: array
|
||||
- type: object
|
||||
_foo_get_default_response:
|
||||
example:
|
||||
string:
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# IncidentData
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
## Methods
|
||||
|
||||
### NewIncidentData
|
||||
|
||||
`func NewIncidentData() *IncidentData`
|
||||
|
||||
NewIncidentData instantiates a new IncidentData 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
|
||||
|
||||
### NewIncidentDataWithDefaults
|
||||
|
||||
`func NewIncidentDataWithDefaults() *IncidentData`
|
||||
|
||||
NewIncidentDataWithDefaults instantiates a new IncidentData 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
|
||||
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
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"
|
||||
)
|
||||
|
||||
// IncidentData - struct for IncidentData
|
||||
type IncidentData struct {
|
||||
ArrayOfMapmapOfStringAny *[]map[string]interface{}
|
||||
MapmapOfStringAny *map[string]interface{}
|
||||
}
|
||||
|
||||
// []map[string]interface{}AsIncidentData is a convenience function that returns []map[string]interface{} wrapped in IncidentData
|
||||
func ArrayOfMapmapOfStringAnyAsIncidentData(v *[]map[string]interface{}) IncidentData {
|
||||
return IncidentData{
|
||||
ArrayOfMapmapOfStringAny: v,
|
||||
}
|
||||
}
|
||||
|
||||
// map[string]interface{}AsIncidentData is a convenience function that returns map[string]interface{} wrapped in IncidentData
|
||||
func MapmapOfStringAnyAsIncidentData(v *map[string]interface{}) IncidentData {
|
||||
return IncidentData{
|
||||
MapmapOfStringAny: v,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Unmarshal JSON data into one of the pointers in the struct
|
||||
func (dst *IncidentData) UnmarshalJSON(data []byte) error {
|
||||
var err error
|
||||
// this object is nullable so check if the payload is null or empty string
|
||||
if string(data) == "" || string(data) == "{}" {
|
||||
return nil
|
||||
}
|
||||
|
||||
match := 0
|
||||
// try to unmarshal data into ArrayOfMapmapOfStringAny
|
||||
err = newStrictDecoder(data).Decode(&dst.ArrayOfMapmapOfStringAny)
|
||||
if err == nil {
|
||||
jsonArrayOfMapmapOfStringAny, _ := json.Marshal(dst.ArrayOfMapmapOfStringAny)
|
||||
if string(jsonArrayOfMapmapOfStringAny) == "{}" { // empty struct
|
||||
dst.ArrayOfMapmapOfStringAny = nil
|
||||
} else {
|
||||
match++
|
||||
}
|
||||
} else {
|
||||
dst.ArrayOfMapmapOfStringAny = nil
|
||||
}
|
||||
|
||||
// try to unmarshal data into MapmapOfStringAny
|
||||
err = newStrictDecoder(data).Decode(&dst.MapmapOfStringAny)
|
||||
if err == nil {
|
||||
jsonMapmapOfStringAny, _ := json.Marshal(dst.MapmapOfStringAny)
|
||||
if string(jsonMapmapOfStringAny) == "{}" { // empty struct
|
||||
dst.MapmapOfStringAny = nil
|
||||
} else {
|
||||
match++
|
||||
}
|
||||
} else {
|
||||
dst.MapmapOfStringAny = nil
|
||||
}
|
||||
|
||||
if match > 1 { // more than 1 match
|
||||
// reset to nil
|
||||
dst.ArrayOfMapmapOfStringAny = nil
|
||||
dst.MapmapOfStringAny = nil
|
||||
|
||||
return fmt.Errorf("data matches more than one schema in oneOf(IncidentData)")
|
||||
} else if match == 1 {
|
||||
return nil // exactly one match
|
||||
} else { // no match
|
||||
return fmt.Errorf("data failed to match schemas in oneOf(IncidentData)")
|
||||
}
|
||||
}
|
||||
|
||||
// Marshal data from the first non-nil pointers in the struct to JSON
|
||||
func (src IncidentData) MarshalJSON() ([]byte, error) {
|
||||
if src.ArrayOfMapmapOfStringAny != nil {
|
||||
return json.Marshal(&src.ArrayOfMapmapOfStringAny)
|
||||
}
|
||||
|
||||
if src.MapmapOfStringAny != nil {
|
||||
return json.Marshal(&src.MapmapOfStringAny)
|
||||
}
|
||||
|
||||
return nil, nil // no data in oneOf schemas
|
||||
}
|
||||
|
||||
// Get the actual instance
|
||||
func (obj *IncidentData) GetActualInstance() (interface{}) {
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
if obj.ArrayOfMapmapOfStringAny != nil {
|
||||
return obj.ArrayOfMapmapOfStringAny
|
||||
}
|
||||
|
||||
if obj.MapmapOfStringAny != nil {
|
||||
return obj.MapmapOfStringAny
|
||||
}
|
||||
|
||||
// all schemas are nil
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullableIncidentData struct {
|
||||
value *IncidentData
|
||||
isSet bool
|
||||
}
|
||||
|
||||
func (v NullableIncidentData) Get() *IncidentData {
|
||||
return v.value
|
||||
}
|
||||
|
||||
func (v *NullableIncidentData) Set(val *IncidentData) {
|
||||
v.value = val
|
||||
v.isSet = true
|
||||
}
|
||||
|
||||
func (v NullableIncidentData) IsSet() bool {
|
||||
return v.isSet
|
||||
}
|
||||
|
||||
func (v *NullableIncidentData) Unset() {
|
||||
v.value = nil
|
||||
v.isSet = false
|
||||
}
|
||||
|
||||
func NewNullableIncidentData(val *IncidentData) *NullableIncidentData {
|
||||
return &NullableIncidentData{value: val, isSet: true}
|
||||
}
|
||||
|
||||
func (v NullableIncidentData) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(v.value)
|
||||
}
|
||||
|
||||
func (v *NullableIncidentData) UnmarshalJSON(src []byte) error {
|
||||
v.isSet = true
|
||||
return json.Unmarshal(src, &v.value)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@ replace go-petstore => ./go-petstore
|
||||
require (
|
||||
github.com/stretchr/testify v1.8.4
|
||||
go-petstore v0.0.0-00010101000000-000000000000
|
||||
golang.org/x/net v0.12.0 // indirect
|
||||
golang.org/x/oauth2 v0.10.0
|
||||
golang.org/x/net v0.20.0 // indirect
|
||||
golang.org/x/oauth2 v0.16.0
|
||||
)
|
||||
|
||||
@@ -888,6 +888,7 @@ golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
||||
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
@@ -1019,6 +1020,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
|
||||
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@@ -1060,6 +1063,8 @@ golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4
|
||||
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
|
||||
golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8=
|
||||
golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI=
|
||||
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
|
||||
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -1157,6 +1162,7 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
@@ -1168,6 +1174,7 @@ golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
||||
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
|
||||
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@@ -1185,6 +1192,7 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
|
||||
Reference in New Issue
Block a user