Skip to content

Commit ba4aae5

Browse files
authored
[Go] bug fix (breaking), minor code format enhancement (#8715)
* go minor code format enhnacement * fix required vars in the model new * remove comma
1 parent ee12a6f commit ba4aae5

33 files changed

Lines changed: 93 additions & 108 deletions

modules/openapi-generator/src/main/resources/go/api.mustache

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Reques
7777
func (a *{{{classname}}}Service) {{{nickname}}}(ctx _context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request {
7878
return {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request{
7979
ApiService: a,
80-
ctx: ctx,{{#pathParams}}
81-
{{paramName}}: {{paramName}},{{/pathParams}}
80+
ctx: ctx,
81+
{{#pathParams}}
82+
{{paramName}}: {{paramName}},
83+
{{/pathParams}}
8284
}
8385
}
8486

modules/openapi-generator/src/main/resources/go/client.mustache

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ func parameterToJson(obj interface{}) (string, error) {
169169
return string(jsonBuf), err
170170
}
171171

172-
173172
// callAPI do the request.
174173
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
175174
if c.cfg.Debug {
@@ -409,9 +408,9 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
409408
return nil
410409
}
411410
if jsonCheck.MatchString(contentType) {
412-
if actualObj, ok := v.(interface{GetActualInstance() interface{}}); ok { // oneOf, anyOf schemas
413-
if unmarshalObj, ok := actualObj.(interface{UnmarshalJSON([]byte) error}); ok { // make sure it has UnmarshalJSON defined
414-
if err = unmarshalObj.UnmarshalJSON(b); err!= nil {
411+
if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas
412+
if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined
413+
if err = unmarshalObj.UnmarshalJSON(b); err != nil {
415414
return err
416415
}
417416
} else {

modules/openapi-generator/src/main/resources/go/model_simple.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ type _{{{classname}}} {{{classname}}}
3131
// This constructor will assign default values to properties that have it defined,
3232
// and makes sure properties required by API are set, but the set of arguments
3333
// will change when the set of required properties is changed
34-
func New{{classname}}({{#vars}}{{#required}}{{nameInCamelCase}} {{dataType}}, {{/required}}{{/vars}}) *{{classname}} {
34+
func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{dataType}}{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} {
3535
this := {{classname}}{}
36-
{{#vars}}
36+
{{#allVars}}
3737
{{#required}}
3838
this.{{name}} = {{nameInCamelCase}}
3939
{{/required}}
@@ -51,7 +51,7 @@ func New{{classname}}({{#vars}}{{#required}}{{nameInCamelCase}} {{dataType}}, {{
5151
{{/vendorExtensions.x-golang-is-container}}
5252
{{/defaultValue}}
5353
{{/required}}
54-
{{/vars}}
54+
{{/allVars}}
5555
return &this
5656
}
5757

@@ -85,7 +85,7 @@ func New{{classname}}WithDefaults() *{{classname}} {
8585
// If the value is explicit nil, the zero value for {{vendorExtensions.x-go-base-type}} will be returned
8686
{{/isNullable}}
8787
func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
88-
if o == nil {{#isNullable}}{{^vendorExtensions.x-golang-is-container}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
88+
if o == nil{{#isNullable}}{{^vendorExtensions.x-golang-is-container}} || o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
8989
var ret {{vendorExtensions.x-go-base-type}}
9090
return ret
9191
}

modules/openapi-generator/src/main/resources/go/utils.mustache

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func (v *NullableBool) UnmarshalJSON(src []byte) error {
6666
return json.Unmarshal(src, &v.value)
6767
}
6868

69-
7069
type NullableInt struct {
7170
value *int
7271
isSet bool
@@ -103,7 +102,6 @@ func (v *NullableInt) UnmarshalJSON(src []byte) error {
103102
return json.Unmarshal(src, &v.value)
104103
}
105104

106-
107105
type NullableInt32 struct {
108106
value *int32
109107
isSet bool
@@ -140,7 +138,6 @@ func (v *NullableInt32) UnmarshalJSON(src []byte) error {
140138
return json.Unmarshal(src, &v.value)
141139
}
142140

143-
144141
type NullableInt64 struct {
145142
value *int64
146143
isSet bool
@@ -177,7 +174,6 @@ func (v *NullableInt64) UnmarshalJSON(src []byte) error {
177174
return json.Unmarshal(src, &v.value)
178175
}
179176

180-
181177
type NullableFloat32 struct {
182178
value *float32
183179
isSet bool
@@ -214,7 +210,6 @@ func (v *NullableFloat32) UnmarshalJSON(src []byte) error {
214210
return json.Unmarshal(src, &v.value)
215211
}
216212

217-
218213
type NullableFloat64 struct {
219214
value *float64
220215
isSet bool
@@ -251,7 +246,6 @@ func (v *NullableFloat64) UnmarshalJSON(src []byte) error {
251246
return json.Unmarshal(src, &v.value)
252247
}
253248

254-
255249
type NullableString struct {
256250
value *string
257251
isSet bool
@@ -288,7 +282,6 @@ func (v *NullableString) UnmarshalJSON(src []byte) error {
288282
return json.Unmarshal(src, &v.value)
289283
}
290284

291-
292285
type NullableTime struct {
293286
value *time.Time
294287
isSet bool

samples/client/petstore/go/go-petstore/client.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/petstore/go/go-petstore/model_animal.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/petstore/go/go-petstore/model_big_cat.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/petstore/go/go-petstore/model_cat.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/petstore/go/go-petstore/model_category.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/petstore/go/go-petstore/model_dog.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)