[Go][Experimental] better oneOf and anyOf implementation (#6166)

* diff oneOf implementation

* update oas3 samples

* fix imports

* remove commented code
This commit is contained in:
William Cheng 2020-05-11 17:25:38 +08:00 committed by GitHub
parent d22bea216c
commit edb94f7ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
126 changed files with 1122 additions and 893 deletions

View File

@ -42,7 +42,6 @@ public class GoClientExperimentalCodegen extends GoClientCodegen {
embeddedTemplateDir = templateDir = "go-experimental";
usesOptionals = false;
useOneOfInterfaces = true;
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata).stability(Stability.EXPERIMENTAL).build();
}
@ -167,6 +166,8 @@ public class GoClientExperimentalCodegen extends GoClientCodegen {
// must be invoked at the beginning of this method.
objs = super.postProcessModels(objs);
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
List<Map<String, Object>> models = (List<Map<String, Object>>) objs.get("models");
for (Map<String, Object> m : models) {
Object v = m.get("model");
@ -193,21 +194,22 @@ public class GoClientExperimentalCodegen extends GoClientCodegen {
+ param.dataType.substring(1);
}
}
}
}
return objs;
// additional import for different cases
// oneOf
if (model.oneOf != null && !model.oneOf.isEmpty()) {
imports.add(createMapping("import", "fmt"));
}
@Override
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
for (String i : Arrays.asList("fmt")) {
Map<String, String> oneImport = new HashMap<String, String>() {{
put("import", i);
}};
if (!imports.contains(oneImport)) {
imports.add(oneImport);
// anyOf
if (model.anyOf != null && !model.anyOf.isEmpty()) {
imports.add(createMapping("import", "fmt"));
}
}
}
return objs;
}
@Override

View File

@ -381,7 +381,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
return nil
}
if jsonCheck.MatchString(contentType) {
if err = json.Unmarshal(b, v); err != nil {
if actualObj, ok := v.(interface{GetActualInstance() interface{}}); ok { // oneOf, anyOf schemas
if unmarshalObj, ok := actualObj.(interface{UnmarshalJSON([]byte) error}); ok { // make sure it has UnmarshalJSON defined
if err = unmarshalObj.UnmarshalJSON(b); err!= nil {
return err
}
} else {
errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined")
}
} else if err = json.Unmarshal(b, v); err != nil { // simple model
return err
}
return nil

View File

@ -11,373 +11,10 @@ import (
{{#model}}
{{#isEnum}}
// {{{classname}}} {{#description}}{{{.}}}{{/description}}{{^description}}the model '{{{classname}}}'{{/description}}
type {{{classname}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}}
// List of {{{name}}}
const (
{{#allowableValues}}
{{#enumVars}}
{{^-first}}
{{/-first}}
{{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}}
{{/enumVars}}
{{/allowableValues}}
)
// Ptr returns reference to {{{name}}} value
func (v {{{classname}}}) Ptr() *{{{classname}}} {
return &v
}
{{>model_enum}}
{{/isEnum}}
{{^isEnum}}
// {{classname}}{{#description}} {{{description}}}{{/description}}{{^description}} struct for {{{classname}}}{{/description}}
type {{classname}} struct {
{{#vendorExtensions.x-is-one-of-interface}}
{{classname}}Interface interface { {{#discriminator}}{{propertyGetter}}() {{propertyType}}{{/discriminator}} }
{{/vendorExtensions.x-is-one-of-interface}}
{{^vendorExtensions.x-is-one-of-interface}}
{{#parent}}
{{^isMapModel}}
{{{parent}}}
{{/isMapModel}}
{{/parent}}
{{#vars}}
{{^-first}}
{{/-first}}
{{#description}}
// {{{description}}}
{{/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-is-one-of-interface}}
}
{{#oneOf}}{{#-first}}{{>model_oneof}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{>model_anyof}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>model_simple}}{{/anyOf}}{{/oneOf}}
{{/isEnum}}
{{^isEnum}}
{{^vendorExtensions.x-is-one-of-interface}}
// 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
// will change when the set of required properties is changed
func New{{classname}}({{#vars}}{{#required}}{{nameInCamelCase}} {{dataType}}, {{/required}}{{/vars}}) *{{classname}} {
this := {{classname}}{}
{{#vars}}
{{#required}}
this.{{name}} = {{nameInCamelCase}}
{{/required}}
{{^required}}
{{#defaultValue}}
{{^vendorExtensions.x-golang-is-container}}
{{#isNullable}}
var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}}
this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}})
{{/isNullable}}
{{^isNullable}}
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
this.{{name}} = &{{nameInCamelCase}}
{{/isNullable}}
{{/vendorExtensions.x-golang-is-container}}
{{/defaultValue}}
{{/required}}
{{/vars}}
return &this
}
// New{{classname}}WithDefaults instantiates a new {{classname}} 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 New{{classname}}WithDefaults() *{{classname}} {
this := {{classname}}{}
{{#vars}}
{{#defaultValue}}
{{^vendorExtensions.x-golang-is-container}}
{{#isNullable}}
{{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}}
var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}}
this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}})
{{/isNullable}}
{{^isNullable}}
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
this.{{name}} = {{^required}}&{{/required}}{{nameInCamelCase}}
{{/isNullable}}
{{/vendorExtensions.x-golang-is-container}}
{{/defaultValue}}
{{/vars}}
return &this
}
{{#vars}}
{{#required}}
// Get{{name}} returns the {{name}} field value
{{#isNullable}}
// If the value is explicit nil, the zero value for {{vendorExtensions.x-go-base-type}} will be returned
{{/isNullable}}
func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
if o == nil {{#isNullable}}{{^vendorExtensions.x-golang-is-container}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
var ret {{vendorExtensions.x-go-base-type}}
return ret
}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
return o.{{name}}
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
return *o.{{name}}.Get()
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
return o.{{name}}
{{/isNullable}}
}
// Get{{name}}Ok returns a tuple with the {{name}} field value
// and a boolean to check if the value has been set.
{{#isNullable}}
// NOTE: If the value is an explicit nil, `nil, true` will be returned
{{/isNullable}}
func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, bool) {
if o == nil {{#isNullable}}{{#vendorExtensions.x-golang-is-container}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
return nil, false
}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
return &o.{{name}}, true
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
return o.{{name}}.Get(), o.{{name}}.IsSet()
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
return &o.{{name}}, true
{{/isNullable}}
}
// Set{{name}} sets field value
func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) {
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
o.{{name}} = v
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
o.{{name}}.Set(&v)
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
o.{{name}} = v
{{/isNullable}}
}
{{/required}}
{{^required}}
// Get{{name}} returns the {{name}} field value if set, zero value otherwise{{#isNullable}} (both if not set or set to explicit null){{/isNullable}}.
func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{^vendorExtensions.x-golang-is-container}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
var ret {{vendorExtensions.x-go-base-type}}
return ret
}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
return o.{{name}}
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
return *o.{{name}}.Get()
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
return *o.{{name}}
{{/isNullable}}
}
// Get{{name}}Ok returns a tuple with the {{name}} field value if set, nil otherwise
// and a boolean to check if the value has been set.
{{#isNullable}}
// NOTE: If the value is an explicit nil, `nil, true` will be returned
{{/isNullable}}
func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, bool) {
if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-is-container}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
return nil, false
}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
return &o.{{name}}, true
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
return o.{{name}}.Get(), o.{{name}}.IsSet()
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
return o.{{name}}, true
{{/isNullable}}
}
// Has{{name}} returns a boolean if a field has been set.
func (o *{{classname}}) Has{{name}}() bool {
if o != nil && {{^isNullable}}o.{{name}} != nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-is-container}}o.{{name}} != nil{{/vendorExtensions.x-golang-is-container}}{{^vendorExtensions.x-golang-is-container}}o.{{name}}.IsSet(){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
return true
}
return false
}
// Set{{name}} gets a reference to the given {{dataType}} and assigns it to the {{name}} field.
func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) {
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
o.{{name}} = v
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
o.{{name}}.Set(&v)
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
o.{{name}} = &v
{{/isNullable}}
}
{{#isNullable}}
{{^vendorExtensions.x-golang-is-container}}
// Set{{name}}Nil sets the value for {{name}} to be an explicit nil
func (o *{{classname}}) Set{{name}}Nil() {
o.{{name}}.Set(nil)
}
// Unset{{name}} ensures that no value is present for {{name}}, not even an explicit nil
func (o *{{classname}}) Unset{{name}}() {
o.{{name}}.Unset()
}
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{/required}}
{{/vars}}
func (o {{classname}}) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
{{#parent}}
{{^isMapModel}}
serialized{{parent}}, err{{parent}} := json.Marshal(o.{{parent}})
if err{{parent}} != nil {
return []byte{}, err{{parent}}
}
err{{parent}} = json.Unmarshal([]byte(serialized{{parent}}), &toSerialize)
if err{{parent}} != nil {
return []byte{}, err{{parent}}
}
{{/isMapModel}}
{{/parent}}
{{#vars}}
{{! if argument is nullable, only serialize it if it is set}}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
{{! support for container fields is not ideal at this point because of lack of Nullable* types}}
if o.{{name}} != nil {
toSerialize["{{baseName}}"] = o.{{name}}
}
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
if {{#required}}true{{/required}}{{^required}}o.{{name}}.IsSet(){{/required}} {
toSerialize["{{baseName}}"] = o.{{name}}.Get()
}
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{! if argument is not nullable, don't set it if it is nil}}
{{^isNullable}}
if {{#required}}true{{/required}}{{^required}}o.{{name}} != nil{{/required}} {
toSerialize["{{baseName}}"] = o.{{name}}
}
{{/isNullable}}
{{/vars}}
return json.Marshal(toSerialize)
}
{{/vendorExtensions.x-is-one-of-interface}}
{{#vendorExtensions.x-is-one-of-interface}}
func (s {{classname}}) MarshalJSON() ([]byte, error) {
return json.Marshal(s.{{classname}}Interface)
}
func (s *{{classname}}) UnmarshalJSON(src []byte) error {
var err error
{{#discriminator}}
var unmarshaled map[string]interface{}
err = json.Unmarshal(src, &unmarshaled)
if err != nil {
return err
}
if v, ok := unmarshaled["{{discriminator.propertyBaseName}}"]; ok {
switch v {
{{#discriminator.mappedModels}}
case "{{mappingName}}":
var result *{{modelName}} = &{{modelName}}{}
err = json.Unmarshal(src, result)
if err != nil {
return err
}
s.{{classname}}Interface = result
return nil
{{/discriminator.mappedModels}}
default:
return fmt.Errorf("No oneOf model has '{{discriminator.propertyBaseName}}' equal to %s", v)
}
} else {
return fmt.Errorf("Discriminator property '{{discriminator.propertyBaseName}}' not found in unmarshaled payload: %+v", unmarshaled)
}
{{/discriminator}}
{{^discriminator}}
{{#oneOf}}
var unmarshaled{{{.}}} *{{{.}}} = &{{{.}}}{}
err = json.Unmarshal(src, unmarshaled{{{.}}})
if err == nil {
s.{{classname}}Interface = unmarshaled{{{.}}}
return nil
}
{{/oneOf}}
return fmt.Errorf("No oneOf model could be deserialized from payload: %s", string(src))
{{/discriminator}}
}
{{/vendorExtensions.x-is-one-of-interface}}
{{#vendorExtensions.x-implements}}
// As{{{.}}} wraps this instance of {{classname}} in {{{.}}}
func (s *{{classname}}) As{{{.}}}() {{{.}}} {
return {{{.}}}{ {{{.}}}Interface: s }
}
{{/vendorExtensions.x-implements}}
{{/isEnum}}
type Nullable{{{classname}}} struct {
value *{{{classname}}}
isSet bool
}
func (v Nullable{{classname}}) Get() *{{classname}} {
return v.value
}
func (v *Nullable{{classname}}) Set(val *{{classname}}) {
v.value = val
v.isSet = true
}
func (v Nullable{{classname}}) IsSet() bool {
return v.isSet
}
func (v *Nullable{{classname}}) Unset() {
v.value = nil
v.isSet = false
}
func NewNullable{{classname}}(val *{{classname}}) *Nullable{{classname}} {
return &Nullable{{classname}}{value: val, isSet: true}
}
func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}
{{/model}}
{{/models}}

View File

@ -0,0 +1,38 @@
// {{classname}}{{#description}} {{{description}}}{{/description}}{{^description}} struct for {{{classname}}}{{/description}}
type {{classname}} struct {
{{#anyOf}}
{{{.}}} *{{{.}}}
{{/anyOf}}
}
// Unmarshal JSON data into any of the pointers in the struct
func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
var err error
{{#anyOf}}
// try to unmarshal JSON data into {{{.}}}
err = json.Unmarshal(data, &dst.{{{.}}});
if err == nil {
json{{{.}}}, _ := json.Marshal(dst.{{{.}}})
if string(json{{{.}}}) == "{}" { // empty struct
dst.{{{.}}} = nil
} else {
return nil // data stored in dst.{{{.}}}, return on the first match
}
} else {
dst.{{{.}}} = nil
}
{{/anyOf}}
return fmt.Errorf("Data failed to match schemas in anyOf({{classname}})")
}
// Marshal data from the first non-nil pointers in the struct to JSON
func (src *{{classname}}) MarshalJSON() ([]byte, error) {
{{#anyOf}}
if src.{{{.}}} != nil {
return json.Marshal(&src.{{{.}}})
}
{{/anyOf}}
return nil, nil // no data in anyOf schemas
}

View File

@ -0,0 +1,54 @@
// {{{classname}}} {{#description}}{{{.}}}{{/description}}{{^description}}the model '{{{classname}}}'{{/description}}
type {{{classname}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}}
// List of {{{name}}}
const (
{{#allowableValues}}
{{#enumVars}}
{{^-first}}
{{/-first}}
{{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}}
{{/enumVars}}
{{/allowableValues}}
)
// Ptr returns reference to {{{name}}} value
func (v {{{classname}}}) Ptr() *{{{classname}}} {
return &v
}
type Nullable{{{classname}}} struct {
value *{{{classname}}}
isSet bool
}
func (v Nullable{{classname}}) Get() *{{classname}} {
return v.value
}
func (v *Nullable{{classname}}) Set(val *{{classname}}) {
v.value = val
v.isSet = true
}
func (v Nullable{{classname}}) IsSet() bool {
return v.isSet
}
func (v *Nullable{{classname}}) Unset() {
v.value = nil
v.isSet = false
}
func NewNullable{{classname}}(val *{{classname}}) *Nullable{{classname}} {
return &Nullable{{classname}}{value: val, isSet: true}
}
func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,57 @@
// {{classname}} - {{#description}}{{{description}}}{{/description}}{{^description}}struct for {{{classname}}}{{/description}}
type {{classname}} struct {
{{#oneOf}}
{{{.}}} *{{{.}}}
{{/oneOf}}
}
// Unmarshl JSON data into one of the pointers in the struct
func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
var err error
match := 0
{{#oneOf}}
// try to unmarshal data into {{{.}}}
err = json.Unmarshal(data, &dst.{{{.}}});
if err == nil {
json{{{.}}}, _ := json.Marshal(dst.{{{.}}})
if string(json{{{.}}}) == "{}" { // empty struct
dst.{{{.}}} = nil
} else {
match++
}
} else {
dst.{{{.}}} = nil
}
{{/oneOf}}
if match > 1 { // more than 1 match
return fmt.Errorf("Data matches more than one schema in oneOf({{classname}})")
} else if match == 1 {
return nil // exactly one match
} else { // no match
return fmt.Errorf("Data failed to match schemas in oneOf({{classname}})")
}
}
// Marshl data from the first non-nil pointers in the struct to JSON
func (src *{{classname}}) MarshalJSON() ([]byte, error) {
{{#oneOf}}
if src.{{{.}}} != nil {
return json.Marshal(&src.{{{.}}})
}
{{/oneOf}}
return nil, nil // no data in oneOf schemas
}
// Get the actual instance
func (obj *{{classname}}) GetActualInstance() (interface{}) {
{{#oneOf}}
if obj.{{{.}}} != nil {
return obj.{{{.}}}
}
{{/oneOf}}
// all schemas are nil
return nil
}

View File

@ -0,0 +1,286 @@
// {{classname}}{{#description}} {{{description}}}{{/description}}{{^description}} struct for {{{classname}}}{{/description}}
type {{classname}} struct {
{{#parent}}
{{^isMapModel}}
{{{parent}}}
{{/isMapModel}}
{{/parent}}
{{#vars}}
{{^-first}}
{{/-first}}
{{#description}}
// {{{description}}}
{{/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}}
}
// 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
// will change when the set of required properties is changed
func New{{classname}}({{#vars}}{{#required}}{{nameInCamelCase}} {{dataType}}, {{/required}}{{/vars}}) *{{classname}} {
this := {{classname}}{}
{{#vars}}
{{#required}}
this.{{name}} = {{nameInCamelCase}}
{{/required}}
{{^required}}
{{#defaultValue}}
{{^vendorExtensions.x-golang-is-container}}
{{#isNullable}}
var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}}
this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}})
{{/isNullable}}
{{^isNullable}}
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
this.{{name}} = &{{nameInCamelCase}}
{{/isNullable}}
{{/vendorExtensions.x-golang-is-container}}
{{/defaultValue}}
{{/required}}
{{/vars}}
return &this
}
// New{{classname}}WithDefaults instantiates a new {{classname}} 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 New{{classname}}WithDefaults() *{{classname}} {
this := {{classname}}{}
{{#vars}}
{{#defaultValue}}
{{^vendorExtensions.x-golang-is-container}}
{{#isNullable}}
{{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}}
var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}}
this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}})
{{/isNullable}}
{{^isNullable}}
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
this.{{name}} = {{^required}}&{{/required}}{{nameInCamelCase}}
{{/isNullable}}
{{/vendorExtensions.x-golang-is-container}}
{{/defaultValue}}
{{/vars}}
return &this
}
{{#vars}}
{{#required}}
// Get{{name}} returns the {{name}} field value
{{#isNullable}}
// If the value is explicit nil, the zero value for {{vendorExtensions.x-go-base-type}} will be returned
{{/isNullable}}
func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
if o == nil {{#isNullable}}{{^vendorExtensions.x-golang-is-container}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
var ret {{vendorExtensions.x-go-base-type}}
return ret
}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
return o.{{name}}
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
return *o.{{name}}.Get()
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
return o.{{name}}
{{/isNullable}}
}
// Get{{name}}Ok returns a tuple with the {{name}} field value
// and a boolean to check if the value has been set.
{{#isNullable}}
// NOTE: If the value is an explicit nil, `nil, true` will be returned
{{/isNullable}}
func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, bool) {
if o == nil {{#isNullable}}{{#vendorExtensions.x-golang-is-container}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
return nil, false
}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
return &o.{{name}}, true
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
return o.{{name}}.Get(), o.{{name}}.IsSet()
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
return &o.{{name}}, true
{{/isNullable}}
}
// Set{{name}} sets field value
func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) {
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
o.{{name}} = v
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
o.{{name}}.Set(&v)
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
o.{{name}} = v
{{/isNullable}}
}
{{/required}}
{{^required}}
// Get{{name}} returns the {{name}} field value if set, zero value otherwise{{#isNullable}} (both if not set or set to explicit null){{/isNullable}}.
func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{^vendorExtensions.x-golang-is-container}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
var ret {{vendorExtensions.x-go-base-type}}
return ret
}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
return o.{{name}}
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
return *o.{{name}}.Get()
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
return *o.{{name}}
{{/isNullable}}
}
// Get{{name}}Ok returns a tuple with the {{name}} field value if set, nil otherwise
// and a boolean to check if the value has been set.
{{#isNullable}}
// NOTE: If the value is an explicit nil, `nil, true` will be returned
{{/isNullable}}
func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, bool) {
if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-is-container}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
return nil, false
}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
return &o.{{name}}, true
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
return o.{{name}}.Get(), o.{{name}}.IsSet()
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
return o.{{name}}, true
{{/isNullable}}
}
// Has{{name}} returns a boolean if a field has been set.
func (o *{{classname}}) Has{{name}}() bool {
if o != nil && {{^isNullable}}o.{{name}} != nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-is-container}}o.{{name}} != nil{{/vendorExtensions.x-golang-is-container}}{{^vendorExtensions.x-golang-is-container}}o.{{name}}.IsSet(){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
return true
}
return false
}
// Set{{name}} gets a reference to the given {{dataType}} and assigns it to the {{name}} field.
func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) {
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
o.{{name}} = v
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
o.{{name}}.Set(&v)
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{^isNullable}}
o.{{name}} = &v
{{/isNullable}}
}
{{#isNullable}}
{{^vendorExtensions.x-golang-is-container}}
// Set{{name}}Nil sets the value for {{name}} to be an explicit nil
func (o *{{classname}}) Set{{name}}Nil() {
o.{{name}}.Set(nil)
}
// Unset{{name}} ensures that no value is present for {{name}}, not even an explicit nil
func (o *{{classname}}) Unset{{name}}() {
o.{{name}}.Unset()
}
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{/required}}
{{/vars}}
func (o {{classname}}) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
{{#parent}}
{{^isMapModel}}
serialized{{parent}}, err{{parent}} := json.Marshal(o.{{parent}})
if err{{parent}} != nil {
return []byte{}, err{{parent}}
}
err{{parent}} = json.Unmarshal([]byte(serialized{{parent}}), &toSerialize)
if err{{parent}} != nil {
return []byte{}, err{{parent}}
}
{{/isMapModel}}
{{/parent}}
{{#vars}}
{{! if argument is nullable, only serialize it if it is set}}
{{#isNullable}}
{{#vendorExtensions.x-golang-is-container}}
{{! support for container fields is not ideal at this point because of lack of Nullable* types}}
if o.{{name}} != nil {
toSerialize["{{baseName}}"] = o.{{name}}
}
{{/vendorExtensions.x-golang-is-container}}
{{^vendorExtensions.x-golang-is-container}}
if {{#required}}true{{/required}}{{^required}}o.{{name}}.IsSet(){{/required}} {
toSerialize["{{baseName}}"] = o.{{name}}.Get()
}
{{/vendorExtensions.x-golang-is-container}}
{{/isNullable}}
{{! if argument is not nullable, don't set it if it is nil}}
{{^isNullable}}
if {{#required}}true{{/required}}{{^required}}o.{{name}} != nil{{/required}} {
toSerialize["{{baseName}}"] = o.{{name}}
}
{{/isNullable}}
{{/vars}}
return json.Marshal(toSerialize)
}
type Nullable{{{classname}}} struct {
value *{{{classname}}}
isSet bool
}
func (v Nullable{{classname}}) Get() *{{classname}} {
return v.value
}
func (v *Nullable{{classname}}) Set(val *{{classname}}) {
v.value = val
v.isSet = true
}
func (v Nullable{{classname}}) IsSet() bool {
return v.isSet
}
func (v *Nullable{{classname}}) Unset() {
v.value = nil
v.isSet = false
}
func NewNullable{{classname}}(val *{{classname}}) *Nullable{{classname}} {
return &Nullable{{classname}}{value: val, isSet: true}
}
func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -380,7 +380,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
return nil
}
if jsonCheck.MatchString(contentType) {
if err = json.Unmarshal(b, v); err != nil {
if actualObj, ok := v.(interface{GetActualInstance() interface{}}); ok { // oneOf, anyOf schemas
if unmarshalObj, ok := actualObj.(interface{UnmarshalJSON([]byte) error}); ok { // make sure it has UnmarshalJSON defined
if err = unmarshalObj.UnmarshalJSON(b); err!= nil {
return err
}
} else {
errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined")
}
} else if err = json.Unmarshal(b, v); err != nil { // simple model
return err
}
return nil

View File

@ -146,3 +146,4 @@ func (v *NullableModel200Response) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesAnyType) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesArray) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesBoolean) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -470,3 +470,4 @@ func (v *NullableAdditionalPropertiesClass) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesInteger) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesNumber) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesObject) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesString) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -143,3 +143,4 @@ func (v *NullableAnimal) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -182,3 +182,4 @@ func (v *NullableApiResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableArrayOfArrayOfNumberOnly) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableArrayOfNumberOnly) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -182,3 +182,4 @@ func (v *NullableArrayTest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -119,3 +119,4 @@ func (v *NullableBigCat) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableBigCatAllOf) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -291,3 +291,4 @@ func (v *NullableCapitalization) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -119,3 +119,4 @@ func (v *NullableCat) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableCatAllOf) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -141,3 +141,4 @@ func (v *NullableCategory) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableClassModel) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableClient) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -119,3 +119,4 @@ func (v *NullableDog) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableDogAllOf) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -146,3 +146,4 @@ func (v *NullableEnumArrays) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -28,7 +28,6 @@ func (v EnumClass) Ptr() *EnumClass {
return &v
}
type NullableEnumClass struct {
value *EnumClass
isSet bool
@ -64,3 +63,4 @@ func (v *NullableEnumClass) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -247,3 +247,4 @@ func (v *NullableEnumTest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -111,3 +111,4 @@ func (v *NullableFile) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -146,3 +146,4 @@ func (v *NullableFileSchemaTestClass) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -552,3 +552,4 @@ func (v *NullableFormatTest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -146,3 +146,4 @@ func (v *NullableHasOnlyReadOnly) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableList) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -218,3 +218,4 @@ func (v *NullableMapTest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -183,3 +183,4 @@ func (v *NullableMixedPropertiesAndAdditionalPropertiesClass) UnmarshalJSON(src
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -211,3 +211,4 @@ func (v *NullableName) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableNumberOnly) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -296,3 +296,4 @@ func (v *NullableOrder) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -182,3 +182,4 @@ func (v *NullableOuterComposite) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -28,7 +28,6 @@ func (v OuterEnum) Ptr() *OuterEnum {
return &v
}
type NullableOuterEnum struct {
value *OuterEnum
isSet bool
@ -64,3 +63,4 @@ func (v *NullableOuterEnum) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -277,3 +277,4 @@ func (v *NullablePet) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -146,3 +146,4 @@ func (v *NullableReadOnlyFirst) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableReturn) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableSpecialModelName) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -146,3 +146,4 @@ func (v *NullableTag) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -223,3 +223,4 @@ func (v *NullableTypeHolderDefault) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -248,3 +248,4 @@ func (v *NullableTypeHolderExample) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -363,3 +363,4 @@ func (v *NullableUser) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -1118,3 +1118,4 @@ func (v *NullableXmlItem) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -1919,7 +1919,6 @@ components:
properties:
color:
type: string
x-one-of-name: Fruit
apple:
properties:
cultivar:
@ -1939,7 +1938,6 @@ components:
oneOf:
- $ref: '#/components/schemas/whale'
- $ref: '#/components/schemas/zebra'
x-one-of-name: Mammal
whale:
properties:
hasBaleen:
@ -1975,7 +1973,6 @@ components:
oneOf:
- $ref: '#/components/schemas/appleReq'
- $ref: '#/components/schemas/bananaReq'
x-one-of-name: FruitReq
appleReq:
properties:
cultivar:

View File

@ -393,7 +393,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
return nil
}
if jsonCheck.MatchString(contentType) {
if err = json.Unmarshal(b, v); err != nil {
if actualObj, ok := v.(interface{GetActualInstance() interface{}}); ok { // oneOf, anyOf schemas
if unmarshalObj, ok := actualObj.(interface{UnmarshalJSON([]byte) error}); ok { // make sure it has UnmarshalJSON defined
if err = unmarshalObj.UnmarshalJSON(b); err!= nil {
return err
}
} else {
errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined")
}
} else if err = json.Unmarshal(b, v); err != nil { // simple model
return err
}
return nil

View File

@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Cultivar** | Pointer to **string** | | [optional]
**Color** | Pointer to **string** | | [optional]
## Methods
@ -51,37 +50,6 @@ SetCultivar sets Cultivar field to given value.
HasCultivar returns a boolean if a field has been set.
### GetColor
`func (o *Apple) GetColor() string`
GetColor returns the Color field if non-nil, zero value otherwise.
### GetColorOk
`func (o *Apple) GetColorOk() (*string, bool)`
GetColorOk returns a tuple with the Color field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetColor
`func (o *Apple) SetColor(v string)`
SetColor sets Color field to given value.
### HasColor
`func (o *Apple) HasColor() bool`
HasColor returns a boolean if a field has been set.
### AsFruit
`func (s *Apple) AsFruit() Fruit`
Convenience method to wrap this instance of Apple in Fruit
[[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

@ -72,12 +72,6 @@ SetMealy sets Mealy field to given value.
HasMealy returns a boolean if a field has been set.
### AsFruitReq
`func (s *AppleReq) AsFruitReq() FruitReq`
Convenience method to wrap this instance of AppleReq in FruitReq
[[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

@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**LengthCm** | Pointer to **float32** | | [optional]
**Color** | Pointer to **string** | | [optional]
## Methods
@ -51,37 +50,6 @@ SetLengthCm sets LengthCm field to given value.
HasLengthCm returns a boolean if a field has been set.
### GetColor
`func (o *Banana) GetColor() string`
GetColor returns the Color field if non-nil, zero value otherwise.
### GetColorOk
`func (o *Banana) GetColorOk() (*string, bool)`
GetColorOk returns a tuple with the Color field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetColor
`func (o *Banana) SetColor(v string)`
SetColor sets Color field to given value.
### HasColor
`func (o *Banana) HasColor() bool`
HasColor returns a boolean if a field has been set.
### AsFruit
`func (s *Banana) AsFruit() Fruit`
Convenience method to wrap this instance of Banana in Fruit
[[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

@ -72,12 +72,6 @@ SetSweet sets Sweet field to given value.
HasSweet returns a boolean if a field has been set.
### AsFruitReq
`func (s *BananaReq) AsFruitReq() FruitReq`
Convenience method to wrap this instance of BananaReq in FruitReq
[[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

@ -4,10 +4,104 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**FruitInterface** | **interface { }** | An interface that can hold any of the proper implementing types |
**Color** | Pointer to **string** | | [optional]
**Cultivar** | Pointer to **string** | | [optional]
**LengthCm** | Pointer to **float32** | | [optional]
## Methods
### NewFruit
`func NewFruit() *Fruit`
NewFruit instantiates a new Fruit 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
### NewFruitWithDefaults
`func NewFruitWithDefaults() *Fruit`
NewFruitWithDefaults instantiates a new Fruit 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
### GetColor
`func (o *Fruit) GetColor() string`
GetColor returns the Color field if non-nil, zero value otherwise.
### GetColorOk
`func (o *Fruit) GetColorOk() (*string, bool)`
GetColorOk returns a tuple with the Color field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetColor
`func (o *Fruit) SetColor(v string)`
SetColor sets Color field to given value.
### HasColor
`func (o *Fruit) HasColor() bool`
HasColor returns a boolean if a field has been set.
### GetCultivar
`func (o *Fruit) GetCultivar() string`
GetCultivar returns the Cultivar field if non-nil, zero value otherwise.
### GetCultivarOk
`func (o *Fruit) GetCultivarOk() (*string, bool)`
GetCultivarOk returns a tuple with the Cultivar field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetCultivar
`func (o *Fruit) SetCultivar(v string)`
SetCultivar sets Cultivar field to given value.
### HasCultivar
`func (o *Fruit) HasCultivar() bool`
HasCultivar returns a boolean if a field has been set.
### GetLengthCm
`func (o *Fruit) GetLengthCm() float32`
GetLengthCm returns the LengthCm field if non-nil, zero value otherwise.
### GetLengthCmOk
`func (o *Fruit) GetLengthCmOk() (*float32, bool)`
GetLengthCmOk returns a tuple with the LengthCm field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetLengthCm
`func (o *Fruit) SetLengthCm(v float32)`
SetLengthCm sets LengthCm field to given value.
### HasLengthCm
`func (o *Fruit) HasLengthCm() bool`
HasLengthCm 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

@ -4,10 +4,120 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**FruitReqInterface** | **interface { }** | An interface that can hold any of the proper implementing types |
**Cultivar** | Pointer to **string** | |
**Mealy** | Pointer to **bool** | | [optional]
**LengthCm** | Pointer to **float32** | |
**Sweet** | Pointer to **bool** | | [optional]
## Methods
### NewFruitReq
`func NewFruitReq(cultivar string, lengthCm float32, ) *FruitReq`
NewFruitReq instantiates a new FruitReq 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
### NewFruitReqWithDefaults
`func NewFruitReqWithDefaults() *FruitReq`
NewFruitReqWithDefaults instantiates a new FruitReq 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
### GetCultivar
`func (o *FruitReq) GetCultivar() string`
GetCultivar returns the Cultivar field if non-nil, zero value otherwise.
### GetCultivarOk
`func (o *FruitReq) GetCultivarOk() (*string, bool)`
GetCultivarOk returns a tuple with the Cultivar field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetCultivar
`func (o *FruitReq) SetCultivar(v string)`
SetCultivar sets Cultivar field to given value.
### GetMealy
`func (o *FruitReq) GetMealy() bool`
GetMealy returns the Mealy field if non-nil, zero value otherwise.
### GetMealyOk
`func (o *FruitReq) GetMealyOk() (*bool, bool)`
GetMealyOk returns a tuple with the Mealy field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetMealy
`func (o *FruitReq) SetMealy(v bool)`
SetMealy sets Mealy field to given value.
### HasMealy
`func (o *FruitReq) HasMealy() bool`
HasMealy returns a boolean if a field has been set.
### GetLengthCm
`func (o *FruitReq) GetLengthCm() float32`
GetLengthCm returns the LengthCm field if non-nil, zero value otherwise.
### GetLengthCmOk
`func (o *FruitReq) GetLengthCmOk() (*float32, bool)`
GetLengthCmOk returns a tuple with the LengthCm field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetLengthCm
`func (o *FruitReq) SetLengthCm(v float32)`
SetLengthCm sets LengthCm field to given value.
### GetSweet
`func (o *FruitReq) GetSweet() bool`
GetSweet returns the Sweet field if non-nil, zero value otherwise.
### GetSweetOk
`func (o *FruitReq) GetSweetOk() (*bool, bool)`
GetSweetOk returns a tuple with the Sweet field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetSweet
`func (o *FruitReq) SetSweet(v bool)`
SetSweet sets Sweet field to given value.
### HasSweet
`func (o *FruitReq) HasSweet() bool`
HasSweet 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

@ -4,10 +4,125 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**MammalInterface** | **interface { GetClassName() string }** | An interface that can hold any of the proper implementing types |
**HasBaleen** | Pointer to **bool** | | [optional]
**HasTeeth** | Pointer to **bool** | | [optional]
**ClassName** | Pointer to **string** | |
**Type** | Pointer to **string** | | [optional]
## Methods
### NewMammal
`func NewMammal(className string, ) *Mammal`
NewMammal instantiates a new Mammal 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
### NewMammalWithDefaults
`func NewMammalWithDefaults() *Mammal`
NewMammalWithDefaults instantiates a new Mammal 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
### GetHasBaleen
`func (o *Mammal) GetHasBaleen() bool`
GetHasBaleen returns the HasBaleen field if non-nil, zero value otherwise.
### GetHasBaleenOk
`func (o *Mammal) GetHasBaleenOk() (*bool, bool)`
GetHasBaleenOk returns a tuple with the HasBaleen field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetHasBaleen
`func (o *Mammal) SetHasBaleen(v bool)`
SetHasBaleen sets HasBaleen field to given value.
### HasHasBaleen
`func (o *Mammal) HasHasBaleen() bool`
HasHasBaleen returns a boolean if a field has been set.
### GetHasTeeth
`func (o *Mammal) GetHasTeeth() bool`
GetHasTeeth returns the HasTeeth field if non-nil, zero value otherwise.
### GetHasTeethOk
`func (o *Mammal) GetHasTeethOk() (*bool, bool)`
GetHasTeethOk returns a tuple with the HasTeeth field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetHasTeeth
`func (o *Mammal) SetHasTeeth(v bool)`
SetHasTeeth sets HasTeeth field to given value.
### HasHasTeeth
`func (o *Mammal) HasHasTeeth() bool`
HasHasTeeth returns a boolean if a field has been set.
### GetClassName
`func (o *Mammal) GetClassName() string`
GetClassName returns the ClassName field if non-nil, zero value otherwise.
### GetClassNameOk
`func (o *Mammal) GetClassNameOk() (*string, bool)`
GetClassNameOk returns a tuple with the ClassName field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetClassName
`func (o *Mammal) SetClassName(v string)`
SetClassName sets ClassName field to given value.
### GetType
`func (o *Mammal) GetType() string`
GetType returns the Type field if non-nil, zero value otherwise.
### GetTypeOk
`func (o *Mammal) GetTypeOk() (*string, bool)`
GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetType
`func (o *Mammal) SetType(v string)`
SetType sets Type field to given value.
### HasType
`func (o *Mammal) HasType() bool`
HasType 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

@ -98,12 +98,6 @@ SetClassName sets ClassName field to given value.
### AsMammal
`func (s *Whale) AsMammal() Mammal`
Convenience method to wrap this instance of Whale in Mammal
[[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

@ -72,12 +72,6 @@ SetClassName sets ClassName field to given value.
### AsMammal
`func (s *Zebra) AsMammal() Mammal`
Convenience method to wrap this instance of Zebra in Mammal
[[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

@ -146,3 +146,4 @@ func (v *NullableModel200Response) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableSpecialModelName) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -146,3 +146,4 @@ func (v *NullableAdditionalPropertiesClass) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -143,3 +143,4 @@ func (v *NullableAnimal) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -182,3 +182,4 @@ func (v *NullableApiResponse) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -16,7 +16,6 @@ import (
// Apple struct for Apple
type Apple struct {
Cultivar *string `json:"cultivar,omitempty"`
Color *string `json:"color,omitempty"`
}
// NewApple instantiates a new Apple object
@ -68,53 +67,14 @@ func (o *Apple) SetCultivar(v string) {
o.Cultivar = &v
}
// GetColor returns the Color field value if set, zero value otherwise.
func (o *Apple) GetColor() string {
if o == nil || o.Color == nil {
var ret string
return ret
}
return *o.Color
}
// GetColorOk returns a tuple with the Color field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Apple) GetColorOk() (*string, bool) {
if o == nil || o.Color == nil {
return nil, false
}
return o.Color, true
}
// HasColor returns a boolean if a field has been set.
func (o *Apple) HasColor() bool {
if o != nil && o.Color != nil {
return true
}
return false
}
// SetColor gets a reference to the given string and assigns it to the Color field.
func (o *Apple) SetColor(v string) {
o.Color = &v
}
func (o Apple) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Cultivar != nil {
toSerialize["cultivar"] = o.Cultivar
}
if o.Color != nil {
toSerialize["color"] = o.Color
}
return json.Marshal(toSerialize)
}
// AsFruit wraps this instance of Apple in Fruit
func (s *Apple) AsFruit() Fruit {
return Fruit{ FruitInterface: s }
}
type NullableApple struct {
value *Apple
isSet bool
@ -150,3 +110,4 @@ func (v *NullableApple) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -104,10 +104,6 @@ func (o AppleReq) MarshalJSON() ([]byte, error) {
return json.Marshal(toSerialize)
}
// AsFruitReq wraps this instance of AppleReq in FruitReq
func (s *AppleReq) AsFruitReq() FruitReq {
return FruitReq{ FruitReqInterface: s }
}
type NullableAppleReq struct {
value *AppleReq
isSet bool
@ -143,3 +139,4 @@ func (v *NullableAppleReq) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableArrayOfArrayOfNumberOnly) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableArrayOfNumberOnly) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -182,3 +182,4 @@ func (v *NullableArrayTest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -16,7 +16,6 @@ import (
// Banana struct for Banana
type Banana struct {
LengthCm *float32 `json:"lengthCm,omitempty"`
Color *string `json:"color,omitempty"`
}
// NewBanana instantiates a new Banana object
@ -68,53 +67,14 @@ func (o *Banana) SetLengthCm(v float32) {
o.LengthCm = &v
}
// GetColor returns the Color field value if set, zero value otherwise.
func (o *Banana) GetColor() string {
if o == nil || o.Color == nil {
var ret string
return ret
}
return *o.Color
}
// GetColorOk returns a tuple with the Color field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Banana) GetColorOk() (*string, bool) {
if o == nil || o.Color == nil {
return nil, false
}
return o.Color, true
}
// HasColor returns a boolean if a field has been set.
func (o *Banana) HasColor() bool {
if o != nil && o.Color != nil {
return true
}
return false
}
// SetColor gets a reference to the given string and assigns it to the Color field.
func (o *Banana) SetColor(v string) {
o.Color = &v
}
func (o Banana) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.LengthCm != nil {
toSerialize["lengthCm"] = o.LengthCm
}
if o.Color != nil {
toSerialize["color"] = o.Color
}
return json.Marshal(toSerialize)
}
// AsFruit wraps this instance of Banana in Fruit
func (s *Banana) AsFruit() Fruit {
return Fruit{ FruitInterface: s }
}
type NullableBanana struct {
value *Banana
isSet bool
@ -150,3 +110,4 @@ func (v *NullableBanana) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -104,10 +104,6 @@ func (o BananaReq) MarshalJSON() ([]byte, error) {
return json.Marshal(toSerialize)
}
// AsFruitReq wraps this instance of BananaReq in FruitReq
func (s *BananaReq) AsFruitReq() FruitReq {
return FruitReq{ FruitReqInterface: s }
}
type NullableBananaReq struct {
value *BananaReq
isSet bool
@ -143,3 +139,4 @@ func (v *NullableBananaReq) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -291,3 +291,4 @@ func (v *NullableCapitalization) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -119,3 +119,4 @@ func (v *NullableCat) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableCatAllOf) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -141,3 +141,4 @@ func (v *NullableCategory) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableClassModel) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableClient) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -119,3 +119,4 @@ func (v *NullableDog) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -110,3 +110,4 @@ func (v *NullableDogAllOf) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -146,3 +146,4 @@ func (v *NullableEnumArrays) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -28,7 +28,6 @@ func (v EnumClass) Ptr() *EnumClass {
return &v
}
type NullableEnumClass struct {
value *EnumClass
isSet bool
@ -64,3 +63,4 @@ func (v *NullableEnumClass) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -373,3 +373,4 @@ func (v *NullableEnumTest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -111,3 +111,4 @@ func (v *NullableFile) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -146,3 +146,4 @@ func (v *NullableFileSchemaTestClass) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -114,3 +114,4 @@ func (v *NullableFoo) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -590,3 +590,4 @@ func (v *NullableFormatTest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -14,63 +14,75 @@ import (
"fmt"
)
// Fruit struct for Fruit
// Fruit - struct for Fruit
type Fruit struct {
FruitInterface interface { }
Apple *Apple
Banana *Banana
}
func (s Fruit) MarshalJSON() ([]byte, error) {
return json.Marshal(s.FruitInterface)
}
func (s *Fruit) UnmarshalJSON(src []byte) error {
// Unmarshl JSON data into one of the pointers in the struct
func (dst *Fruit) UnmarshalJSON(data []byte) error {
var err error
var unmarshaledApple *Apple = &Apple{}
err = json.Unmarshal(src, unmarshaledApple)
match := 0
// try to unmarshal data into Apple
err = json.Unmarshal(data, &dst.Apple);
if err == nil {
s.FruitInterface = unmarshaledApple
jsonApple, _ := json.Marshal(dst.Apple)
if string(jsonApple) == "{}" { // empty struct
dst.Apple = nil
} else {
match++
}
} else {
dst.Apple = nil
}
// try to unmarshal data into Banana
err = json.Unmarshal(data, &dst.Banana);
if err == nil {
jsonBanana, _ := json.Marshal(dst.Banana)
if string(jsonBanana) == "{}" { // empty struct
dst.Banana = nil
} else {
match++
}
} else {
dst.Banana = nil
}
if match > 1 { // more than 1 match
return fmt.Errorf("Data matches more than one schema in oneOf(Fruit)")
} else if match == 1 {
return nil // exactly one match
} else { // no match
return fmt.Errorf("Data failed to match schemas in oneOf(Fruit)")
}
}
// Marshl data from the first non-nil pointers in the struct to JSON
func (src *Fruit) MarshalJSON() ([]byte, error) {
if src.Apple != nil {
return json.Marshal(&src.Apple)
}
if src.Banana != nil {
return json.Marshal(&src.Banana)
}
return nil, nil // no data in oneOf schemas
}
// Get the actual instance
func (obj *Fruit) GetActualInstance() (interface{}) {
if obj.Apple != nil {
return obj.Apple
}
if obj.Banana != nil {
return obj.Banana
}
// all schemas are nil
return nil
}
var unmarshaledBanana *Banana = &Banana{}
err = json.Unmarshal(src, unmarshaledBanana)
if err == nil {
s.FruitInterface = unmarshaledBanana
return nil
}
return fmt.Errorf("No oneOf model could be deserialized from payload: %s", string(src))
}
type NullableFruit struct {
value *Fruit
isSet bool
}
func (v NullableFruit) Get() *Fruit {
return v.value
}
func (v *NullableFruit) Set(val *Fruit) {
v.value = val
v.isSet = true
}
func (v NullableFruit) IsSet() bool {
return v.isSet
}
func (v *NullableFruit) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableFruit(val *Fruit) *NullableFruit {
return &NullableFruit{value: val, isSet: true}
}
func (v NullableFruit) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableFruit) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -14,63 +14,75 @@ import (
"fmt"
)
// FruitReq struct for FruitReq
// FruitReq - struct for FruitReq
type FruitReq struct {
FruitReqInterface interface { }
AppleReq *AppleReq
BananaReq *BananaReq
}
func (s FruitReq) MarshalJSON() ([]byte, error) {
return json.Marshal(s.FruitReqInterface)
}
func (s *FruitReq) UnmarshalJSON(src []byte) error {
// Unmarshl JSON data into one of the pointers in the struct
func (dst *FruitReq) UnmarshalJSON(data []byte) error {
var err error
var unmarshaledAppleReq *AppleReq = &AppleReq{}
err = json.Unmarshal(src, unmarshaledAppleReq)
match := 0
// try to unmarshal data into AppleReq
err = json.Unmarshal(data, &dst.AppleReq);
if err == nil {
s.FruitReqInterface = unmarshaledAppleReq
jsonAppleReq, _ := json.Marshal(dst.AppleReq)
if string(jsonAppleReq) == "{}" { // empty struct
dst.AppleReq = nil
} else {
match++
}
} else {
dst.AppleReq = nil
}
// try to unmarshal data into BananaReq
err = json.Unmarshal(data, &dst.BananaReq);
if err == nil {
jsonBananaReq, _ := json.Marshal(dst.BananaReq)
if string(jsonBananaReq) == "{}" { // empty struct
dst.BananaReq = nil
} else {
match++
}
} else {
dst.BananaReq = nil
}
if match > 1 { // more than 1 match
return fmt.Errorf("Data matches more than one schema in oneOf(FruitReq)")
} else if match == 1 {
return nil // exactly one match
} else { // no match
return fmt.Errorf("Data failed to match schemas in oneOf(FruitReq)")
}
}
// Marshl data from the first non-nil pointers in the struct to JSON
func (src *FruitReq) MarshalJSON() ([]byte, error) {
if src.AppleReq != nil {
return json.Marshal(&src.AppleReq)
}
if src.BananaReq != nil {
return json.Marshal(&src.BananaReq)
}
return nil, nil // no data in oneOf schemas
}
// Get the actual instance
func (obj *FruitReq) GetActualInstance() (interface{}) {
if obj.AppleReq != nil {
return obj.AppleReq
}
if obj.BananaReq != nil {
return obj.BananaReq
}
// all schemas are nil
return nil
}
var unmarshaledBananaReq *BananaReq = &BananaReq{}
err = json.Unmarshal(src, unmarshaledBananaReq)
if err == nil {
s.FruitReqInterface = unmarshaledBananaReq
return nil
}
return fmt.Errorf("No oneOf model could be deserialized from payload: %s", string(src))
}
type NullableFruitReq struct {
value *FruitReq
isSet bool
}
func (v NullableFruitReq) Get() *FruitReq {
return v.value
}
func (v *NullableFruitReq) Set(val *FruitReq) {
v.value = val
v.isSet = true
}
func (v NullableFruitReq) IsSet() bool {
return v.isSet
}
func (v *NullableFruitReq) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableFruitReq(val *FruitReq) *NullableFruitReq {
return &NullableFruitReq{value: val, isSet: true}
}
func (v NullableFruitReq) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableFruitReq) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -11,174 +11,57 @@ package petstore
import (
"encoding/json"
"fmt"
)
// GmFruit struct for GmFruit
type GmFruit struct {
Color *string `json:"color,omitempty"`
Cultivar *string `json:"cultivar,omitempty"`
LengthCm *float32 `json:"lengthCm,omitempty"`
Apple *Apple
Banana *Banana
}
// NewGmFruit instantiates a new GmFruit 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 NewGmFruit() *GmFruit {
this := GmFruit{}
return &this
// Unmarshal JSON data into any of the pointers in the struct
func (dst *GmFruit) UnmarshalJSON(data []byte) error {
var err error
// try to unmarshal JSON data into Apple
err = json.Unmarshal(data, &dst.Apple);
if err == nil {
jsonApple, _ := json.Marshal(dst.Apple)
if string(jsonApple) == "{}" { // empty struct
dst.Apple = nil
} else {
return nil // data stored in dst.Apple, return on the first match
}
} else {
dst.Apple = nil
}
// NewGmFruitWithDefaults instantiates a new GmFruit 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 NewGmFruitWithDefaults() *GmFruit {
this := GmFruit{}
return &this
// try to unmarshal JSON data into Banana
err = json.Unmarshal(data, &dst.Banana);
if err == nil {
jsonBanana, _ := json.Marshal(dst.Banana)
if string(jsonBanana) == "{}" { // empty struct
dst.Banana = nil
} else {
return nil // data stored in dst.Banana, return on the first match
}
} else {
dst.Banana = nil
}
// GetColor returns the Color field value if set, zero value otherwise.
func (o *GmFruit) GetColor() string {
if o == nil || o.Color == nil {
var ret string
return ret
}
return *o.Color
return fmt.Errorf("Data failed to match schemas in anyOf(GmFruit)")
}
// GetColorOk returns a tuple with the Color field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *GmFruit) GetColorOk() (*string, bool) {
if o == nil || o.Color == nil {
return nil, false
}
return o.Color, true
// Marshal data from the first non-nil pointers in the struct to JSON
func (src *GmFruit) MarshalJSON() ([]byte, error) {
if src.Apple != nil {
return json.Marshal(&src.Apple)
}
// HasColor returns a boolean if a field has been set.
func (o *GmFruit) HasColor() bool {
if o != nil && o.Color != nil {
return true
if src.Banana != nil {
return json.Marshal(&src.Banana)
}
return false
return nil, nil // no data in anyOf schemas
}
// SetColor gets a reference to the given string and assigns it to the Color field.
func (o *GmFruit) SetColor(v string) {
o.Color = &v
}
// GetCultivar returns the Cultivar field value if set, zero value otherwise.
func (o *GmFruit) GetCultivar() string {
if o == nil || o.Cultivar == nil {
var ret string
return ret
}
return *o.Cultivar
}
// GetCultivarOk returns a tuple with the Cultivar field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *GmFruit) GetCultivarOk() (*string, bool) {
if o == nil || o.Cultivar == nil {
return nil, false
}
return o.Cultivar, true
}
// HasCultivar returns a boolean if a field has been set.
func (o *GmFruit) HasCultivar() bool {
if o != nil && o.Cultivar != nil {
return true
}
return false
}
// SetCultivar gets a reference to the given string and assigns it to the Cultivar field.
func (o *GmFruit) SetCultivar(v string) {
o.Cultivar = &v
}
// GetLengthCm returns the LengthCm field value if set, zero value otherwise.
func (o *GmFruit) GetLengthCm() float32 {
if o == nil || o.LengthCm == nil {
var ret float32
return ret
}
return *o.LengthCm
}
// GetLengthCmOk returns a tuple with the LengthCm field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *GmFruit) GetLengthCmOk() (*float32, bool) {
if o == nil || o.LengthCm == nil {
return nil, false
}
return o.LengthCm, true
}
// HasLengthCm returns a boolean if a field has been set.
func (o *GmFruit) HasLengthCm() bool {
if o != nil && o.LengthCm != nil {
return true
}
return false
}
// SetLengthCm gets a reference to the given float32 and assigns it to the LengthCm field.
func (o *GmFruit) SetLengthCm(v float32) {
o.LengthCm = &v
}
func (o GmFruit) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Color != nil {
toSerialize["color"] = o.Color
}
if o.Cultivar != nil {
toSerialize["cultivar"] = o.Cultivar
}
if o.LengthCm != nil {
toSerialize["lengthCm"] = o.LengthCm
}
return json.Marshal(toSerialize)
}
type NullableGmFruit struct {
value *GmFruit
isSet bool
}
func (v NullableGmFruit) Get() *GmFruit {
return v.value
}
func (v *NullableGmFruit) Set(val *GmFruit) {
v.value = val
v.isSet = true
}
func (v NullableGmFruit) IsSet() bool {
return v.isSet
}
func (v *NullableGmFruit) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableGmFruit(val *GmFruit) *NullableGmFruit {
return &NullableGmFruit{value: val, isSet: true}
}
func (v NullableGmFruit) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableGmFruit) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -146,3 +146,4 @@ func (v *NullableHasOnlyReadOnly) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -120,3 +120,4 @@ func (v *NullableHealthCheckResult) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -148,3 +148,4 @@ func (v *NullableInlineObject) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

Some files were not shown because too many files have changed in this diff Show More