Skip to main content

document

Function document 

Source
pub fn document(
    registry: &CapabilityRegistry,
    version: &str,
    cases: Option<&CaseContext<'_>>,
) -> Result<Value, String>
Expand description

The OpenAPI document of the registry. cases is the repository the examples are drawn from: every operation’s examples are its capability’s benchmark cases against that index; None renders the document without examples, for a registry that has no repository behind it. Fails only on a schema component name defined twice with different content.

use majordomus_cli::capability::{builtin, CapabilityRegistry};
use majordomus_cli::http::openapi::document;
let registry = CapabilityRegistry::builder().with_builtin(builtin::all()).build().unwrap();
let doc = document(&registry, "0.0.0", None).unwrap();
assert_eq!(doc["openapi"], "3.1.0");
assert_eq!(doc["paths"]["/api/v1/object"]["get"]["operationId"], "objects.get");
assert_eq!(doc["paths"]["/api/v1/object"]["get"]["x-majordomus-mcp"]["tool"], "majordomus_get");
assert_eq!(doc["paths"]["/api/v1/object"]["get"]["tags"], serde_json::json!(["objects"]));
assert!(doc["tags"].as_array().unwrap().iter().any(|t| t["name"] == "objects"));
assert!(doc["paths"]["/api/v1/object"]["get"]["responses"]["404"].is_object());
assert!(doc["paths"]["/api/v1/object"]["get"]["responses"].get("422").is_none(), "a query has nothing to refuse");
assert!(doc["paths"]["/api/v1/peers/announce"]["post"]["responses"]["422"].is_object());