Skip to content

Commit 4d3384e

Browse files
committed
wip
1 parent ecb1ea7 commit 4d3384e

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

templates/go/model_simple.mustache

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type {{classname}} struct {
3737
{{/isWriteOnly}}
3838
{{/isReadOnly}}
3939
{{/required}}
40-
{{name}} *{{#isNullable}}{{dataType}}{{/isNullable}}{{^isNullable}}{{^isPrimitive}}{{dataType}}{{/isPrimitive}}{{#isPrimitive}}{{baseType}}{{/isPrimitive}}{{/isNullable}} `json:"{{baseName}}{{#required}}{{#isReadOnly}},omitempty{{/isReadOnly}}{{/required}}{{#required}}{{#isWriteOnly}},omitempty{{/isWriteOnly}}{{/required}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}`
40+
{{name}} *{{#isNullable}}{{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}{{/isNullable}}{{^isNullable}}{{^isPrimitiveType}}{{dataType}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}{{/isPrimitiveType}}{{/isNullable}} `json:"{{baseName}}{{#required}}{{#isReadOnly}},omitempty{{/isReadOnly}}{{/required}}{{#required}}{{#isWriteOnly}},omitempty{{/isWriteOnly}}{{/required}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}`
4141
{{#isAdditionalPropertiesTrue}}
4242
AdditionalProperties map[string]interface{}
4343
{{/isAdditionalPropertiesTrue}}
@@ -59,7 +59,7 @@ type _{{{classname}}} {{{classname}}}
5959
// This constructor will assign default values to properties that have it defined,
6060
// and makes sure properties required by API are set, but the set of arguments
6161
// will change when the set of required properties is changed
62-
func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} *{{#isNullable}}{{dataType}}{{/isNullable}}{{^isNullable}}{{dataType}}{{/isNullable}}{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} {
62+
func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{datatype}}{{/isInteger}}{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} {
6363
this := {{classname}}{}
6464
{{#allVars}}
6565
{{#required}}
@@ -69,7 +69,7 @@ func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} *{{#isNullable}}{{dat
6969
{{#defaultValue}}
7070
{{^vendorExtensions.x-golang-is-container}}
7171
{{^isReadOnly}}
72-
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
72+
var {{nameInCamelCase}} {{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} = {{{.}}}
7373
{{#isNullable}}
7474
this.{{name}} = *New{{dataType}}(&{{nameInCamelCase}})
7575
{{/isNullable}}
@@ -94,7 +94,7 @@ func New{{classname}}WithDefaults() *{{classname}} {
9494
{{^vendorExtensions.x-golang-is-container}}
9595
{{^isReadOnly}}
9696
{{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}}
97-
var {{nameInCamelCase}} {{{dataType}}} = {{{.}}}
97+
var {{nameInCamelCase}} {{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} = {{{.}}}
9898
{{#isNullable}}
9999
this.{{name}} = *New{{dataType}}(&{{nameInCamelCase}})
100100
{{/isNullable}}
@@ -117,10 +117,9 @@ func New{{classname}}WithDefaults() *{{classname}} {
117117
{{#deprecated}}
118118
// Deprecated
119119
{{/deprecated}}
120-
func (o *{{classname}}) Get{{name}}() *{{#isNullable}}{{dataType}}{{/isNullable}}{{^isNullable}}{{dataType}}{{/isNullable}} {
120+
func (o *{{classname}}) Get{{name}}() (result *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) {
121121
if o == nil|| IsNil(o.{{name}}) {{#isNullable}}{{^vendorExtensions.x-golang-is-container}} || o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
122-
var ret *{{#isNullable}}{{dataType}}{{/isNullable}}{{^isNullable}}{{dataType}}{{/isNullable}}
123-
return ret
122+
return
124123
}
125124

126125
{{#isNullable}}
@@ -144,13 +143,13 @@ func (o *{{classname}}) Get{{name}}() *{{#isNullable}}{{dataType}}{{/isNullable}
144143
{{#deprecated}}
145144
// Deprecated
146145
{{/deprecated}}
147-
func (o *{{classname}}) Get{{name}}Ok() (*{{#isNullable}}{{dataType}}{{/isNullable}}{{^isNullable}}{{dataType}}{{/isNullable}}, bool) {
146+
func (o *{{classname}}) Get{{name}}Ok() (result *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}},ok bool) {
148147
if o == nil{{#isNullable}}{{#vendorExtensions.x-golang-is-container}} || IsNil(o.{{name}}){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
149148
{{^isFreeFormObject}}
150149
return nil, false
151150
{{/isFreeFormObject}}
152151
{{#isFreeFormObject}}
153-
return &{{#isNullable}}{{dataType}}{{/isNullable}}{{^isNullable}}{{dataType}}{{/isNullable}}{}, false
152+
return &{{datatype}}{}, false
154153
{{/isFreeFormObject}}
155154
}
156155
{{#isNullable}}
@@ -170,7 +169,7 @@ func (o *{{classname}}) Get{{name}}Ok() (*{{#isNullable}}{{dataType}}{{/isNullab
170169
{{#deprecated}}
171170
// Deprecated
172171
{{/deprecated}}
173-
func (o *{{classname}}) Set{{name}}(v *{{#isNullable}}{{dataType}}{{/isNullable}}{{^isNullable}}{{dataType}}{{/isNullable}}) {
172+
func (o *{{classname}}) Set{{name}}(v *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) {
174173
{{#isNullable}}
175174
{{#vendorExtensions.x-golang-is-container}}
176175
o.{{name}} = v
@@ -193,10 +192,9 @@ func (o *{{classname}}) Set{{name}}(v *{{#isNullable}}{{dataType}}{{/isNullable}
193192
{{#deprecated}}
194193
// Deprecated
195194
{{/deprecated}}
196-
func (o *{{classname}}) Get{{name}}() *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{baseType}}{{/isContainer}} {
195+
func (o *{{classname}}) Get{{name}}() (result *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}}) {
197196
if o == nil || IsNil(o.{{name}}) {{#isNullable}}{{^vendorExtensions.x-golang-is-container}} || IsNil(o.{{name}}.Get()){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
198-
var ret *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{baseType}}{{/isContainer}}
199-
return ret
197+
return
200198
}
201199
{{#isNullable}}
202200
{{#vendorExtensions.x-golang-is-container}}
@@ -219,13 +217,13 @@ func (o *{{classname}}) Get{{name}}() *{{#isContainer}}{{dataType}}{{/isContaine
219217
{{#deprecated}}
220218
// Deprecated
221219
{{/deprecated}}
222-
func (o *{{classname}}) Get{{name}}Ok() (*{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{baseType}}{{/isContainer}}, bool) {
220+
func (o *{{classname}}) Get{{name}}Ok() (result *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}},ok bool) {
223221
if o == nil || IsNil(o.{{name}}) {
224222
{{^isFreeFormObject}}
225223
return nil, false
226224
{{/isFreeFormObject}}
227225
{{#isFreeFormObject}}
228-
return &{{#isNullable}}{{dataType}}{{/isNullable}}{{^isNullable}}{{dataType}}{{/isNullable}}{}, false
226+
return &{{datatype}}{}, false
229227
{{/isFreeFormObject}}
230228
}
231229
{{#isNullable}}
@@ -254,14 +252,14 @@ func (o *{{classname}}) Has{{name}}() bool {
254252
{{#deprecated}}
255253
// Deprecated
256254
{{/deprecated}}
257-
func (o *{{classname}}) Set{{name}}(v *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{baseType}}{{/isContainer}}) {
255+
func (o *{{classname}}) Set{{name}}(v *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}}) {
258256
{{#isNullable}}
259257
{{#vendorExtensions.x-golang-is-container}}
260258
o.{{name}} = v
261259
{{/vendorExtensions.x-golang-is-container}}
262260
{{^vendorExtensions.x-golang-is-container}}
263261
if IsNil(o.{{name}}) {
264-
o.{{name}} = new({{dataType}})
262+
o.{{name}} = new({{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}})
265263
}
266264
o.{{name}}.Set(v)
267265
{{/vendorExtensions.x-golang-is-container}}
@@ -275,17 +273,14 @@ func (o *{{classname}}) Set{{name}}(v *{{#isContainer}}{{dataType}}{{/isContaine
275273
// Set{{name}}Nil sets the value for {{name}} to be an explicit nil
276274
func (o *{{classname}}) Set{{name}}Nil() {
277275
if IsNil(o.{{name}}) {
278-
o.{{name}} = new({{dataType}})
276+
o.{{name}} = new({{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}})
279277
}
280278
o.{{name}}.Set(nil)
281279
}
282280

283281
// Unset{{name}} ensures that no value is present for {{name}}, not even an explicit nil
284282
func (o *{{classname}}) Unset{{name}}() {
285-
if IsNil(o.{{name}}) {
286-
o.{{name}} = new({{dataType}})
287-
}
288-
o.{{name}}.Unset()
283+
o.{{name}}=nil
289284
}
290285
{{/vendorExtensions.x-golang-is-container}}
291286
{{/isNullable}}

0 commit comments

Comments
 (0)