Git Product home page Git Product logo

Comments (9)

BelfordZ avatar BelfordZ commented on August 31, 2024

the issues involved here:

  1. Generated code's return value is sometimes missing its generic type.
  2. Tries to add derive/serialize to foreign types
  3. multiple duplicate use statements

from generator.

mersinvald avatar mersinvald commented on August 31, 2024

Looked into the generated code, so here are some more specifics:

Multiple duplicate use statements

use $path gets generated in the header for every use of the $path in the type definitions, i.e for every sub-schema.

Multiple definitions of the same type:
pub enum TransactionElement {
    String(String),
    TransactionClass(TransactionClass),
}
/* ... */
pub enum TransactionElement {
    String(String),
    TransactionClass(TransactionClass),
}

Seems like the same issue as above, but with some types being regenerated if used twice in different methods?
Possible solution 1: deduplicate typings if they're the same
Possible solution 2: threat the whole schema as the whole when generating typings
Possible solution 3 (hacky): prefix the types with the method they relate to, or enclose them in modules like

pub mod method_name {
     /* method types */
}

Though the solution 3 is very dirty in terms of resulting API, as types related to different methods aren't compatible out of the box.

Tries to add derive/serialize to foreign types

Not present after fixing other errors

Generated code's return value is sometimes missing its generic type.

For the following result schemas the generator fails to derive the correct return type:

    "result": {
        "name": "",
        "schema": {
          "type": "array",
          "items": {
            "$ref": "#/components/schemas/Log"
          }
        }
      }
    "result": {
        "name": "",
        "schema": {
          "$ref": "#/components/schemas/BlockRLP"
        }
      }
    "result": {
        "name": "",
        "schema": {
          "description": "",
          "$ref": "#/components/schemas/Bytes"
        }
      }

The common issue here is the "name": "" which is causing troubles, as far as `I can see.
Possible solution: fallback to the schema name if name's not present?

Missing types

EndHash type isn't present in type definitions, and it's a pretty problematic type as in different methods it has different characteristics, even though it is named identically.

Possible solutions: prefix the method name to the ambiguous types, no idea why there's no definition at all though, maybe generator couldn't decide which one of the multiple variants of EndHash to generate.

Tests mis-generation for types with common prefix

There's the following list of functions:

pub fn debug_traceBlock(&mut self, blockRLP: BlockRlp) -> RpcRequest<StackTrace>;
pub fn debug_traceBlockByHash(&mut self, blockHash: BlockHash) -> RpcRequest<Trace>;
pub fn debug_traceBlockByNumber(&mut self, blockNumber: BlockNumber) -> RpcRequest<Trace>;
pub fn debug_traceBlockFromFile(&mut self, filename: Filename) -> RpcRequest<Bytes>;

The generated test for debug_traceBlock tries to pass 4 arguments (BlockRlp, BlockHash, BlockNumber, Filename) as the arguments.
Seems like arguments list for foo contains all arguments for any foo* combined.

from generator.

mersinvald avatar mersinvald commented on August 31, 2024

Actually about the Generated code's return value is sometimes missing its generic type.

I'd propose not using the name at all, if the schema is defined as just a single ref statement.
It cripples the API a lot: two identical structs with just different names wouldn't be interchangeable in Rust, so say there are 2 methods:

fn one() -> SameType1
fn two(arg: SameType2)

The SameType1 and SameType2 have common schema and different names, therefore user wouldn't be able to do two(one()) call without manually converting the same type into another same type:

let st1 = one();
let st2 = SameType2 {
    a: st1.a,
    b: st1.b,
    c: st1.c,
    ...
};
two(st2);

from generator.

shanejonas avatar shanejonas commented on August 31, 2024

@mersinvald names shouldn't be empty, I'll fix that up in the openrpc.json for multi-geth

from generator.

shanejonas avatar shanejonas commented on August 31, 2024

@mersinvald the openrpc.json is all fixed up and filled out, latest is here: https://raw.githubusercontent.com/etclabscore/multi-geth/feat/openrpc-discover/rpc/openrpc.json

from generator.

BelfordZ avatar BelfordZ commented on August 31, 2024

related to #169

from generator.

mersinvald avatar mersinvald commented on August 31, 2024

@shanejonas 404 at https://raw.githubusercontent.com/etclabscore/multi-geth/feat/openrpc-discover/rpc/openrpc.json

from generator.

shanejonas avatar shanejonas commented on August 31, 2024

this openrpc file lives here now

https://github.com/etclabscore/ethereum-json-rpc-specification

@mersinvald

from generator.

BelfordZ avatar BelfordZ commented on August 31, 2024

fixed!

from generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.