-
Notifications
You must be signed in to change notification settings - Fork 190
chore: Support nested attributes in conversion logic for generating Resource Model from API response #3261
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
chore: Support nested attributes in conversion logic for generating Resource Model from API response #3261
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, leaving some questions and suggestions
"JSON arrays not supported yet": { | ||
responseJSON: `{"attr": [{"key": "value"}]}`, | ||
errorStr: "unmarshal not supported yet for type []interface {} for field attr", | ||
"JSON maps not supported yet": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice that we capture current limitation with a test
} | ||
} | ||
|
||
func convertUnknownToNull(valModel reflect.Value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this logic be recursive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unknown to null logic moved to another PR
@@ -164,26 +173,211 @@ func unmarshalAttr(attrNameJSON string, attrObjJSON any, valModel reflect.Value) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth it to log a debug message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, in general I prefer not to log debug messages, I don't know if this case is so important to be logged
AttrSetString: types.SetUnknown(types.StringType), | ||
AttrSetObj: types.SetUnknown(objTypeTest), | ||
} | ||
// attrUnexisting is ignored because it is in JSON but not in the model, no error is returned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice with these comments
func convertUnknownToNull(valModel reflect.Value) { | ||
for i := 0; i < valModel.NumField(); i++ { | ||
field := valModel.Field(i) | ||
if obj, ok := field.Interface().(types.Object); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would only work for types.Object? What about other types.XXX
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, creating ticket created for to null logic: CLOUDP-312809
return err | ||
} | ||
} | ||
convertUnknownToNull(valModel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be better to do in a different step?
Then it would be easier to override and possible use values from state instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EspenAlbert do you mean not doing it in Unmarshal, but in another public func?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EspenAlbert ticket created for to null logic: CLOUDP-312809 cc @AgustinBettati
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in another public func
Yes, I believe so. Sounds good to me with a different ticket 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Thanks for addressing the comments
Description
Support nested attributes in conversion logic for generating Resource Model from API response. It includes ListNest, SetNested and SingleNested. MapNested is not supported as it's not needed at the moment.
Link to any related issue(s): CLOUDP-311710
Type of change:
Required Checklist:
Further comments