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

openRPC based APIs #2346

Open
xmonader opened this issue May 29, 2024 · 6 comments
Open

openRPC based APIs #2346

xmonader opened this issue May 29, 2024 · 6 comments
Assignees
Labels
type_feature New feature or request
Milestone

Comments

@xmonader
Copy link
Collaborator

the plan would be exposing zos APIs over mycelium IP, Let's start by creating openRPC documentation, underlying handlers won't need to be changed

KDS is suggesting documenting using this https://pypi.org/project/tabella/

@ashraffouda
Copy link
Collaborator

to have openrpc for zos api we need some modification to myceilum for user verification so it would be better if the user starts myceilum with his mnemonics so it has the same identity on the chain and from that we can check the sender ip and using myceilum we can get the key hence we can look up his twin with that key from the chain so we verify that it is the same user. so what needed from myceilum
1- user start myceilum with his chain mnemonics so we can derive the same key
2- from ip we can get the address (pk)

@ashraffouda ashraffouda added the type_feature New feature or request label Jun 2, 2024
@ashraffouda ashraffouda added this to the 3.12 milestone Jun 2, 2024
@ashraffouda
Copy link
Collaborator

ashraffouda commented Jun 4, 2024

so far I checked those pkgs
1- https://github.com/zchee/go-openrpc
this repo doesn't have a working code. all commits seems like initial commits and not maintaind and is like 5 years old

2- https://github.com/gregdhill/go-openrpc
this one is working I did a hello world example but also not maintained and is 2 years old also using deprecated pkgs like packr but this is not a big deal we can either use it as it is or maybe later we update it those deprecated stuff is not used alot in the code
this one starts from api.json file and it will generate the server stubs, for client generation in go or in any other language we need to use different libraries
3- https://github.com/etclabscore/go-openrpc-reflect
I didn't do hands on on it but the difference between it and the second one is this one starts from the code and tries to reflect the server code and generate the json spec file but this one expecting to follow some code styles also not sure if this will be working with all our types in zos or not

p.s all the above pkgs doesn't provide client code generation, so whatever we will choose from the above we will relay on an external openrpc client generation tool

@Omarabdul3ziz
Copy link
Contributor

Omarabdul3ziz commented Jul 1, 2024

Update:

to simplify things here is what we need:

  • a server code: using the jsonrpc protocol (should be written in go)
  • an openrpc doc: a document describing the jsonrpc API
  • a client code: uses the jsonrpc protocol to call the API (should be in different langs: go, ts, v, ...)

as an implementation, i am thinking of:

  • Server could be implemented by the net/rpc package it should have all that we need. i already created a working example with it.
  • Docs file should be auto-generated from the server, according to the openrpc this could done by registering an rpc.discover method to the server, after some searching the only tool that can do this is https://github.com/etclabscore/go-openrpc-reflect i tried it and it is compatible with the servers from net/rpc i managed to create a simple doc with it. but unfortunately, it has some problems and limitations:
    • it uses an old version of the openrpc schema here
    • methods can't handle complex types, only the numeric/bool/string types so structs/slices are not allowed as params or return types here
  • Client can be auto-generated from the openrpc file with this official tool from open-rpc org https://github.com/open-rpc/generator it supports generating the client code with ts

another quicker approach @ashraffouda suggests is to start from the doc file itself so

Suggestion

  • to bypass the limitation on the reflect package, it is mentioned that we can build a custom schema definition, there are no docs around that but i may invest some time trying to do it to allow structs as param/return types
  • or like this tool https://github.com/swaggo/swag that generates OpenApi docs for RestApi from comments on handlers, we could have a tool that generates OpenRpc docs for out JsonRpcApi from comments on the method/types.

both suggestions will take some time, so to finish things quickly we could go with ashraf suggestion and then consider one of the suggestions.

@ashraffouda
Copy link
Collaborator

it will be better if we can build the server then generate the spec file out of it, but as u mentioned this is not well supported in golang, but to do this by either create a tool to generate this file or modify one of the existing libs to do this will take much time than expected, my suggestion is to create the spec file manually and use gregdhill/go-openrpc to create server code which I think will be much much faster than doing other suggestions

@Omarabdul3ziz
Copy link
Contributor

work is done on the:

  • specfile
  • generator tool
  • jsonrpc endpoints

waiting for this threefoldtech/mycelium#341

@ashraffouda
Copy link
Collaborator

blocked on threefoldtech/mycelium#341

@ashraffouda ashraffouda moved this from In Progress to Blocked in 3.15.x Jul 17, 2024
@xmonader xmonader removed this from 3.15.x Oct 24, 2024
@xmonader xmonader modified the milestones: 3.12, 3.13 Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type_feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants