Repository: juspay/hyperswitch
File: crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs (Rust)

Code before:

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PaymentsResponse {
    operation: Operation,
    three_d_s_auth_request: String,
    three_d_s_auth_url: Secret<url::Url>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NexixpayMandateResponse {
    operation: Operation,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
pub enum NexixpayPaymentsResponse {
    PaymentResponse(Box<PaymentsResponse>),
    MandateResponse(Box<NexixpayMandateResponse>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ThreeDSAuthResult {
    #[serde(skip_serializing_if = "Option::is_none")]
    authentication_value: Option<Secret<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    eci: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    xid: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    status: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    version: Option<String>,
}

impl ForeignTryFrom<(&ThreeDSAuthResult, String, Option<Secret<String>>)>
    for UcsAuthenticationData
{
    type Error = error_stack::Report<errors::ConnectorError>;

    fn foreign_try_from(
        (auth_result, operation_id, pa_res): (&ThreeDSAuthResult, String, Option<Secret<String>>),
    ) -> Result<Self, Self::Error> {
        Ok(Self {
            trans_status: auth_result
                .status
                .as_ref()
                .and_then(|s| s.parse::<common_enums::TransactionStatus>().ok()),

Review comment (suggestion):
You can add a single `skip_serializing_none` annotation on the Struct. This will be applied on all fields
```suggestion
#[serde(rename_all = "camelCase")]
#[skip_serializing_none]
```

Code after:
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PaymentsResponse {
    operation: Operation,
    three_d_s_auth_request: String,
    three_d_s_auth_url: Secret<url::Url>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NexixpayMandateResponse {
    operation: Operation,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
pub enum NexixpayPaymentsResponse {
    PaymentResponse(Box<PaymentsResponse>),
    MandateResponse(Box<NexixpayMandateResponse>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[skip_serializing_none]
pub struct ThreeDSAuthResult {
    authentication_value: Option<Secret<String>>,
    eci: Option<String>,
    xid: Option<String>,
    status: Option<String>,
    version: Option<String>,
}

impl ForeignTryFrom<(&ThreeDSAuthResult, String)> for UcsAuthenticationData {
    type Error = error_stack::Report<errors::ConnectorError>;

    fn foreign_try_from(
        (auth_result, operation_id): (&ThreeDSAuthResult, String),
    ) -> Result<Self, Self::Error> {
        Ok(Self {
            trans_status: auth_result
                .status
                .as_ref()
                .and_then(|s| s.parse::<common_enums::TransactionStatus>().ok()),
            eci: auth_result.eci.clone(),
            cavv: auth_result.authentication_value.clone(),
            ucaf_collection_indicator: None,
            threeds_server_transaction_id: auth_result.xid.clone(),
            message_version: auth_result