-
Notifications
You must be signed in to change notification settings - Fork 68
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
anyOf
generated code cannot be serialized
#710
Comments
The answer is both simple and disappointing: our current It it's possible to generate a pub enum BlockNumberOrHash {
#[schemars(with = "String")]
PredefinedBlock(Predefined),
BlockNumber(EthInt64),
BlockHash(EthHash),
BlockNumberObject(BlockNumber),
BlockHashObject(BlockHash),
} Looking at this definition, we've got
Generating a useful JSON schema from this type is going to be tricky. While code typify generates is lousy... even an optimal implementation wouldn't be that great given the lack of precision in the schema. I'm not exactly sure what the serializations are for these variants, but I'd suggest a custom |
Thanks! I've tried adding more precision to the three strings: So respectively using patterns
But I still face the same error. I will try the custom |
Yes: you'll probably need to hand-roll your |
In our codebase, we are using the following structs, which are part of an ETH RPC API built on top of our Filecoin node implementation:
We're using typify to create a JSON OpenRPC specification to establish a Common Node API.
Our issue is that the untagged
BlockNumberOrHash
enum is translated into a definition that usesanyOf
(see attached json file). The Rust code generated from this JSON specification is used in some tooling, and when trying to use the string variant to create an RPC request, we encounter the following error:Do you have any ideas on how to work around this kind of issue? For example, could we generate a
oneOf
(XOR) constraint instead?Many thanks.
my_types.json
The text was updated successfully, but these errors were encountered: