Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !3113

[Go][client] make structure members pointers, provide custom marshalling

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/bkabrda/go-structure-members-pointers into 4.1.x Jun 06, 2019
  • Overview 0
  • Commits 30
  • Pipelines 0
  • Changes 475+

Created by: bkabrda

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

@antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) @kemokemo (2018/09

This is my shot at fixing #522 (closed). It's still WIP, but I wanted to gather some initial comments to see if it makes sense to take it all the way to the end.

Basically, this PR makes all the members of generated structures pointers and it adds getters/setters for them. Additionally, it provides custom marshalling to check that required/nullable attributes are set properly in JSON when marshalling. Todo list of things that need to be done before this could be considered good to go:

  • Not sure about this, but I think I should change the basic types for struct members in Java code (typeMappings).
    • It actually turns out to be much cleaner to do this purely on the template level, so that's what I did.
  • This will need update of documentations as well.
    • I updated to model_doc.mustache to reflect the changes.
  • I need to take a closer look at enums and see if something needs to be adapted for them to work ok.
    • This seems to not require any changes for enums.
  • One of the lines (for getting the "zero" value of a type) is duplicated in two places; it'd be ideal to hide it behind some sort of macro. Quick google search didn't reveal if mustache provides something like this, I need to take a look again.
    • Turns out that the easiest way to do this is to create an uninitialized var of that specific type and return that - no macro needed.
  • Not sure if getters should return empty instance or nil for structure members that point to other structures. I guess nil would be more in line with what's going on here generally, but not sure - I'm trying to mimic gen-accessors.go referenced in [1], which returns empty structures, but I'm not 100 % sure why that's a good thing to do.
    • I think this is ok as long as it's documented, which it is now.
  • I don't think custom unmarshalling needs to be created, but not sure.
    • This would probably only be required if we wanted to add Get{{name}}ExplicitNull method to nullable struct members. I don't think we need that right now. If we ever need that, we can add it without introducing and API breakage.
  • Fix tests

Any comments would be appreciated. Thanks!

[1] https://github.com/OpenAPITools/openapi-generator/issues/522#issuecomment-499014015

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/bkabrda/go-structure-members-pointers