[go-server] Set default values in object properties#18532
[go-server] Set default values in object properties#18532rledisez wants to merge 1 commit intoOpenAPITools:masterfrom
Conversation
|
Does the default work when there are nested objects? such as embedded struct, and when a struct is a type for one of the fields. |
The previous version was not working in that case. It was just handling basic types (string, int, bool). I took inspiration of the function NewObjectWithDefaults from the "go" templates to create a function that create a struct with defaults for each type and call it when required. I think it does what you asked for. |
|
could you add some tests that generates as such: struct A { struct B { struct C { This is B embeds A, and C has a field of type A. Make sure the code is generated correctly if S1 has a default. |
When a default value is set for an object property, ensure it is set into the struct before decoding the JSON body. Fix OpenAPITools#4579
|
Thx for your feedback. I updated the template to set default values for embedded structs. I created a test as |
When a default value is set for an object property, ensure it is set into the struct before decoding the JSON body.
Fix #4579