Skip to content
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

Stacks-blockchain-api client library #185

Merged
merged 10 commits into from
Aug 20, 2020
Merged

Stacks-blockchain-api client library #185

merged 10 commits into from
Aug 20, 2020

Conversation

zone117x
Copy link
Member

@zone117x zone117x commented Jul 29, 2020

Reference issue: #170

This uses openapi-generator to generate a client library based off the openapi.yaml and json schema files.

There's currently a bug with the transaction responses not being typed correctly, see OpenAPITools/openapi-generator#6513

All the newly committed source files are auto generated, except for test.ts which has a brief demo of how the generated client is used:

image

@codecov
Copy link

codecov bot commented Jul 29, 2020

Codecov Report

Merging #185 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #185   +/-   ##
=======================================
  Coverage   59.65%   59.65%           
=======================================
  Files          44       44           
  Lines        2917     2917           
  Branches      496      496           
=======================================
  Hits         1740     1740           
  Misses       1174     1174           
  Partials        3        3           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 780c84e...55bf0a3. Read the comment docs.

@kyranjamie
Copy link
Contributor

kyranjamie commented Jul 29, 2020

I'd love to get some mileage out of an auto-generated client tool like this, but I'm not sold it'll be worth the time investment and tying ourselves into a tool.

First, I'd imagine were we to proceed using this, we'd quickly come across some requirement we want to add that is not easily added, and requires some ugly monkey-patch. It'll have a limitation somewhere (similar to bug shared).

Second, I'm not sure what problem it solves. A simple client library is trivial to build. All the types are there. Hank's made a start. Give it two days of dedicated dev and we'll have a pretty decent client ready.

Curious on @hstove and @aulneau's input. They'll also be heavy users of whatever client lib we end up with.

@zone117x
Copy link
Member Author

I'd like to avoid maintaining multiple sources of truth for the public API. We currently maintain two. One in OpenAPI format and one in server ts code. This approach avoids adding a third.

Spending a day or so fleshing out a full client implementation isn't my concern, it's the maintenance burden that I'd like to avoid.

@kyranjamie
Copy link
Contributor

kyranjamie commented Jul 30, 2020

I wouldn't disagree. There should only be one source of truth, the spec.

But is auto-generating a client the only way to achieve this? TypeScript can import JSON (build step to convert yaml).
We can conform to the source of truth by referencing all the details in the spec.

image

My main critique with this approach is that we're not able to make our own API design decisions. The client should be as friendly to use as possible. If we can make a request easier to use/consume with a few lines of code, we should. With a generator you get what your given. Maybe a hybrid approach could work, if we can set it up to extend/rewrite methods ourselves.

The generated types for requests parameters here would be pretty useful, though.

@agraebe agraebe linked an issue Aug 4, 2020 that may be closed by this pull request
@zone117x zone117x marked this pull request as ready for review August 20, 2020 20:59
@zone117x zone117x changed the title feat: auto-generated client demo Stacks-blockchain-api client library Aug 20, 2020
@zone117x zone117x merged commit 402686c into master Aug 20, 2020
@zone117x zone117x deleted the feat/client-lib-demo branch August 20, 2020 22:20
@blockstack-devops
Copy link

🎉 This PR is included in version 0.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create an API client/SDK
3 participants