forked from loafle/openapi-generator-original
[go-experimental] Fix generating array aliases as models (#6939)
Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
@@ -2,8 +2,13 @@
|
||||
type {{classname}} struct {
|
||||
{{#parent}}
|
||||
{{^isMapModel}}
|
||||
{{^isArrayModel}}
|
||||
{{{parent}}}
|
||||
{{/isArrayModel}}
|
||||
{{/isMapModel}}
|
||||
{{#isArrayModel}}
|
||||
Items {{{parent}}}
|
||||
{{/isArrayModel}}
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
{{^-first}}
|
||||
@@ -218,9 +223,10 @@ func (o *{{classname}}) Unset{{name}}() {
|
||||
{{/required}}
|
||||
{{/vars}}
|
||||
func (o {{classname}}) MarshalJSON() ([]byte, error) {
|
||||
toSerialize := map[string]interface{}{}
|
||||
toSerialize := {{#isArrayModel}}make([]interface{}, len(o.Items)){{/isArrayModel}}{{^isArrayModel}}map[string]interface{}{}{{/isArrayModel}}
|
||||
{{#parent}}
|
||||
{{^isMapModel}}
|
||||
{{^isArrayModel}}
|
||||
serialized{{parent}}, err{{parent}} := json.Marshal(o.{{parent}})
|
||||
if err{{parent}} != nil {
|
||||
return []byte{}, err{{parent}}
|
||||
@@ -229,7 +235,13 @@ func (o {{classname}}) MarshalJSON() ([]byte, error) {
|
||||
if err{{parent}} != nil {
|
||||
return []byte{}, err{{parent}}
|
||||
}
|
||||
{{/isArrayModel}}
|
||||
{{/isMapModel}}
|
||||
{{#isArrayModel}}
|
||||
for i, item := range o.Items {
|
||||
toSerialize[i] = item
|
||||
}
|
||||
{{/isArrayModel}}
|
||||
{{/parent}}
|
||||
{{#vars}}
|
||||
{{! if argument is nullable, only serialize it if it is set}}
|
||||
@@ -370,4 +382,10 @@ func (o *{{{classname}}}) UnmarshalJSON(bytes []byte) (err error) {
|
||||
}
|
||||
|
||||
{{/isAdditionalPropertiesTrue}}
|
||||
{{#isArrayModel}}
|
||||
func (o *{{{classname}}}) UnmarshalJSON(bytes []byte) (err error) {
|
||||
return json.Unmarshal(bytes, &o.Items)
|
||||
}
|
||||
|
||||
{{/isArrayModel}}
|
||||
{{>nullable_model}}
|
||||
|
||||
Reference in New Issue
Block a user