influxdb-client-go icon indicating copy to clipboard operation
influxdb-client-go copied to clipboard

feat(v3): optimized generated client code

Open vlastahajek opened this issue 3 years ago • 3 comments

Swagger generated code refactor according to the https://gist.github.com/rogpeppe/359e7465956e98bed4c5b9692b910a05:

  • Single method for each operation
  • Filtering operations only for those with JSON request body (POST and PATCH) and for those with a single JSON response with status code 2xx
  • Returning concrete response type, instead of a wrapper
  • Non 2xx responses result in error
  • Single request parameter - path, query, cookie and header params merged into single struct along with request body

Requires oapi-codegen with extended template helpers: https://github.com/influxdata/oapi-codegen/pull/1

vlastahajek avatar Mar 31 '22 13:03 vlastahajek

I've removed the default, not modified, templates

vlastahajek avatar Apr 07 '22 08:04 vlastahajek

The goal of this PR is to review generated code. In the general view, providing wrapper API over generated code is for having a consistent user-friendly API. As a first example, there is OrganizationAPI with a few implemented functions.

We will provide a getter for Client.apiClient so user can write a custom call to server using generated code.

vlastahajek avatar Apr 29 '22 13:04 vlastahajek

I think that we should also consider relying upon the generated API, we can modify the templates to output documentation and links to the API doc. there are also comments from RogP that request improvements in the generated API, additional properties would be better represented as simple maps.

It would be also nice to distinguish our custom functions in the templates by some prefix, so it is then easier to read what are standard template functions and what are our extensions.

sranka avatar May 02 '22 04:05 sranka

This PR has become obsolete. The modified templates and generated code are already used in the Go v2. The plan is to reuse the management API from Go v2 with a slightly modified API based on the Go V# API design.

vlastahajek avatar Nov 08 '22 10:11 vlastahajek