-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[go-server] Set default values in object properties #18532
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
base: master
Are you sure you want to change the base?
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