diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java index 0bea07e4dba..a72d18959b1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java @@ -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> imports = (List>) objs.get("imports"); + List> models = (List>) objs.get("models"); for (Map m : models) { Object v = m.get("model"); @@ -193,23 +194,24 @@ public class GoClientExperimentalCodegen extends GoClientCodegen { + param.dataType.substring(1); } } + + // additional import for different cases + // oneOf + if (model.oneOf != null && !model.oneOf.isEmpty()) { + imports.add(createMapping("import", "fmt")); + } + + // anyOf + if (model.anyOf != null && !model.anyOf.isEmpty()) { + imports.add(createMapping("import", "fmt")); + } } + + } return objs; } - @Override - public void addImportsToOneOfInterface(List> imports) { - for (String i : Arrays.asList("fmt")) { - Map oneImport = new HashMap() {{ - put("import", i); - }}; - if (!imports.contains(oneImport)) { - imports.add(oneImport); - } - } - } - @Override public Map postProcessOperationsWithModels(Map objs, List allModels) { objs = super.postProcessOperationsWithModels(objs, allModels); @@ -262,7 +264,7 @@ public class GoClientExperimentalCodegen extends GoClientCodegen { return "URL(string: \"https://example.com\")!"; } else if (codegenParameter.isDateTime || codegenParameter.isDate) { // datetime or date return "Get-Date"; - } else{ // numeric + } else { // numeric if (StringUtils.isEmpty(codegenParameter.example)) { return codegenParameter.example; } else { @@ -302,7 +304,7 @@ public class GoClientExperimentalCodegen extends GoClientCodegen { return "\"https://example.com\")!"; } else if (codegenProperty.isDateTime || codegenProperty.isDate) { // datetime or date return "time.Now()"; - } else{ // numeric + } else { // numeric String example; if (StringUtils.isEmpty(codegenProperty.example)) { example = codegenProperty.example; diff --git a/modules/openapi-generator/src/main/resources/go-experimental/client.mustache b/modules/openapi-generator/src/main/resources/go-experimental/client.mustache index b4567ea9d9e..6fe63dcfdf9 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/client.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/client.mustache @@ -169,7 +169,7 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { return nil, err } log.Printf("\n%s\n", string(dump)) - } + } resp, err := c.cfg.HTTPClient.Do(request) if err != nil { @@ -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 diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache index 91a0d12b314..684af1d33c6 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model_anyof.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model_anyof.mustache new file mode 100644 index 00000000000..140cbe4f409 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/go-experimental/model_anyof.mustache @@ -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 +} diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model_enum.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model_enum.mustache new file mode 100644 index 00000000000..648080d099e --- /dev/null +++ b/modules/openapi-generator/src/main/resources/go-experimental/model_enum.mustache @@ -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) +} diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model_oneof.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model_oneof.mustache new file mode 100644 index 00000000000..5e5d7763137 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/go-experimental/model_oneof.mustache @@ -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 +} diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache new file mode 100644 index 00000000000..0a06b4a2743 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache @@ -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) +} diff --git a/samples/client/petstore/go-experimental/go-petstore/client.go b/samples/client/petstore/go-experimental/go-petstore/client.go index 2f97c129ab1..a9bd76d6123 100644 --- a/samples/client/petstore/go-experimental/go-petstore/client.go +++ b/samples/client/petstore/go-experimental/go-petstore/client.go @@ -180,7 +180,7 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { return nil, err } log.Printf("\n%s\n", string(dump)) - } + } resp, err := c.cfg.HTTPClient.Do(request) if err != nil { @@ -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 diff --git a/samples/client/petstore/go-experimental/go-petstore/model_200_response.go b/samples/client/petstore/go-experimental/go-petstore/model_200_response.go index c36b5e6da67..0eea6ec0447 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_200_response.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_200_response.go @@ -146,3 +146,4 @@ func (v *NullableModel200Response) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_any_type.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_any_type.go index f729cf41fb5..9618b3d2a26 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_any_type.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_any_type.go @@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesAnyType) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_array.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_array.go index 643059a3d8f..32b38620ad4 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_array.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_array.go @@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesArray) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_boolean.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_boolean.go index b56dcdc5f35..098e83c9c42 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_boolean.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_boolean.go @@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesBoolean) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go index 9505c3e7e6d..046e91b9075 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go @@ -470,3 +470,4 @@ func (v *NullableAdditionalPropertiesClass) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_integer.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_integer.go index 8f8a9e18f79..dfedb1bc545 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_integer.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_integer.go @@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesInteger) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_number.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_number.go index 4162e4998a1..10428e020c0 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_number.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_number.go @@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesNumber) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_object.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_object.go index 8f3268795b1..6f16a067a4a 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_object.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_object.go @@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesObject) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_string.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_string.go index 61f48829781..b3f971dd13a 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_string.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_string.go @@ -110,3 +110,4 @@ func (v *NullableAdditionalPropertiesString) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_animal.go b/samples/client/petstore/go-experimental/go-petstore/model_animal.go index 3ae97984bcd..a1a7f99db9d 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_animal.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_animal.go @@ -143,3 +143,4 @@ func (v *NullableAnimal) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_api_response.go b/samples/client/petstore/go-experimental/go-petstore/model_api_response.go index 715916da953..f66dd2b120d 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_api_response.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_api_response.go @@ -182,3 +182,4 @@ func (v *NullableApiResponse) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go b/samples/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go index ce9c83bac77..27cc790083d 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go @@ -110,3 +110,4 @@ func (v *NullableArrayOfArrayOfNumberOnly) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go b/samples/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go index 9c8cf80ba85..ba3cdec1dde 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go @@ -110,3 +110,4 @@ func (v *NullableArrayOfNumberOnly) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_array_test_.go b/samples/client/petstore/go-experimental/go-petstore/model_array_test_.go index 05abdef6503..bcb08067162 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_array_test_.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_array_test_.go @@ -182,3 +182,4 @@ func (v *NullableArrayTest) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_big_cat.go b/samples/client/petstore/go-experimental/go-petstore/model_big_cat.go index a853e71eb4c..f4457f7a83c 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_big_cat.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_big_cat.go @@ -119,3 +119,4 @@ func (v *NullableBigCat) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_big_cat_all_of.go b/samples/client/petstore/go-experimental/go-petstore/model_big_cat_all_of.go index 154ce487dbd..f5594871944 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_big_cat_all_of.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_big_cat_all_of.go @@ -110,3 +110,4 @@ func (v *NullableBigCatAllOf) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_capitalization.go b/samples/client/petstore/go-experimental/go-petstore/model_capitalization.go index bd950d64273..782bbab9b1f 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_capitalization.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_capitalization.go @@ -291,3 +291,4 @@ func (v *NullableCapitalization) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_cat.go b/samples/client/petstore/go-experimental/go-petstore/model_cat.go index fa7fe3699da..6f7425873cd 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_cat.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_cat.go @@ -119,3 +119,4 @@ func (v *NullableCat) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_cat_all_of.go b/samples/client/petstore/go-experimental/go-petstore/model_cat_all_of.go index 3ed56df463e..2efc62d2022 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_cat_all_of.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_cat_all_of.go @@ -110,3 +110,4 @@ func (v *NullableCatAllOf) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_category.go b/samples/client/petstore/go-experimental/go-petstore/model_category.go index df490d1668f..e00cc7ba84b 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_category.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_category.go @@ -141,3 +141,4 @@ func (v *NullableCategory) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_class_model.go b/samples/client/petstore/go-experimental/go-petstore/model_class_model.go index 518bf54ac3d..5213ad9d879 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_class_model.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_class_model.go @@ -110,3 +110,4 @@ func (v *NullableClassModel) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_client.go b/samples/client/petstore/go-experimental/go-petstore/model_client.go index cfc309393b1..d1b9ffcc287 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_client.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_client.go @@ -110,3 +110,4 @@ func (v *NullableClient) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_dog.go b/samples/client/petstore/go-experimental/go-petstore/model_dog.go index 607dcf455c5..12a5bee4876 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_dog.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_dog.go @@ -119,3 +119,4 @@ func (v *NullableDog) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_dog_all_of.go b/samples/client/petstore/go-experimental/go-petstore/model_dog_all_of.go index e30f7fafba6..a5a791e50f0 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_dog_all_of.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_dog_all_of.go @@ -110,3 +110,4 @@ func (v *NullableDogAllOf) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_enum_arrays.go b/samples/client/petstore/go-experimental/go-petstore/model_enum_arrays.go index edc98c6ee47..1fbadb34e71 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_enum_arrays.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_enum_arrays.go @@ -146,3 +146,4 @@ func (v *NullableEnumArrays) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_enum_class.go b/samples/client/petstore/go-experimental/go-petstore/model_enum_class.go index fbfbfdd27d4..9c963952561 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_enum_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_enum_class.go @@ -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) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_enum_test_.go b/samples/client/petstore/go-experimental/go-petstore/model_enum_test_.go index ac8736d7f8b..852dd860739 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_enum_test_.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_enum_test_.go @@ -247,3 +247,4 @@ func (v *NullableEnumTest) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_file.go b/samples/client/petstore/go-experimental/go-petstore/model_file.go index 61d028327e0..d7a50dc683a 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_file.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_file.go @@ -111,3 +111,4 @@ func (v *NullableFile) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go b/samples/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go index 92b799a6163..887cd35c752 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go @@ -146,3 +146,4 @@ func (v *NullableFileSchemaTestClass) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_format_test_.go b/samples/client/petstore/go-experimental/go-petstore/model_format_test_.go index 40108c96004..dbccde98dc4 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_format_test_.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_format_test_.go @@ -552,3 +552,4 @@ func (v *NullableFormatTest) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go b/samples/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go index 98d282bb39b..0aa39e6de8c 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go @@ -146,3 +146,4 @@ func (v *NullableHasOnlyReadOnly) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_list.go b/samples/client/petstore/go-experimental/go-petstore/model_list.go index de655731a9b..7966d7b337c 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_list.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_list.go @@ -110,3 +110,4 @@ func (v *NullableList) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_map_test_.go b/samples/client/petstore/go-experimental/go-petstore/model_map_test_.go index 5a1d29671cb..42724f8d875 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_map_test_.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_map_test_.go @@ -218,3 +218,4 @@ func (v *NullableMapTest) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go b/samples/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go index 355bcab8503..21b7cb60ab4 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go @@ -183,3 +183,4 @@ func (v *NullableMixedPropertiesAndAdditionalPropertiesClass) UnmarshalJSON(src v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_name.go b/samples/client/petstore/go-experimental/go-petstore/model_name.go index 39cf81c6a4d..f910dc37c0c 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_name.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_name.go @@ -211,3 +211,4 @@ func (v *NullableName) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_number_only.go b/samples/client/petstore/go-experimental/go-petstore/model_number_only.go index dbb70c5c1f7..6307b2871e9 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_number_only.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_number_only.go @@ -110,3 +110,4 @@ func (v *NullableNumberOnly) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_order.go b/samples/client/petstore/go-experimental/go-petstore/model_order.go index 895475b260c..797c8e9236f 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_order.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_order.go @@ -296,3 +296,4 @@ func (v *NullableOrder) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_outer_composite.go b/samples/client/petstore/go-experimental/go-petstore/model_outer_composite.go index 26a09e445c6..88049de0dac 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_outer_composite.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_outer_composite.go @@ -182,3 +182,4 @@ func (v *NullableOuterComposite) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_outer_enum.go b/samples/client/petstore/go-experimental/go-petstore/model_outer_enum.go index 9cc54d7b5c1..3ea46060c59 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_outer_enum.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_outer_enum.go @@ -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) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_pet.go b/samples/client/petstore/go-experimental/go-petstore/model_pet.go index a72afed465a..876af8724d7 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_pet.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_pet.go @@ -277,3 +277,4 @@ func (v *NullablePet) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_read_only_first.go b/samples/client/petstore/go-experimental/go-petstore/model_read_only_first.go index 277badc58cf..af6291b4c82 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_read_only_first.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_read_only_first.go @@ -146,3 +146,4 @@ func (v *NullableReadOnlyFirst) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_return.go b/samples/client/petstore/go-experimental/go-petstore/model_return.go index b8821489c0e..e6350da030c 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_return.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_return.go @@ -110,3 +110,4 @@ func (v *NullableReturn) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_special_model_name.go b/samples/client/petstore/go-experimental/go-petstore/model_special_model_name.go index 057caa3e4b2..e50eb5d32d1 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_special_model_name.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_special_model_name.go @@ -110,3 +110,4 @@ func (v *NullableSpecialModelName) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_tag.go b/samples/client/petstore/go-experimental/go-petstore/model_tag.go index 6ba3864c612..0f8157a6b7a 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_tag.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_tag.go @@ -146,3 +146,4 @@ func (v *NullableTag) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_type_holder_default.go b/samples/client/petstore/go-experimental/go-petstore/model_type_holder_default.go index f6e8d19a5f5..3ff4e709be1 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_type_holder_default.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_type_holder_default.go @@ -223,3 +223,4 @@ func (v *NullableTypeHolderDefault) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_type_holder_example.go b/samples/client/petstore/go-experimental/go-petstore/model_type_holder_example.go index 1cfe75a9d48..4996f734edc 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_type_holder_example.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_type_holder_example.go @@ -248,3 +248,4 @@ func (v *NullableTypeHolderExample) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_user.go b/samples/client/petstore/go-experimental/go-petstore/model_user.go index 838cf38d979..29f2e3f2652 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_user.go @@ -363,3 +363,4 @@ func (v *NullableUser) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/client/petstore/go-experimental/go-petstore/model_xml_item.go b/samples/client/petstore/go-experimental/go-petstore/model_xml_item.go index 1feb8028225..1d78601f060 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_xml_item.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_xml_item.go @@ -1118,3 +1118,4 @@ func (v *NullableXmlItem) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml index 8f1a907787d..f7bec563071 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml @@ -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: diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/client.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/client.go index 9da20522a22..f38d68a6a60 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/client.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/client.go @@ -183,7 +183,7 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { return nil, err } log.Printf("\n%s\n", string(dump)) - } + } resp, err := c.cfg.HTTPClient.Do(request) if err != nil { @@ -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 diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Apple.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Apple.md index 082c8265bb2..659ddff5731 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Apple.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Apple.md @@ -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) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/AppleReq.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/AppleReq.md index f55210bfa20..31286b79887 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/AppleReq.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/AppleReq.md @@ -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) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Banana.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Banana.md index 731cd4482aa..d803a8f4adc 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Banana.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Banana.md @@ -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) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/BananaReq.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/BananaReq.md index 6bbb22f2f02..2f9887641ec 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/BananaReq.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/BananaReq.md @@ -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) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Fruit.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Fruit.md index fa033d3ef6f..bccbd0baf80 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Fruit.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Fruit.md @@ -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) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FruitReq.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FruitReq.md index c22de780064..0eac3bb84f1 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FruitReq.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FruitReq.md @@ -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) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Mammal.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Mammal.md index 7d3dfe04b15..9f14ab56165 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Mammal.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Mammal.md @@ -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) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Whale.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Whale.md index c8c5ab6398b..8f346ab7206 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Whale.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Whale.md @@ -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) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Zebra.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Zebra.md index 0c51b4a5c23..13fd37c0ed6 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Zebra.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/Zebra.md @@ -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) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_200_response.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_200_response.go index c36b5e6da67..0eea6ec0447 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_200_response.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_200_response.go @@ -146,3 +146,4 @@ func (v *NullableModel200Response) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model__special_model_name_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model__special_model_name_.go index 057caa3e4b2..e50eb5d32d1 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model__special_model_name_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model__special_model_name_.go @@ -110,3 +110,4 @@ func (v *NullableSpecialModelName) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go index eb00215c7fc..941f00027db 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go @@ -146,3 +146,4 @@ func (v *NullableAdditionalPropertiesClass) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_animal.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_animal.go index 3ae97984bcd..a1a7f99db9d 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_animal.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_animal.go @@ -143,3 +143,4 @@ func (v *NullableAnimal) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_api_response.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_api_response.go index 715916da953..f66dd2b120d 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_api_response.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_api_response.go @@ -182,3 +182,4 @@ func (v *NullableApiResponse) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple.go index 0d4d9a879b5..d6800b1ad0a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple.go @@ -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) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple_req.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple_req.go index 3c0bb897545..f5f4cbad71e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple_req.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_apple_req.go @@ -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) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go index ce9c83bac77..27cc790083d 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_array_of_number_only.go @@ -110,3 +110,4 @@ func (v *NullableArrayOfArrayOfNumberOnly) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go index 9c8cf80ba85..ba3cdec1dde 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_of_number_only.go @@ -110,3 +110,4 @@ func (v *NullableArrayOfNumberOnly) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_test_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_test_.go index 05abdef6503..bcb08067162 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_test_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_array_test_.go @@ -182,3 +182,4 @@ func (v *NullableArrayTest) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana.go index 7d54c890043..a4fb1e38640 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana.go @@ -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) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana_req.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana_req.go index e75998e7bc1..eb0d40c61d9 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana_req.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_banana_req.go @@ -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) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_capitalization.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_capitalization.go index bd950d64273..782bbab9b1f 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_capitalization.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_capitalization.go @@ -291,3 +291,4 @@ func (v *NullableCapitalization) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat.go index fa7fe3699da..6f7425873cd 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat.go @@ -119,3 +119,4 @@ func (v *NullableCat) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat_all_of.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat_all_of.go index 3ed56df463e..2efc62d2022 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat_all_of.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_cat_all_of.go @@ -110,3 +110,4 @@ func (v *NullableCatAllOf) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_category.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_category.go index df490d1668f..e00cc7ba84b 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_category.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_category.go @@ -141,3 +141,4 @@ func (v *NullableCategory) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_class_model.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_class_model.go index 518bf54ac3d..5213ad9d879 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_class_model.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_class_model.go @@ -110,3 +110,4 @@ func (v *NullableClassModel) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_client.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_client.go index cfc309393b1..d1b9ffcc287 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_client.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_client.go @@ -110,3 +110,4 @@ func (v *NullableClient) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog.go index 607dcf455c5..12a5bee4876 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog.go @@ -119,3 +119,4 @@ func (v *NullableDog) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog_all_of.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog_all_of.go index e30f7fafba6..a5a791e50f0 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog_all_of.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_dog_all_of.go @@ -110,3 +110,4 @@ func (v *NullableDogAllOf) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_arrays.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_arrays.go index edc98c6ee47..1fbadb34e71 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_arrays.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_arrays.go @@ -146,3 +146,4 @@ func (v *NullableEnumArrays) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_class.go index 9ae671ac905..b090a7bd6f9 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_class.go @@ -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) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_test_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_test_.go index 0098ee7682a..f9c20efe677 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_test_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_enum_test_.go @@ -373,3 +373,4 @@ func (v *NullableEnumTest) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file.go index 61d028327e0..d7a50dc683a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file.go @@ -111,3 +111,4 @@ func (v *NullableFile) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go index 92b799a6163..887cd35c752 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_file_schema_test_class.go @@ -146,3 +146,4 @@ func (v *NullableFileSchemaTestClass) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_foo.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_foo.go index 673ead81f0d..825b2761c1c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_foo.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_foo.go @@ -114,3 +114,4 @@ func (v *NullableFoo) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_format_test_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_format_test_.go index 89e97de0a87..bcc0289a091 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_format_test_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_format_test_.go @@ -590,3 +590,4 @@ func (v *NullableFormatTest) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit.go index 1181d5c94d8..8d4b3ccf6f8 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit.go @@ -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 - return nil + jsonApple, _ := json.Marshal(dst.Apple) + if string(jsonApple) == "{}" { // empty struct + dst.Apple = nil + } else { + match++ + } + } else { + dst.Apple = nil } - var unmarshaledBanana *Banana = &Banana{} - err = json.Unmarshal(src, unmarshaledBanana) + + // try to unmarshal data into Banana + err = json.Unmarshal(data, &dst.Banana); if err == nil { - s.FruitInterface = unmarshaledBanana - return 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)") } - 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 +// 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 } -func (v *NullableFruit) Set(val *Fruit) { - v.value = val - v.isSet = true +// 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 } -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) -} diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go index 86320b7c9b8..c1b0500050a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go @@ -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 - return nil + jsonAppleReq, _ := json.Marshal(dst.AppleReq) + if string(jsonAppleReq) == "{}" { // empty struct + dst.AppleReq = nil + } else { + match++ + } + } else { + dst.AppleReq = nil } - var unmarshaledBananaReq *BananaReq = &BananaReq{} - err = json.Unmarshal(src, unmarshaledBananaReq) + + // try to unmarshal data into BananaReq + err = json.Unmarshal(data, &dst.BananaReq); if err == nil { - s.FruitReqInterface = unmarshaledBananaReq - return 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)") } - 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 +// 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 } -func (v *NullableFruitReq) Set(val *FruitReq) { - v.value = val - v.isSet = true +// 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 } -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) -} diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_gm_fruit.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_gm_fruit.go index 2449853433b..997688ee143 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_gm_fruit.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_gm_fruit.go @@ -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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// HasColor returns a boolean if a field has been set. -func (o *GmFruit) HasColor() bool { - if o != nil && o.Color != nil { - return true +// 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 } - return false -} - -// 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 + // 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 } - return false + return fmt.Errorf("Data failed to match schemas in anyOf(GmFruit)") } -// 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 +// 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) } - 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 src.Banana != nil { + return json.Marshal(&src.Banana) } - if o.Cultivar != nil { - toSerialize["cultivar"] = o.Cultivar - } - if o.LengthCm != nil { - toSerialize["lengthCm"] = o.LengthCm - } - return json.Marshal(toSerialize) + + return nil, nil // no data in anyOf schemas } -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) -} diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go index 98d282bb39b..0aa39e6de8c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_has_only_read_only.go @@ -146,3 +146,4 @@ func (v *NullableHasOnlyReadOnly) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_health_check_result.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_health_check_result.go index 12719c684d3..af5a5b94a1e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_health_check_result.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_health_check_result.go @@ -120,3 +120,4 @@ func (v *NullableHealthCheckResult) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object.go index 0ae09b0d746..ec6a571e8eb 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object.go @@ -148,3 +148,4 @@ func (v *NullableInlineObject) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_1.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_1.go index 13a07bceee0..d95ad59790a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_1.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_1.go @@ -149,3 +149,4 @@ func (v *NullableInlineObject1) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_2.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_2.go index fc33d433a88..d3029a8e77b 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_2.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_2.go @@ -152,3 +152,4 @@ func (v *NullableInlineObject2) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_3.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_3.go index 3e7990cdeea..c51c19956f5 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_3.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_3.go @@ -566,3 +566,4 @@ func (v *NullableInlineObject3) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_4.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_4.go index 646fa87e375..b4fcf5fa1f0 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_4.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_4.go @@ -134,3 +134,4 @@ func (v *NullableInlineObject4) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_5.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_5.go index d565e10a434..974844007a7 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_5.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_object_5.go @@ -142,3 +142,4 @@ func (v *NullableInlineObject5) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_response_default.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_response_default.go index 619830ddc35..19fb6bcd8a8 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_response_default.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_inline_response_default.go @@ -110,3 +110,4 @@ func (v *NullableInlineResponseDefault) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_list.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_list.go index de655731a9b..7966d7b337c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_list.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_list.go @@ -110,3 +110,4 @@ func (v *NullableList) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mammal.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mammal.go index 29c4fdcfa23..bd830b26689 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mammal.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mammal.go @@ -14,79 +14,75 @@ import ( "fmt" ) -// Mammal struct for Mammal +// Mammal - struct for Mammal type Mammal struct { - MammalInterface interface { GetClassName() string } + Whale *Whale + Zebra *Zebra } -func (s Mammal) MarshalJSON() ([]byte, error) { - return json.Marshal(s.MammalInterface) -} - -func (s *Mammal) UnmarshalJSON(src []byte) error { +// Unmarshl JSON data into one of the pointers in the struct +func (dst *Mammal) UnmarshalJSON(data []byte) error { var err error - var unmarshaled map[string]interface{} - err = json.Unmarshal(src, &unmarshaled) - if err != nil { - return err - } - if v, ok := unmarshaled["className"]; ok { - switch v { - case "whale": - var result *Whale = &Whale{} - err = json.Unmarshal(src, result) - if err != nil { - return err - } - s.MammalInterface = result - return nil - case "zebra": - var result *Zebra = &Zebra{} - err = json.Unmarshal(src, result) - if err != nil { - return err - } - s.MammalInterface = result - return nil - default: - return fmt.Errorf("No oneOf model has 'className' equal to %s", v) + match := 0 + // try to unmarshal data into Whale + err = json.Unmarshal(data, &dst.Whale); + if err == nil { + jsonWhale, _ := json.Marshal(dst.Whale) + if string(jsonWhale) == "{}" { // empty struct + dst.Whale = nil + } else { + match++ } } else { - return fmt.Errorf("Discriminator property 'className' not found in unmarshaled payload: %+v", unmarshaled) + dst.Whale = nil + } + + // try to unmarshal data into Zebra + err = json.Unmarshal(data, &dst.Zebra); + if err == nil { + jsonZebra, _ := json.Marshal(dst.Zebra) + if string(jsonZebra) == "{}" { // empty struct + dst.Zebra = nil + } else { + match++ + } + } else { + dst.Zebra = nil + } + + if match > 1 { // more than 1 match + return fmt.Errorf("Data matches more than one schema in oneOf(Mammal)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("Data failed to match schemas in oneOf(Mammal)") } } -type NullableMammal struct { - value *Mammal - isSet bool + +// Marshl data from the first non-nil pointers in the struct to JSON +func (src *Mammal) MarshalJSON() ([]byte, error) { + if src.Whale != nil { + return json.Marshal(&src.Whale) + } + + if src.Zebra != nil { + return json.Marshal(&src.Zebra) + } + + return nil, nil // no data in oneOf schemas } -func (v NullableMammal) Get() *Mammal { - return v.value +// Get the actual instance +func (obj *Mammal) GetActualInstance() (interface{}) { + if obj.Whale != nil { + return obj.Whale + } + + if obj.Zebra != nil { + return obj.Zebra + } + + // all schemas are nil + return nil } -func (v *NullableMammal) Set(val *Mammal) { - v.value = val - v.isSet = true -} - -func (v NullableMammal) IsSet() bool { - return v.isSet -} - -func (v *NullableMammal) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableMammal(val *Mammal) *NullableMammal { - return &NullableMammal{value: val, isSet: true} -} - -func (v NullableMammal) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableMammal) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_map_test_.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_map_test_.go index 5a1d29671cb..42724f8d875 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_map_test_.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_map_test_.go @@ -218,3 +218,4 @@ func (v *NullableMapTest) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go index 355bcab8503..21b7cb60ab4 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go @@ -183,3 +183,4 @@ func (v *NullableMixedPropertiesAndAdditionalPropertiesClass) UnmarshalJSON(src v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_name.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_name.go index 39cf81c6a4d..f910dc37c0c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_name.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_name.go @@ -211,3 +211,4 @@ func (v *NullableName) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go index c9d8facc2a8..0f3e7fb3a41 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go @@ -571,3 +571,4 @@ func (v *NullableNullableClass) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_number_only.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_number_only.go index dbb70c5c1f7..6307b2871e9 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_number_only.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_number_only.go @@ -110,3 +110,4 @@ func (v *NullableNumberOnly) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_order.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_order.go index 895475b260c..797c8e9236f 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_order.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_order.go @@ -296,3 +296,4 @@ func (v *NullableOrder) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_composite.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_composite.go index 26a09e445c6..88049de0dac 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_composite.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_composite.go @@ -182,3 +182,4 @@ func (v *NullableOuterComposite) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum.go index 60598913a47..acb4c4426b0 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum.go @@ -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) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_default_value.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_default_value.go index 326abb7dfb6..3cb4c30561f 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_default_value.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_default_value.go @@ -28,7 +28,6 @@ func (v OuterEnumDefaultValue) Ptr() *OuterEnumDefaultValue { return &v } - type NullableOuterEnumDefaultValue struct { value *OuterEnumDefaultValue isSet bool @@ -64,3 +63,4 @@ func (v *NullableOuterEnumDefaultValue) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer.go index c1ca119de39..ce7e82adc41 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer.go @@ -28,7 +28,6 @@ func (v OuterEnumInteger) Ptr() *OuterEnumInteger { return &v } - type NullableOuterEnumInteger struct { value *OuterEnumInteger isSet bool @@ -64,3 +63,4 @@ func (v *NullableOuterEnumInteger) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer_default_value.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer_default_value.go index bc08397c462..790b7b56885 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer_default_value.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_outer_enum_integer_default_value.go @@ -28,7 +28,6 @@ func (v OuterEnumIntegerDefaultValue) Ptr() *OuterEnumIntegerDefaultValue { return &v } - type NullableOuterEnumIntegerDefaultValue struct { value *OuterEnumIntegerDefaultValue isSet bool @@ -64,3 +63,4 @@ func (v *NullableOuterEnumIntegerDefaultValue) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_pet.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_pet.go index a72afed465a..876af8724d7 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_pet.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_pet.go @@ -277,3 +277,4 @@ func (v *NullablePet) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_read_only_first.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_read_only_first.go index 277badc58cf..af6291b4c82 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_read_only_first.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_read_only_first.go @@ -146,3 +146,4 @@ func (v *NullableReadOnlyFirst) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_return.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_return.go index b8821489c0e..e6350da030c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_return.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_return.go @@ -110,3 +110,4 @@ func (v *NullableReturn) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_tag.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_tag.go index 6ba3864c612..0f8157a6b7a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_tag.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_tag.go @@ -146,3 +146,4 @@ func (v *NullableTag) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go index 9a9bd7dcfda..bee4da234d0 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go @@ -513,3 +513,4 @@ func (v *NullableUser) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_whale.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_whale.go index 0f78fbb708e..faeb8187021 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_whale.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_whale.go @@ -140,10 +140,6 @@ func (o Whale) MarshalJSON() ([]byte, error) { return json.Marshal(toSerialize) } -// AsMammal wraps this instance of Whale in Mammal -func (s *Whale) AsMammal() Mammal { - return Mammal{ MammalInterface: s } -} type NullableWhale struct { value *Whale isSet bool @@ -179,3 +175,4 @@ func (v *NullableWhale) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_zebra.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_zebra.go index e8c2717d137..b28b9d7d1db 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_zebra.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_zebra.go @@ -104,10 +104,6 @@ func (o Zebra) MarshalJSON() ([]byte, error) { return json.Marshal(toSerialize) } -// AsMammal wraps this instance of Zebra in Mammal -func (s *Zebra) AsMammal() Mammal { - return Mammal{ MammalInterface: s } -} type NullableZebra struct { value *Zebra isSet bool @@ -143,3 +139,4 @@ func (v *NullableZebra) UnmarshalJSON(src []byte) error { v.isSet = true return json.Unmarshal(src, &v.value) } +