OpenAPITools / OpenAPITools/openapi-generator
[BUG][GO] ToMap() function does not consider inner objects -> so they are not mapped.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Go model's MarshalJSON and ToMap entry points, using LegacyCheckDefinitionDTO and its embedded LegacyDefinitionDTO as the example. Reproduce the nested-object marshaling case and verify that the resulting JSON includes the inner object's mapped fields rather than only the outer layer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100