apcore-toolkit
Rust toolkit for building APCore framework integrations. Scan web framework endpoints (Axum, Actix, Rocket, etc.), extract JSON Schemas, infer behavioral annotations, and output APCore-compatible module definitions — as YAML binding files, direct registry entries, or HTTP proxy modules.
If you're building an APCore adapter for a Rust web framework, this crate provides all the shared infrastructure so you only need to write the framework-specific scanning logic.
Installation
[]
= { = "https://github.com/aiperceivable/apcore-toolkit-rust" }
# Optional: HTTP proxy writer
= { = "https://github.com/aiperceivable/apcore-toolkit-rust", = ["http-proxy"] }
Core Modules
| Module | Description |
|---|---|
ScannedModule |
Canonical struct representing a scanned endpoint |
BaseScanner<App> |
Async trait for framework scanners, generic over the App type with default () (e.g., BaseScanner<axum::Router>) |
filter_modules |
Regex-based include/exclude filtering for scanned modules |
deduplicate_ids |
Resolves duplicate module IDs by appending _2, _3, etc. |
infer_annotations_from_method |
Maps HTTP methods to behavioral ModuleAnnotations |
YAMLWriter |
Generates .binding.yaml files for apcore::BindingLoader |
BindingLoader |
Parses .binding.yaml files back into ScannedModule values (pure-data inverse of YAMLWriter, with loose/strict modes) |
BindingLoadError |
thiserror-derived error enum: PathNotFound, FileRead, FileTooLarge, TooManyFiles, YamlParse, MissingFields, InvalidStructure |
RegistryWriter |
Registers modules directly into an apcore::Registry with pluggable HandlerFactory |
HTTPProxyRegistryWriter |
Registers HTTP proxy modules that forward requests to a running API (feature: http-proxy) |
Enhancer |
Pluggable trait for metadata enhancement |
AIEnhancer |
SLM-based metadata enhancement for scanned modules |
WriteResult |
Structured result type for all writer operations |
WriteError |
Typed error (via thiserror) for I/O failures during write |
Verifier |
Pluggable trait for validating written artifacts |
VerifyResult |
Result type for verification operations |
YAMLVerifier |
Verifies YAML files parse correctly with required fields |
RegistryVerifier |
Verifies modules are registered and retrievable |
MagicBytesVerifier |
Verifies file headers match expected magic bytes |
JSONVerifier |
Verifies JSON files parse correctly |
to_markdown |
Converts JSON objects to Markdown with depth control and table heuristics |
format_csv (v0.7.0) |
Byte-equivalent RFC 4180 CSV emitter — header = union of keys; canonical JSON for nested cells; CRLF terminator |
format_jsonl (v0.7.0) |
Byte-equivalent JSON Lines emitter — canonical compact JSON per row, LF terminator |
enrich_schema_descriptions |
Merges descriptions into JSON Schema properties |
DisplayResolver |
Sparse binding.yaml overlay — resolves alias, description, guidance, tags into metadata["display"] |
SyntaxVerifier |
Verifies Rust source files parse without syntax errors (via syn) |
deep_resolve_refs |
Recursively resolves all $ref pointers in a JSON Schema (depth-limited to 16) |
resolve_target |
Validates and parses module_path:qualname target strings |
get_writer |
Factory function mapping format strings to OutputFormat variants |
Usage
Scanning and Writing
use async_trait;
use ;
use json;
;
async
Framework-Specific Scanner (Axum Example)
use ;
use async_trait;
;
Direct Registry Registration
use Registry;
use RegistryWriter;
let mut registry = new;
let writer = new;
writer.write;
Registry with Custom Handler Factory
use Arc;
use ;
let factory: HandlerFactory = new;
let writer = with_handler_factory;
writer.write;
Output Format Factory
use ;
let format = get_writer; // Some(OutputFormat::Yaml)
let format = get_writer; // Some(OutputFormat::Registry)
let format = get_writer; // Some(OutputFormat::HttpProxy)
OpenAPI Schema Extraction
use ;
let input_schema = extract_input_schema;
let output_schema = extract_output_schema;
Schema Enrichment
use HashMap;
use enrich_schema_descriptions;
let mut descs = new;
descs.insert;
let enriched = enrich_schema_descriptions;
Markdown Formatting
use ;
use json;
let data = json!;
let opts = MarkdownOptions ;
let md = to_markdown.unwrap;
Tabular Formats (v0.7.0)
Byte-equivalent CSV / JSONL emitters with a cross-SDK conformance contract — Rust, Python, and TypeScript produce identical bytes for the same input.
use ;
use ;
let rows: = vec!;
// CSV: header = union of keys across all rows (no silent data loss on
// heterogeneous rows); nested values serialized as canonical compact JSON;
// RFC 4180 CRLF line terminator.
print!;
// sn,title,score,description\r\n1,First,78,\r\n2,Second,82,later-only field\r\n
// JSONL: canonical compact JSON per row, LF terminator, no trailing blank.
print!;
// UTF-8 BOM for Excel locales (default off for pipeline consumers):
print!;
Note — this crate enables the
serde_json/preserve_orderfeature, required for canonical insertion-order key emission. Transitively affects ALLserde_json::Mapiteration in your dependency tree; downstream code that relied on alphabetical iteration must re-sort explicitly.
See apcore-toolkit/docs/features/formatting.md § Tabular Formats for the full contract and apcore-toolkit/conformance/fixtures/format_csv.json / format_jsonl.json for the shared cross-SDK test corpus.
Requirements
- See
Cargo.tomlfor full dependency list
Features
| Feature | Description |
|---|---|
http-proxy |
Enables HTTPProxyRegistryWriter (adds reqwest dependency) |
Documentation
Full documentation is available at https://github.com/aiperceivable/apcore-toolkit.
License
Apache-2.0