Skip to main content

Crate navree_openapi

Crate navree_openapi 

Source
Expand description

The OpenAPI 3.1 document model and the ToSchema trait and derive that describe Rust types as JSON Schema (for the document, for AI tools and structured output, for MCP tools and for the automation editor).

Items hidden from this documentation are not public API: Navree’s own macros and crates use them, and they can change in any release.

use navree_openapi::ToSchema;
use serde_json::json;

/// A note on a deal.
#[derive(ToSchema)]
#[schema(as = Note)]
struct NoteResource {
    /// The text.
    body: String,
    pinned: Option<bool>,
}

assert_eq!(NoteResource::name(), "Note");
assert_eq!(
    serde_json::to_value(NoteResource::schema()).unwrap(),
    json!({
        "type": "object",
        "description": "A note on a deal.",
        "required": ["body"],
        "properties": {
            "body": {"type": "string", "description": "The text."},
            "pinned": {"type": ["boolean", "null"]},
        },
    })
);

Structs§

ComponentProperties
Properties a module adds at run time to the values of one component schema, so the OpenAPI document lists them too. navree-auth’s user resource extensions add fields to UserResource this way (an app’s roles, say).
Components
components.
Document
An OpenAPI document (the root object).
Info
info.
MediaType
A body of one content type.
NotASchema
A value that can’t be a schema: anything but a JSON object.
Object
#[schema(value_type = Object)]: {"type": "object"}, whatever the field’s Rust type is.
Operation
An operation: what one method on one path does.
Parameter
A parameter of an operation.
RequestBody
A request body.
Response
A response.
Schema
One JSON Schema. Every field is a keyword; extra holds the ones without a field, so reading a schema and writing it again loses nothing but the order of its keywords.
SecurityScheme
A security scheme.
Server
One entry of servers.
Tag
One entry of tags.

Enums§

SchemaType
The type keyword: one name, or several (["string", "null"]).
Subschema
A keyword whose value is a schema or a boolean (items, additionalProperties).
Type
A JSON Schema type name.

Traits§

ToSchema
A type described by a JSON Schema: #[derive(ToSchema)], or by hand.

Functions§

components_of
The component schemas T refers to, one for each name: what a schema that stands alone puts under $defs.

Type Aliases§

PathItem
The operations of one path, by lower-case method (get, post), in the order they were added.

Derive Macros§

ToSchema
#[derive(ToSchema)]: see the macro’s documentation in navree-macros. Implements navree_openapi::ToSchema for a struct or an enum: its JSON Schema, for the OpenAPI document, AI tools and structured output, MCP tools and automation blocks.