Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ starlark = "0.13"

# CLI - MCP
rmcp = { version = "0.13", default-features = false }
schemars = "0.8"
schemars = "1.2"
Comment thread
echobt marked this conversation as resolved.
Comment thread
echobt marked this conversation as resolved.

# CLI - Utilities
time = { version = "0.3", features = ["formatting", "parsing", "local-offset", "macros"] }
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/app-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ the exact trusted browser origins in configuration.
## Contract

[OpenAPI 3.1 JSON](app-server.openapi.json) is generated from the handler models
with schemars 0.8.22 and served at authenticated `GET /api/v1/openapi.json`.
with schemars 1.2 and served at authenticated `GET /api/v1/openapi.json`.
The supported contract covers:

| Method | Path (under `/api/v1`) | Meaning |
Expand Down
44 changes: 22 additions & 22 deletions docs/reference/app-server.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"uptime_seconds": {
"format": "uint64",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
},
"version": {
Expand All @@ -42,8 +42,8 @@
},
"required": [
"status",
"uptime_seconds",
"version"
"version",
"uptime_seconds"
],
"title": "HealthResponse",
"type": "object"
Expand All @@ -62,7 +62,7 @@
},
"tokens": {
"format": "uint32",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
},
"tool_calls": {
Expand All @@ -76,9 +76,9 @@
}
},
"required": [
"content",
"id",
"role",
"content",
"tokens"
],
"title": "MessageResponse",
Expand All @@ -90,47 +90,47 @@
"active_sessions": {
"description": "Active sessions.",
"format": "uint",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
},
"errors": {
"description": "Errors.",
"format": "uint64",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
},
"rate_limit_hits": {
"description": "Rate limit hits.",
"format": "uint64",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
},
"sessions_created": {
"description": "Sessions created.",
"format": "uint64",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
},
"total_requests": {
"description": "Total requests.",
"format": "uint64",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
},
"uptime_seconds": {
"description": "Server uptime in seconds.",
"format": "uint64",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
}
},
"required": [
"uptime_seconds",
"active_sessions",
"errors",
"total_requests",
"rate_limit_hits",
"sessions_created",
"total_requests",
"uptime_seconds"
"errors"
],
"title": "MetricsSnapshot",
"type": "object"
Expand Down Expand Up @@ -163,7 +163,7 @@
},
"message_count": {
"format": "uint",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
},
"model": {
Expand All @@ -174,15 +174,15 @@
},
"total_tokens": {
"format": "uint64",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
}
},
"required": [
"id",
"message_count",
"model",
"status",
"message_count",
"total_tokens"
],
"title": "SessionListItem",
Expand All @@ -196,7 +196,7 @@
},
"message_count": {
"format": "uint",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
},
"metadata": true,
Expand All @@ -214,15 +214,15 @@
},
"total_tokens": {
"format": "uint64",
"minimum": 0.0,
"minimum": 0,
"type": "integer"
}
},
"required": [
"id",
"message_count",
"model",
"status",
"message_count",
"total_tokens"
],
"title": "SessionResponse",
Expand All @@ -246,9 +246,9 @@
}
},
"required": [
"arguments",
"id",
"name"
"name",
"arguments"
],
"type": "object"
}
Expand Down
11 changes: 9 additions & 2 deletions src/cortex-app-server/src/api/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ fn add<T: JsonSchema>(schemas: &mut Map<String, Value>, name: &str) {
let schema = schemars::schema_for!(T);
let encoded = serde_json::to_string(&schema)
.expect("Serializable schema")
.replace("#/$defs/", "#/components/schemas/")
.replace("#/definitions/", "#/components/schemas/");
let mut value: Value = serde_json::from_str(&encoded).expect("Generated schema JSON");
let object = value.as_object_mut().expect("Schema object");
object.remove("$schema");
if let Some(Value::Object(definitions)) = object.remove("definitions") {
schemas.extend(definitions);
// schemars 1.x emits nested schemas under `$defs` (JSON Schema 2020-12,
// the dialect OpenAPI 3.1 uses); 0.8 emitted `definitions` (draft 7).
// Both are unwrapped into the document's `components.schemas` map, which
// the `$ref` rewrite above points at.
for key in ["$defs", "definitions"] {
if let Some(Value::Object(nested)) = object.remove(key) {
schemas.extend(nested);
}
}
schemas.insert(name.to_string(), value);
}
Expand Down
16 changes: 7 additions & 9 deletions src/cortex-protocol/src/conversation_id.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Conversation identifier type.

use std::borrow::Cow;
use std::fmt;
use std::str::FromStr;

use schemars::JsonSchema;
use schemars::r#gen::SchemaGenerator;
use schemars::schema::{InstanceType, Schema, SchemaObject};
use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

Expand All @@ -15,15 +14,14 @@ use uuid::Uuid;
pub struct ConversationId(Uuid);

impl JsonSchema for ConversationId {
fn schema_name() -> String {
"ConversationId".to_string()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("ConversationId")
}

fn json_schema(_gen: &mut SchemaGenerator) -> Schema {
Schema::Object(SchemaObject {
instance_type: Some(InstanceType::String.into()),
format: Some("uuid".to_string()),
..Default::default()
json_schema!({
"type": "string",
"format": "uuid",
})
}
}
Expand Down
Loading