apcore_toolkit/lib.rs
1// All-caps acronyms (AIEnhancer, HTTPProxy*, YAML*, JSON*) are intentional:
2// these names match the Python and TypeScript SDK public surfaces for cross-language
3// parity. Clippy's C-CASE recommendation is waived for this crate.
4#![allow(clippy::upper_case_acronyms)]
5
6//! apcore-toolkit — Shared scanner, schema extraction, and output toolkit.
7//!
8//! Rust implementation — tri-language parity with Python and TypeScript.
9//!
10//! The crate version is exported as [`VERSION`] to match the `__version__`
11//! / `VERSION` symbols in the Python and TypeScript SDKs.
12//!
13//! # Language-writer parity
14//!
15//! Python ships `PythonWriter`, TypeScript ships `TypeScriptWriter`, and the
16//! Rust SDK ships [`RustWriter`] for generating language-native handler stubs.
17//! The generated files are starting-point stubs; Rust consumers may also work
18//! directly with the strongly-typed `ScannedModule` / registry APIs.
19//!
20//! [`RustWriter`]: crate::output::rust_writer::RustWriter
21//!
22//! # Crate-root re-exports
23//!
24//! The HTTP verb helpers and `SCANNER_VERB_MAP` are exported directly at
25//! the crate root. As of v0.5.0 they are no longer re-exported through the
26//! `scanner` module path — import from the crate root or `http_verb_map`:
27//!
28//! ```
29//! use apcore_toolkit::{generate_suggested_alias, has_path_params, resolve_http_verb, SCANNER_VERB_MAP};
30//!
31//! assert_eq!(resolve_http_verb("POST", false), "create");
32//! assert!(has_path_params("/tasks/{id}"));
33//! assert_eq!(SCANNER_VERB_MAP.get("POST").copied(), Some("create"));
34//! assert_eq!(
35//! generate_suggested_alias("/tasks/user_data", "POST"),
36//! "tasks.user_data.create"
37//! );
38//! ```
39
40/// Crate version, read from `Cargo.toml` at compile time.
41///
42/// Mirrors Python's `apcore_toolkit.__version__` and TypeScript's
43/// `VERSION` export so all three SDKs expose the current toolkit version
44/// via a public symbol.
45pub const VERSION: &str = env!("CARGO_PKG_VERSION");
46
47pub mod ai_enhancer;
48pub mod binding_loader;
49pub mod display;
50pub mod formatting;
51pub mod http_verb_map;
52pub mod openapi;
53pub mod output;
54pub mod resolve_target;
55pub mod scanner;
56pub mod schema_utils;
57pub mod serializers;
58pub mod types;
59
60// Re-export primary types at crate root for convenience.
61pub use ai_enhancer::{AIEnhancer, AIEnhancerError, Enhancer};
62pub use binding_loader::{BindingLoadError, BindingLoader};
63pub use display::{DisplayResolver, DisplayResolverError};
64pub use formatting::{
65 format_csv, format_jsonl, format_module, format_modules, format_schema, to_markdown,
66 FormatError, FormatOutput, GroupBy, MarkdownError, MarkdownOptions, ModuleStyle, SchemaStyle,
67};
68pub use http_verb_map::{
69 extract_path_param_names, generate_suggested_alias, has_path_params, resolve_http_verb,
70 substitute_path_params, SCANNER_VERB_MAP,
71};
72pub use openapi::{
73 deep_resolve_refs, extract_input_schema, extract_output_schema, resolve_ref, resolve_schema,
74};
75pub use output::errors::WriteError;
76pub use output::registry_writer::{HandlerFactory, HandlerFn, RegistryWriter};
77pub use output::rust_writer::RustWriter;
78pub use output::types::{Verifier, VerifyResult, WriteResult};
79pub use output::verifiers::{
80 run_verifier_chain, JSONVerifier, MagicBytesVerifier, RegistryVerifier, SyntaxVerifier,
81 YAMLVerifier,
82};
83pub use output::yaml_writer::YAMLWriter;
84pub use output::{get_writer, InvalidFormatError, OutputFormat};
85pub use resolve_target::{resolve_target, ResolveTargetError, ResolvedTarget};
86pub use scanner::{deduplicate_ids, filter_modules, infer_annotations_from_method, BaseScanner};
87pub use schema_utils::enrich_schema_descriptions;
88pub use serializers::{annotations_to_dict, module_to_dict, modules_to_dicts};
89pub use types::{clone_module, create_scanned_module, ScannedModule};
90
91#[cfg(feature = "http-proxy")]
92pub use output::http_proxy_writer::{HTTPProxyRegistryWriter, HTTPProxyRegistryWriterError};