Skip to content

Commit bfd3b6f

Browse files
committed
fix(go): use non-pointer receiver for JSON marshal
In the case of a required anyOf property, JSON marshalling would has been incorrect. Required properties are not nullable, and thus always use value receivers. For the single case of anyOf models, a pointer receiver was used for MarshalJSON. All other instances of json marshalling use value receivers. This change is simply to use a value receiver instead of a pointer receiver in the template for `MarshalJSON` on anyOf models.
1 parent 008c1a4 commit bfd3b6f

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
6868
}
6969

7070
// Marshal data from the first non-nil pointers in the struct to JSON
71-
func (src *{{classname}}) MarshalJSON() ([]byte, error) {
71+
func (src {{classname}}) MarshalJSON() ([]byte, error) {
7272
{{#anyOf}}
7373
if src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} != nil {
7474
return json.Marshal(&src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})

samples/client/others/go/oneof-anyof-required/model_object2.go

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

samples/openapi3/client/petstore/go/go-petstore/model_any_of_primitive_type.go

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

samples/openapi3/client/petstore/go/go-petstore/model_filter_any.go

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

samples/openapi3/client/petstore/go/go-petstore/model_gm_fruit.go

Lines changed: 1 addition & 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)