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

[Bug] API serializes certain fields as snake case differently than serde #2732

Closed
banool opened this issue Aug 9, 2022 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@banool
Copy link
Contributor

banool commented Aug 9, 2022

Code demonstrating the issue:

use serde::{Deserialize, Serialize};
use poem_openapi::{Object, Union};
use poem_openapi::types::ToJSON;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Object)]
pub struct Ed25519Signature {}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Object)]
pub struct MultiEd25519Signature {}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Object)]
pub struct MultiAgentSignature {}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Union)]
#[serde(tag = "type", rename_all = "snake_case")]
#[oai(one_of, discriminator_name = "type", rename_all = "snake_case")]
pub enum TransactionSignature {
    Ed25519Signature(Ed25519Signature),
    MultiEd25519Signature(MultiEd25519Signature),
    MultiAgentSignature(MultiAgentSignature),
}

fn main() {
    let test = TransactionSignature::Ed25519Signature(Ed25519Signature{});
    println!("test: {}", serde_json::to_string(&test).unwrap());
    println!("test: {}", test.to_json().unwrap());
}

Output:

test: {"type":"ed25519_signature"}
test: {"type":"ed_25519_signature"}

I will open an issue with Poem to make it act the same as serde.

@banool banool added the bug Something isn't working label Aug 9, 2022
@banool
Copy link
Contributor Author

banool commented Aug 9, 2022

poem-web/poem#362

@banool
Copy link
Contributor Author

banool commented Aug 10, 2022

At least on #2721 (I haven't tested on main yet) this makes it fail when starting a local testnet, specifically in process in crates/aptos-faucet/src/mint.rs, I believe on the account creation requests.

@banool
Copy link
Contributor Author

banool commented Aug 10, 2022

Okay this doesn't happen on main, that's good, it is something I change in #2721. This blocks rollout of API v1 though.

@banool
Copy link
Contributor Author

banool commented Aug 10, 2022

On my side I think I just need to find everywhere that deserializes an API response and make it use the function from the poem trait instead of serde_json.

@banool
Copy link
Contributor Author

banool commented Aug 10, 2022

Addressed on our side in #2764.

@banool banool closed this as completed Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant