Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][GO] ToMap() function does not consider inner objects -> so they are not mapped. #20089

Open
4 tasks
orlyIsaacs opened this issue Nov 12, 2024 · 0 comments
Open
4 tasks

Comments

@orlyIsaacs
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • [version 7.9.0 ] Have you tested with the latest master to confirm the issue still exists?
  • [v] Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When marshaling an object, the MarshalJSON function is called and implemented for all of the objects. This calls ToMap(), which makes sure that all of the fields in the object are not empty - and if they are, it omits them. However, in the case where an object contains an inner object, it doesn't send the inner object to its inner ToMap() function, resulting in the marshaling happening only on the object's "first layer" of values.

openapi-generator version

7.9.0

OpenAPI declaration file content or url

example:

type LegacyCheckDefinitionDTO struct {
LegacyDefinitionDTO
TesterAccessId int64 json:"tester_access_id"
IdOnTester *string json:"id_on_tester,omitempty"
Timeout *int32 json:"timeout,omitempty"
}

this is the MarshalJSON toMap() function -

func (o LegacyCheckDefinitionDTO) MarshalJSON() ([]byte, error) {
toSerialize, err := o.ToMap()
if err != nil {
return []byte{}, err
}
return json.Marshal(toSerialize)
}

and this is the toMap() function -

func (o LegacyCheckDefinitionDTO) ToMap() (map[string]interface{}, error) {
toSerialize["tester_access_id"] = o.TesterAccessId
if !IsNil(o.IdOnTester) {
toSerialize["id_on_tester"] = o.IdOnTester
}
if !IsNil(o.Timeout) {
toSerialize["timeout"] = o.Timeout
}
return toSerialize, nil

The function doesn't take care of its inner object LegacyDefinitionDTO !

Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

Add iteration on all of the objects and call toMap() on all of them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant