Skip to main content

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 conformance;
50pub mod display;
51pub mod formatting;
52pub mod http_verb_map;
53pub mod openapi;
54pub mod output;
55pub mod resolve_target;
56pub mod scanner;
57pub mod schema_utils;
58pub mod serializers;
59pub mod types;
60
61// Re-export primary types at crate root for convenience.
62pub use ai_enhancer::{AIEnhancer, AIEnhancerError, Enhancer};
63pub use binding_loader::{BindingLoadError, BindingLoader};
64pub use conformance::assert_annotations_preserved;
65pub use display::{DisplayResolver, DisplayResolverError};
66pub use formatting::{
67    format_csv, format_jsonl, format_module, format_modules, format_schema, to_markdown,
68    FormatError, FormatOutput, GroupBy, MarkdownError, MarkdownOptions, ModuleStyle, SchemaStyle,
69};
70pub use http_verb_map::{
71    extract_path_param_names, generate_suggested_alias, has_path_params, resolve_http_verb,
72    substitute_path_params, SCANNER_VERB_MAP,
73};
74pub use openapi::{
75    deep_resolve_refs, extract_input_schema, extract_output_schema, resolve_ref, resolve_schema,
76};
77pub use output::errors::WriteError;
78pub use output::registry_writer::{HandlerFactory, HandlerFn, RegistryWriter};
79pub use output::rust_writer::RustWriter;
80pub use output::types::{Verifier, VerifyResult, WriteResult};
81pub use output::verifiers::{
82    run_verifier_chain, JSONVerifier, MagicBytesVerifier, RegistryVerifier, SyntaxVerifier,
83    YAMLVerifier,
84};
85pub use output::yaml_writer::YAMLWriter;
86pub use output::{get_writer, InvalidFormatError, OutputFormat};
87pub use resolve_target::{resolve_target, ResolveTargetError, ResolvedTarget};
88pub use scanner::{deduplicate_ids, filter_modules, infer_annotations_from_method, BaseScanner};
89pub use schema_utils::enrich_schema_descriptions;
90pub use serializers::{annotations_to_dict, module_to_dict, modules_to_dicts};
91pub use types::{clone_module, create_scanned_module, ScannedModule};
92
93#[cfg(feature = "http-proxy")]
94pub use output::http_proxy_writer::{HTTPProxyRegistryWriter, HTTPProxyRegistryWriterError};