IBM / go-sdk-core

The go-sdk-core repository contains core functionality required by Go code generated by the IBM OpenAPI SDK Generator.
Apache License 2.0
30 stars 24 forks source link

feat(unmarshal): introduce new unmarshal functions for primitives and models #54

Closed padamstx closed 4 years ago

padamstx commented 4 years ago

Fixes: https://github.ibm.com/arf/planning-sdk-squad/issues/1613

This PR contains new unmarshal functions for primitive and model types in the Go core. This will be needed in the SDK generator changes to fix the referenced issue.

The "new" approach for unmarshalling JSON values (primitives and models) in the Go generator will be to generate a single Unmarshal<model>() function for each model. This generated function can then be passed as a parameter (along with the JSON input and a pointer to the unmarshal result) to the core's UnmarshalModel() function. UnmarshalModel() will use reflection to interpret the JSON input and the result to determine the appropriate type of unmarshal operation (e.g. a single model instance, a slice of models, a map of models, or a map of model slices).

The new UnmarshalPrimitive() function will be invoked from within a model's generated Unmarshal<model>() function to unmarshal struct fields involving primitive types (e.g. a single instance of a primitive type, a slice of primitives, a map of primitives, a map of primitive slices, and a slice of maps of primitive slices).

This PR contains only the changes in the Go core. There will be a corresponding PR for the SDK generator changes.

Note: there might be some additional tweaks needed to the code changes in this PR as I complete the corresponding SDK generator changes, but I wanted to get this PR submitted so the review process can begin. One change that I identified as I reviewed the code before submitting this PR is that there is a common piece of code within each of the private unmarshalModelXXX functions that I can pull out and implement in a private function. This will not change the overall behavior of those functions.

padamstx commented 4 years ago

@smikulcik Hi Simon, I wanted to tag you as a reviewer on this PR, but I see you're not in the required team within the github.com/IBM org. Please feel free to take a look and provide feedback one way or another :)

padamstx commented 4 years ago

I just pushed a new commit to this PR that includes the following:

I think (I hope) that this PR is now 100% complete and ready for the corresponding Generator changes to commence (famous last words, right?).

padamstx commented 4 years ago

While working through the Go generator changes, I found even more opportunities to improve the Go core :) I just pushed a commit that enhances the BaseService.Request() method so that it can directly return various types of response body data via the 'result' parameter (and the DetailedResponse.Result field as well). These changes allow us to reduce the amount of code that we generate immediately after the call to BaseService.Request() within an operation method.

ibm-devx-automation commented 4 years ago

:tada: This PR is included in version 3.4.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

ibm-devx-automation commented 4 years ago

:tada: This PR is included in version 4.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: