Skip to content

How to flatten parameters by using proc macro? #1576

@wakuflair

Description

@wakuflair

Hi, I have an API defined by proc macro like this:

#[method(name = "foo")]
async fn foo(&self, parameter: FooParameter) -> Result<(), ErrorObjectOwned>;

Using a struct FooParameter because there are many parameters and I think it's a best practice for grouping parameters.

But now the client has to have one more level to construct the parameter:

var payload = {
      jsonrpc: "2.0",
      method: "foo",
      params:  {
        parameter: {
          name: "bob",
          age: 40,
        },
      id: 1,
    }
  }

So is there a way to flatten the struct parameter when using proc macro to allow the client use like this:

var payload = {
  jsonrpc: "2.0",
  method: "foo",
  params: {
    name: "bob",
    age: 40,
  },
  id: 1,
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions