pub struct OpenApiRouteRegistry { /* private fields */ }Expand description
OpenAPI route registry that manages generated routes
Implementations§
Source§impl OpenApiRouteRegistry
impl OpenApiRouteRegistry
Sourcepub fn new(spec: OpenApiSpec) -> Self
pub fn new(spec: OpenApiSpec) -> Self
Create a new registry from an OpenAPI spec
Sourcepub fn new_with_env(spec: OpenApiSpec) -> Self
pub fn new_with_env(spec: OpenApiSpec) -> Self
Create a new registry from an OpenAPI spec with environment-based validation options
Options are read from environment variables:
MOCKFORGE_REQUEST_VALIDATION: “off”/“warn”/“enforce” (default: “enforce”)MOCKFORGE_AGGREGATE_ERRORS: “1”/“true” to aggregate errors (default: true)MOCKFORGE_RESPONSE_VALIDATION: “1”/“true” to validate responses (default: false)MOCKFORGE_RESPONSE_TEMPLATE_EXPAND: “1”/“true” to expand templates (default: false)MOCKFORGE_VALIDATION_STATUS: HTTP status code for validation failures (optional)
Sourcepub fn new_with_options(spec: OpenApiSpec, options: ValidationOptions) -> Self
pub fn new_with_options(spec: OpenApiSpec, options: ValidationOptions) -> Self
Construct with explicit options
Sourcepub fn clone_for_validation(&self) -> Self
pub fn clone_for_validation(&self) -> Self
Clone this registry for validation purposes (creates an independent copy)
This is useful when you need a separate registry instance for validation that won’t interfere with the main registry’s state.
Sourcepub fn routes(&self) -> &[OpenApiRoute]
pub fn routes(&self) -> &[OpenApiRoute]
Get all routes
Sourcepub fn spec(&self) -> &OpenApiSpec
pub fn spec(&self) -> &OpenApiSpec
Get the OpenAPI specification
Sourcepub fn build_router(self) -> Router
pub fn build_router(self) -> Router
Build an Axum router from the OpenAPI spec (simplified)
Sourcepub fn build_router_with_latency(
self,
latency_injector: LatencyInjector,
) -> Router
pub fn build_router_with_latency( self, latency_injector: LatencyInjector, ) -> Router
Build an Axum router from the OpenAPI spec with latency injection support
Sourcepub fn build_router_with_injectors(
self,
latency_injector: LatencyInjector,
failure_injector: Option<FailureInjector>,
) -> Router
pub fn build_router_with_injectors( self, latency_injector: LatencyInjector, failure_injector: Option<FailureInjector>, ) -> Router
Build an Axum router from the OpenAPI spec with both latency and failure injection support
Sourcepub fn build_router_with_injectors_and_overrides(
self,
latency_injector: LatencyInjector,
failure_injector: Option<FailureInjector>,
overrides: Option<Overrides>,
overrides_enabled: bool,
) -> Router
pub fn build_router_with_injectors_and_overrides( self, latency_injector: LatencyInjector, failure_injector: Option<FailureInjector>, overrides: Option<Overrides>, overrides_enabled: bool, ) -> Router
Build an Axum router from the OpenAPI spec with latency, failure injection, and overrides support
Sourcepub fn get_route(&self, path: &str, method: &str) -> Option<&OpenApiRoute>
pub fn get_route(&self, path: &str, method: &str) -> Option<&OpenApiRoute>
Get route by path and method
Sourcepub fn get_routes_for_path(&self, path: &str) -> Vec<&OpenApiRoute>
pub fn get_routes_for_path(&self, path: &str) -> Vec<&OpenApiRoute>
Get all routes for a specific path
Sourcepub fn validate_request(
&self,
path: &str,
method: &str,
body: Option<&Value>,
) -> Result<()>
pub fn validate_request( &self, path: &str, method: &str, body: Option<&Value>, ) -> Result<()>
Validate request against OpenAPI spec (legacy body-only)
Sourcepub fn validate_request_with(
&self,
path: &str,
method: &str,
path_params: &Map<String, Value>,
query_params: &Map<String, Value>,
body: Option<&Value>,
) -> Result<()>
pub fn validate_request_with( &self, path: &str, method: &str, path_params: &Map<String, Value>, query_params: &Map<String, Value>, body: Option<&Value>, ) -> Result<()>
Validate request against OpenAPI spec with path/query params
Sourcepub fn validate_request_with_all(
&self,
path: &str,
method: &str,
path_params: &Map<String, Value>,
query_params: &Map<String, Value>,
header_params: &Map<String, Value>,
cookie_params: &Map<String, Value>,
body: Option<&Value>,
) -> Result<()>
pub fn validate_request_with_all( &self, path: &str, method: &str, path_params: &Map<String, Value>, query_params: &Map<String, Value>, header_params: &Map<String, Value>, cookie_params: &Map<String, Value>, body: Option<&Value>, ) -> Result<()>
Validate request against OpenAPI spec with path/query/header/cookie params
Sourcepub fn get_operation(
&self,
path: &str,
method: &str,
) -> Option<OpenApiOperation>
pub fn get_operation( &self, path: &str, method: &str, ) -> Option<OpenApiOperation>
Get operation details for a route
Sourcepub fn extract_path_parameters(
&self,
path: &str,
method: &str,
) -> HashMap<String, String>
pub fn extract_path_parameters( &self, path: &str, method: &str, ) -> HashMap<String, String>
Extract path parameters from a request path by matching against known routes
Sourcepub fn convert_path_to_axum(openapi_path: &str) -> String
pub fn convert_path_to_axum(openapi_path: &str) -> String
Convert OpenAPI path to Axum-compatible path This is a utility function for converting path parameters from {param} to :param format
Sourcepub fn build_router_with_ai(
&self,
ai_generator: Option<Arc<dyn AiGenerator + Send + Sync>>,
) -> Router
pub fn build_router_with_ai( &self, ai_generator: Option<Arc<dyn AiGenerator + Send + Sync>>, ) -> Router
Build router with AI generator support
Trait Implementations§
Source§impl Clone for OpenApiRouteRegistry
impl Clone for OpenApiRouteRegistry
Source§fn clone(&self) -> OpenApiRouteRegistry
fn clone(&self) -> OpenApiRouteRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for OpenApiRouteRegistry
impl RefUnwindSafe for OpenApiRouteRegistry
impl Send for OpenApiRouteRegistry
impl Sync for OpenApiRouteRegistry
impl Unpin for OpenApiRouteRegistry
impl UnwindSafe for OpenApiRouteRegistry
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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