`anyOf` generated code cannot be serialized
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia con il file my_types.json allegato e con il Rust generato dalla relativa definizione anyOf; riproduci la serializzazione della variante string in una richiesta RPC. Traccia il modo in cui il tipo generato gestisce l’untagged enum e il flattening, quindi verifica che l’errore di serializzazione segnalato sia stato risolto o che sia stata stabilita una soluzione alternativa documentata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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:
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub enum Predefined {
Earliest,
Pending,
#[default]
Latest,
Safe,
Finalized,
}
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct BlockNumber {
block_number: EthInt64,
}
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct BlockHash {
block_hash: EthHash,
require_canonical: bool,
}
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(untagged)]
pub enum BlockNumberOrHash {
#[schemars(with = "String")]
PredefinedBlock(Predefined),
BlockNumber(EthInt64),
BlockHash(EthHash),
BlockNumberObject(BlockNumber),
BlockHashObject(BlockHash),
}
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 uses anyOf (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:
couldn't serialize params
can only flatten structs and maps (got a string)
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.
- Lingua principale
- Rust
- Stelle
- 898
- Fork
- 114
- Merge medio
- 4h 18m
- PR unite (30g)
- 14
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di oxidecomputer/typify
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
oxidecomputer/typify#1077 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
oxidecomputer/typify#1075 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
oxidecomputer/typify#1060 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 48/100
oxidecomputer/typify#1059 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
oxidecomputer/typify#1022 · 1 commento ·
Tutte le issue di oxidecomputer/typify
Issue simili
-
risk:low runtime status:in-progress type:test
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
bevyengine/bevy#25861 ·