coinbase / mesh-specifications

Specification files for the Mesh Blockchain Standard
Apache License 2.0
324 stars 92 forks source link

TypeScript type generation #15

Closed kyranjamie closed 4 years ago

kyranjamie commented 4 years ago

Great work putting together a blockchain api standard so far @patrick-ogrady and co 👍

One feature I'm particularly interested in would be to generate typing info from the model files. Doing so leverages tooling many are already using, and can facilitate a much better DX.

We're already doing this @blockstack with our api layer that sits atop our code node, and publishing a package of the output types.

It's not a perfect set up. It uses a mash of npm packages, and has ran into some limitations of the JSON Schema standard. Primarily: How should you generate types with allOf and oneOf properties, as well as types with 2 or more discriminating type unions. But otherwise has served us quite well.

Would love to hear whether this has already been discussed, and thoughts on how it could fit into the Rosetta project.

patrick-ogrady commented 4 years ago

We have only done [this]((https://https://github.com/coinbase/rosetta-sdk-go) for Golang so far 😢 . You can find our generated code in the types package!

If you are interested in doing the same for JS, TS, or any other language, I'm sure others in the community would use it extensively. We already received 1 question about this in our Discourse (I attached this issue there as well).

I wrote up a little blurb explaining the decision to start with Golang here.

AlanVerbner commented 4 years ago

@kyranjamie we are using https://www.npmjs.com/package/dtsgenerator to generate typescript type definitions based on api.json file, something like dtsgen --out ./types/rosetta-types.d.ts ./rosetta-specifications/api.json

sp6pe commented 4 years ago

@AlanVerbner Would be cool if you created a Typescript SDK! We'd be happy to post it on the main website and community page!