Polish schema endpoint: rename show, align field name, add tests

Review feedback on #23, applied on top of the original commit:

- Rename the CLI subcommand from `schema get` to `schema show` to match
  the existing `run show` / `commit show` convention. A `#[command(alias
  = "get")]` preserves muscle memory for anyone who already typed `get`.
- Rename `SchemaGetOutput` → `SchemaOutput` and its field `source` →
  `schema_source`, so the get response and the apply request use the
  same field name for the same concept.
- Use `println!` instead of `print!` in the CLI so the shell prompt
  doesn't land on the last line of schema output.
- Add three integration tests on `/schema`: happy path (no auth),
  401 when bearer is required but missing, 403 when the policy grants
  the actor branch_create but not read.

Follow-ups left for a separate PR: include `schema_ir_hash` and
`schema_identity_version` in the response payload so clients can do
drift detection and the server can set an ETag; and a fast-path local
read that skips `Omnigraph::open()` when only the schema source is
needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
andrew 2026-04-18 00:30:46 +03:00
parent 0c4df674fa
commit be520f31f4
4 changed files with 104 additions and 16 deletions

View file

@ -18,7 +18,7 @@ use omnigraph_server::api::{
BranchCreateOutput, BranchCreateRequest, BranchDeleteOutput, BranchListOutput,
BranchMergeOutput, BranchMergeRequest, ChangeOutput, ChangeRequest, CommitListOutput,
CommitOutput, ErrorOutput, ExportRequest, IngestOutput, IngestRequest, ReadOutput, ReadRequest,
RunListOutput, RunOutput, SchemaApplyOutput, SchemaApplyRequest, SchemaGetOutput, SnapshotOutput,
RunListOutput, RunOutput, SchemaApplyOutput, SchemaApplyRequest, SchemaOutput, SnapshotOutput,
SnapshotTableOutput, commit_output, ingest_output, read_output, run_output,
schema_apply_output, snapshot_payload,
};
@ -303,8 +303,9 @@ enum SchemaCommand {
#[arg(long)]
json: bool,
},
/// Get the current accepted schema source
Get {
/// Show the current accepted schema source
#[command(alias = "get")]
Show {
/// Repo URI
uri: Option<String>,
#[arg(long)]
@ -2014,7 +2015,7 @@ async fn main() -> Result<()> {
print_schema_apply_human(&output);
}
}
SchemaCommand::Get {
SchemaCommand::Show {
uri,
target,
config,
@ -2025,7 +2026,7 @@ async fn main() -> Result<()> {
resolve_remote_bearer_token(&config, uri.as_deref(), target.as_deref())?;
let uri = resolve_uri(&config, uri, target.as_deref())?;
let output = if is_remote_uri(&uri) {
remote_json::<SchemaGetOutput>(
remote_json::<SchemaOutput>(
&http_client,
Method::GET,
remote_url(&uri, "/schema"),
@ -2035,14 +2036,14 @@ async fn main() -> Result<()> {
.await?
} else {
let db = Omnigraph::open(&uri).await?;
SchemaGetOutput {
source: db.schema_source().to_string(),
SchemaOutput {
schema_source: db.schema_source().to_string(),
}
};
if json {
print_json(&output)?;
} else {
print!("{}", output.source);
println!("{}", output.schema_source);
}
}
},