Skip to content

Commit 846960a

Browse files
Generate JSON schema for app-server protocol (#5063)
Add annotations and an export script that let us generate app-server protocol types as typescript and JSONSchema. The script itself is a bit hacky because we need to manually label some of the types. Unfortunately it seems that enum variants don't get good names by default and end up with something like `EventMsg1`, `EventMsg2`, etc. I'm not an expert in this by any means, but since this is only run manually and we already need to enumerate the types required to describe the protocol, it didn't seem that much worse. An ideal solution here would be to have some kind of root that we could generate schemas for in one go, but I'm not sure if that's compatible with how we generate the protocol today.
1 parent 049a61b commit 846960a

File tree

19 files changed

+807
-288
lines changed

19 files changed

+807
-288
lines changed

codex-rs/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codex-rs/app-server-protocol/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ path = "src/lib.rs"
1111
workspace = true
1212

1313
[dependencies]
14+
anyhow = { workspace = true }
15+
clap = { workspace = true, features = ["derive"] }
1416
codex-protocol = { workspace = true }
1517
paste = { workspace = true }
18+
schemars = { workspace = true }
1619
serde = { workspace = true, features = ["derive"] }
1720
serde_json = { workspace = true }
1821
strum_macros = { workspace = true }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use anyhow::Result;
2+
use clap::Parser;
3+
use std::path::PathBuf;
4+
5+
#[derive(Parser, Debug)]
6+
#[command(
7+
about = "Generate TypeScript bindings and JSON Schemas for the Codex app-server protocol"
8+
)]
9+
struct Args {
10+
/// Output directory where generated files will be written
11+
#[arg(short = 'o', long = "out", value_name = "DIR")]
12+
out_dir: PathBuf,
13+
14+
/// Optional Prettier executable path to format generated TypeScript files
15+
#[arg(short = 'p', long = "prettier", value_name = "PRETTIER_BIN")]
16+
prettier: Option<PathBuf>,
17+
}
18+
19+
fn main() -> Result<()> {
20+
let args = Args::parse();
21+
codex_app_server_protocol::generate_types(&args.out_dir, args.prettier.as_deref())
22+
}

0 commit comments

Comments
 (0)