ory / sdk

The place where ORY's SDKs are being auto-generated
Apache License 2.0
140 stars 84 forks source link

Rust client fail to parse UiNodeAttributes #381

Open chunleng opened 4 days ago

chunleng commented 4 days ago

Preflight checklist

Ory Network Project

No response

Describe the bug

While using create_native_registration_flow, I ran into the following bug:

called `Result::unwrap()` on an `Err` value: Serde(Error("missing field `node_type`", line: 1, column: 508))

It seems to have occurred once before in https://github.com/ory/sdk/issues/325 and appeared again

Reproducing the bug

Run the following code:

use ory_client::apis::{
    configuration::Configuration, frontend_api::create_native_registration_flow,
};

#[tokio::main]
async fn main() {
    create_native_registration_flow(
        &Configuration {
            base_path: "http://localhost:4433".to_string(),
            ..Default::default()
        },
        None,
        None,
    )
    .await
    .unwrap();
}

Relevant log output

called `Result::unwrap()` on an `Err` value: Serde(Error("missing field `node_type`", line: 1, column: 508))

Relevant configuration

No response

Version

Kratos 1.3.0

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Docker Compose

Additional Context

docker image: oryd/kratos:v1.3.0 cargo:

ory-client = { git = "https://github.com/ory/client-rust", tag = "v1.14.5" }
chunleng commented 4 days ago

Did a little testing locally and found out that the autogenerator might be a little off:

According to serde library: https://serde.rs/enum-representations.html#internally-tagged When using #[serde(tag = "node_type")], the relevant field should not appear in the enum item's struct, however, the autogenerator seems to have included node_type in the item, causing the deserialize to fail

// https://github.com/ory/client-rust/blob/10027729688da0967e45cf7d7e1b8a1ec5ea8173/src/models/ui_node_attributes.rs#L16
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "node_type")]
pub enum UiNodeAttributes {
    #[serde(rename="input")]
    Input(Box<models::UiNodeInputAttributes>),
    ...
}

// https://github.com/ory/client-rust/blob/10027729688da0967e45cf7d7e1b8a1ec5ea8173/src/models/ui_node_input_attributes.rs#L16
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct UiNodeInputAttributes {
    ...
    /// NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0.  In this struct it technically always is \"input\". text Text input Input img Image a Anchor script Script
    #[serde(rename = "node_type")]
    pub node_type: NodeTypeEnum,
    ...
}

One method to resolve is to remove node_type field from the struct of UiNodeXXXAttributes (e.g. UiNodeInputAttributes, etc.)