From 67a219ffc2c08eb0e7ac4176908964458a1fd2a4 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Mon, 27 Oct 2025 14:06:13 -0700 Subject: [PATCH] fix: move account struct to app-server-protocol and use camelCase (#5829) Makes sense to move this struct to `app-server-protocol/` since we want to serialize as camelCase, but we don't for structs defined in `protocol/` It was: ``` export type Account = { "type": "ApiKey", api_key: string, } | { "type": "chatgpt", email: string | null, plan_type: PlanType, }; ``` But we want: ``` export type Account = { "type": "apiKey", apiKey: string, } | { "type": "chatgpt", email: string | null, planType: PlanType, }; ``` --- codex-rs/app-server-protocol/src/protocol.rs | 47 +++++++++++++++++++- codex-rs/protocol/src/account.rs | 15 ------- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/codex-rs/app-server-protocol/src/protocol.rs b/codex-rs/app-server-protocol/src/protocol.rs index f164ce56..65a233a3 100644 --- a/codex-rs/app-server-protocol/src/protocol.rs +++ b/codex-rs/app-server-protocol/src/protocol.rs @@ -5,7 +5,7 @@ use crate::JSONRPCNotification; use crate::JSONRPCRequest; use crate::RequestId; use codex_protocol::ConversationId; -use codex_protocol::account::Account; +use codex_protocol::account::PlanType; use codex_protocol::config_types::ForcedLoginMethod; use codex_protocol::config_types::ReasoningEffort; use codex_protocol::config_types::ReasoningSummary; @@ -236,6 +236,22 @@ client_request_definitions! { }, } +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)] +#[serde(tag = "type", rename_all = "camelCase")] +#[ts(tag = "type")] +pub enum Account { + #[serde(rename = "apiKey", rename_all = "camelCase")] + #[ts(rename = "apiKey", rename_all = "camelCase")] + ApiKey { api_key: String }, + + #[serde(rename = "chatgpt", rename_all = "camelCase")] + #[ts(rename = "chatgpt", rename_all = "camelCase")] + ChatGpt { + email: Option, + plan_type: PlanType, + }, +} + #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] #[serde(rename_all = "camelCase")] pub struct GetAccountResponse { @@ -1246,6 +1262,35 @@ mod tests { Ok(()) } + #[test] + fn account_serializes_fields_in_camel_case() -> Result<()> { + let api_key = Account::ApiKey { + api_key: "secret".to_string(), + }; + assert_eq!( + json!({ + "type": "apiKey", + "apiKey": "secret", + }), + serde_json::to_value(&api_key)?, + ); + + let chatgpt = Account::ChatGpt { + email: Some("user@example.com".to_string()), + plan_type: PlanType::Plus, + }; + assert_eq!( + json!({ + "type": "chatgpt", + "email": "user@example.com", + "planType": "plus", + }), + serde_json::to_value(&chatgpt)?, + ); + + Ok(()) + } + #[test] fn serialize_list_models() -> Result<()> { let request = ClientRequest::ListModels { diff --git a/codex-rs/protocol/src/account.rs b/codex-rs/protocol/src/account.rs index 1d63910c..fb707c3a 100644 --- a/codex-rs/protocol/src/account.rs +++ b/codex-rs/protocol/src/account.rs @@ -18,18 +18,3 @@ pub enum PlanType { #[serde(other)] Unknown, } - -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)] -#[serde(tag = "type")] -#[ts(tag = "type")] -pub enum Account { - ApiKey { - api_key: String, - }, - #[serde(rename = "chatgpt")] - #[ts(rename = "chatgpt")] - ChatGpt { - email: Option, - plan_type: PlanType, - }, -}