[app-server] fix account/read response annotation (#5642)
The API schema export is currently broken: ``` > cargo run -p codex-app-server-protocol --bin export -- --out DIR Error: this type cannot be exported ``` This PR fixes the error message so we get more info: ``` > cargo run -p codex-app-server-protocol --bin export -- --out DIR Error: failed to export client responses: dependency core::option::Option<codex_protocol::account::Account> cannot be exported ``` And fixes the root cause which is the `account/read` response.
This commit is contained in:
@@ -23,6 +23,7 @@ use std::io::Write;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
use ts_rs::ExportError;
|
||||||
use ts_rs::TS;
|
use ts_rs::TS;
|
||||||
|
|
||||||
const HEADER: &str = "// GENERATED CODE! DO NOT MODIFY BY HAND!\n\n";
|
const HEADER: &str = "// GENERATED CODE! DO NOT MODIFY BY HAND!\n\n";
|
||||||
@@ -104,6 +105,19 @@ macro_rules! for_each_schema_type {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn export_ts_with_context<F>(label: &str, export: F) -> Result<()>
|
||||||
|
where
|
||||||
|
F: FnOnce() -> std::result::Result<(), ExportError>,
|
||||||
|
{
|
||||||
|
match export() {
|
||||||
|
Ok(()) => Ok(()),
|
||||||
|
Err(ExportError::CannotBeExported(ty)) => Err(anyhow!(
|
||||||
|
"failed to export {label}: dependency {ty} cannot be exported"
|
||||||
|
)),
|
||||||
|
Err(err) => Err(err.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate_types(out_dir: &Path, prettier: Option<&Path>) -> Result<()> {
|
pub fn generate_types(out_dir: &Path, prettier: Option<&Path>) -> Result<()> {
|
||||||
generate_ts(out_dir, prettier)?;
|
generate_ts(out_dir, prettier)?;
|
||||||
generate_json(out_dir)?;
|
generate_json(out_dir)?;
|
||||||
@@ -113,13 +127,17 @@ pub fn generate_types(out_dir: &Path, prettier: Option<&Path>) -> Result<()> {
|
|||||||
pub fn generate_ts(out_dir: &Path, prettier: Option<&Path>) -> Result<()> {
|
pub fn generate_ts(out_dir: &Path, prettier: Option<&Path>) -> Result<()> {
|
||||||
ensure_dir(out_dir)?;
|
ensure_dir(out_dir)?;
|
||||||
|
|
||||||
ClientRequest::export_all_to(out_dir)?;
|
export_ts_with_context("ClientRequest", || ClientRequest::export_all_to(out_dir))?;
|
||||||
export_client_responses(out_dir)?;
|
export_ts_with_context("client responses", || export_client_responses(out_dir))?;
|
||||||
ClientNotification::export_all_to(out_dir)?;
|
export_ts_with_context("ClientNotification", || {
|
||||||
|
ClientNotification::export_all_to(out_dir)
|
||||||
|
})?;
|
||||||
|
|
||||||
ServerRequest::export_all_to(out_dir)?;
|
export_ts_with_context("ServerRequest", || ServerRequest::export_all_to(out_dir))?;
|
||||||
export_server_responses(out_dir)?;
|
export_ts_with_context("server responses", || export_server_responses(out_dir))?;
|
||||||
ServerNotification::export_all_to(out_dir)?;
|
export_ts_with_context("ServerNotification", || {
|
||||||
|
ServerNotification::export_all_to(out_dir)
|
||||||
|
})?;
|
||||||
|
|
||||||
generate_index_ts(out_dir)?;
|
generate_index_ts(out_dir)?;
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ client_request_definitions! {
|
|||||||
#[ts(rename = "account/read")]
|
#[ts(rename = "account/read")]
|
||||||
GetAccount {
|
GetAccount {
|
||||||
params: #[ts(type = "undefined")] #[serde(skip_serializing_if = "Option::is_none")] Option<()>,
|
params: #[ts(type = "undefined")] #[serde(skip_serializing_if = "Option::is_none")] Option<()>,
|
||||||
response: Option<Account>,
|
response: GetAccountResponse,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// DEPRECATED APIs below
|
/// DEPRECATED APIs below
|
||||||
@@ -534,6 +534,12 @@ pub struct GetAccountRateLimitsResponse {
|
|||||||
pub rate_limits: RateLimitSnapshot,
|
pub rate_limits: RateLimitSnapshot,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||||
|
#[serde(transparent)]
|
||||||
|
#[ts(export)]
|
||||||
|
#[ts(type = "Account | null")]
|
||||||
|
pub struct GetAccountResponse(#[ts(type = "Account | null")] pub Option<Account>);
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct GetAuthStatusResponse {
|
pub struct GetAuthStatusResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user