TheThingsNetwork / lorawan-stack

The Things Stack, an Open Source LoRaWAN Network Server
https://www.thethingsindustries.com/stack/
Apache License 2.0
995 stars 309 forks source link

Code generation for calling API endpoints #32

Open johanstokking opened 5 years ago

johanstokking commented 5 years ago

Summary: Currently, api methods for the http connector in the js-sdk are generated at runtime from a json schema that contains all api defintions.

What is already there? What do you see now? All api methods are generated at runtime when the main instance gets instantiated on the client. The api-defintions.json gets parsed and for each entry a method is created in the api module.

What is missing? What do you want to see? A set of generated es6 methods (during build) that will delegate all api calls to axios and can be published within the sdk, without the need to include redundant json files and generate the methods at runtime.

This shouldnt be too hard, since all methods have the same structure, only the arguments differ.

Worth noting, that the current implementation should stay until the draft sdk is finished, as well as the backend api, and can be tested.


Original issue: https://github.com/TheThingsIndustries/lorawan-stack/issues/1137 by @bafonins

johanstokking commented 5 years ago

Please discuss relevance for Next Up

kschiffer commented 5 years ago

I think we should look into resolving this in the near future.

bafonins commented 4 years ago

We dont need to change the current api of the stack in order to implement this. We can generate api methods for the js sdk using the swagger schema that is produced by grpc-gateway.

bafonins commented 4 years ago

Also, references https://github.com/TheThingsNetwork/lorawan-stack/issues/1982. no api changes required as well

bafonins commented 4 years ago

update on this. I have a working utility that can generate API functions from the swagger schema using babel. However, I would like to check if we can use grpc directly.

htdvisser commented 4 years ago

I have tried that in the past. The best way (at the time) was https://github.com/improbable-eng/grpc-web

johanstokking commented 4 years ago

See #2298 for an open issue with Swagger also

rvolosatovs commented 4 years ago

FYI https://github.com/grpc/grpc-web is supported by https://github.com/TheThingsIndustries/docker-protobuf Not sure what's the difference from improbable-eng one and if it's related at all

bafonins commented 4 years ago

Moving to Next up since this doesnt cause any problems with the current setup and there are issues with higher priority to work on.