cognis-macros 0.2.1

Standalone derive macros for generating OpenAPI-compatible JSON schemas from Rust structs
Documentation

Proc macros for the Cognis framework.

This crate exposes two kinds of macros with different coupling guarantees:

Framework-independent derives

[JsonSchema] / [ToolSchema] / [GraphState] are derive macros whose generated code references only serde_json (and, for GraphState, the reducer fn paths the user supplies). They don't reference cognis_core or any other workspace crate, so consumers can derive schemas in crates that don't depend on the framework.

Framework-coupled attributes

[tool] is a #[proc_macro_attribute] that generates a cognis_core::tools::BaseTool implementation. Its output necessarily references cognis_core::tools::{ValidateArgs, BaseTool, ToolInput, ToolOutput} and cognis_core::tools::validation::check_*. Code annotated with #[cognis::tool] must therefore compile against the cognis framework.

Derive usage

use cognis_macros::JsonSchema;
use serde::{Serialize, Deserialize};

#[derive(JsonSchema, Serialize, Deserialize)]
struct SearchFilter {
    /// Minimum relevance score
    min_score: f64,
    /// Categories to include
    categories: Vec<String>,
    /// Optional max results
    limit: Option<u32>,
}

// Static schema — no instance needed
let schema = SearchFilter::json_schema();
// {"type":"object","properties":{...},"required":["min_score","categories"]}

#[derive(JsonSchema)] supported types

Rust type JSON Schema
String {"type": "string"}
f32, f64 {"type": "number"}
i8..i128, u8..u128, usize, isize {"type": "integer"}
bool {"type": "boolean"}
Vec<T> {"type": "array", "items": <T>}
Option<T> schema of T, removed from required
HashMap<String, V> {"type": "object", "additionalProperties": <V>}
serde_json::Value {} (any)
Nested struct with #[derive(JsonSchema)] recursive object schema
Enum with #[derive(JsonSchema)] {"type": "string", "enum": [...]}