pub struct SchemaLearner { /* private fields */ }Expand description
Thread-safe schema learner for API endpoints.
Uses DashMap for lock-free concurrent access to endpoint schemas. Implements O(1) amortized LRU eviction when max_schemas is exceeded.
Implementations§
Source§impl SchemaLearner
impl SchemaLearner
Sourcepub fn with_config(config: SchemaLearnerConfig) -> Self
pub fn with_config(config: SchemaLearnerConfig) -> Self
Create a new schema learner with custom configuration.
Sourcepub fn config(&self) -> &SchemaLearnerConfig
pub fn config(&self) -> &SchemaLearnerConfig
Get current configuration.
Sourcepub fn learn_from_request(&self, template: &str, request_body: &Value)
pub fn learn_from_request(&self, template: &str, request_body: &Value)
Learn schema from a request body.
Updates the endpoint schema with field types and constraints learned from the JSON body.
§Note
Only JSON object bodies are processed. Array-root bodies (e.g., [{...}])
are silently skipped. This is a known limitation for APIs that use arrays
as the root element in request/response bodies.
Sourcepub fn learn_from_response(&self, template: &str, response_body: &Value)
pub fn learn_from_response(&self, template: &str, response_body: &Value)
Learn schema from a response body.
§Note
Only JSON object bodies are processed. Array-root bodies (e.g., [{...}])
are silently skipped. This is a known limitation for APIs that use arrays
as the root element in request/response bodies.
Sourcepub fn learn_from_pair(
&self,
template: &str,
request_body: Option<&Value>,
response_body: Option<&Value>,
)
pub fn learn_from_pair( &self, template: &str, request_body: Option<&Value>, response_body: Option<&Value>, )
Learn from both request and response.
§Note
Only JSON object bodies are processed. Array-root bodies (e.g., [{...}])
are silently skipped. This is a known limitation for APIs that use arrays
as the root element in request/response bodies.
Sourcepub fn validate_request(
&self,
template: &str,
request_body: &Value,
) -> ValidationResult
pub fn validate_request( &self, template: &str, request_body: &Value, ) -> ValidationResult
Validate a request body against the learned schema.
Returns a list of violations. Empty list means validation passed. Returns empty if schema doesn’t exist or has insufficient samples.
Sourcepub fn validate_response(
&self,
template: &str,
response_body: &Value,
) -> ValidationResult
pub fn validate_response( &self, template: &str, response_body: &Value, ) -> ValidationResult
Validate a response body against the learned schema.
Sourcepub fn get_schema(&self, template: &str) -> Option<EndpointSchema>
pub fn get_schema(&self, template: &str) -> Option<EndpointSchema>
Get schema for an endpoint.
Sourcepub fn get_all_schemas(&self) -> Vec<EndpointSchema>
pub fn get_all_schemas(&self) -> Vec<EndpointSchema>
Get all schemas.
Sourcepub fn get_stats(&self) -> SchemaLearnerStats
pub fn get_stats(&self) -> SchemaLearnerStats
Get statistics.
Sourcepub fn export(&self) -> Vec<EndpointSchema>
pub fn export(&self) -> Vec<EndpointSchema>
Export all schemas for persistence.
Sourcepub fn import(&self, schemas: Vec<EndpointSchema>)
pub fn import(&self, schemas: Vec<EndpointSchema>)
Import schemas from persistence.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SchemaLearner
impl !RefUnwindSafe for SchemaLearner
impl Send for SchemaLearner
impl Sync for SchemaLearner
impl Unpin for SchemaLearner
impl UnsafeUnpin for SchemaLearner
impl UnwindSafe for SchemaLearner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more