Expand description
§navree-openapi
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§
- Component
Properties - 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
UserResourcethis way (an app’sroles, say). - Components
components.- Document
- An OpenAPI document (the root object).
- Info
info.- Media
Type - A body of one content type.
- NotA
Schema - 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.
- Request
Body - A request body.
- Response
- A response.
- Schema
- One JSON Schema. Every field is a keyword;
extraholds the ones without a field, so reading a schema and writing it again loses nothing but the order of its keywords. - Security
Scheme - A security scheme.
- Server
- One entry of
servers. - Tag
- One entry of
tags.
Enums§
- Schema
Type - The
typekeyword: 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
Trefers to, one for each name: what a schema that stands alone puts under$defs.
Type Aliases§
- Path
Item - 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. Implementsnavree_openapi::ToSchemafor a struct or an enum: its JSON Schema, for the OpenAPI document, AI tools and structured output, MCP tools and automation blocks.