Skip to main content

OpenApiRouteRegistry

Struct OpenApiRouteRegistry 

Source
pub struct OpenApiRouteRegistry { /* private fields */ }
Expand description

OpenAPI route registry that manages generated routes

Implementations§

Source§

impl OpenApiRouteRegistry

Source

pub fn new(spec: OpenApiSpec) -> Self

Create a new registry from an OpenAPI spec

Source

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)
Source

pub fn new_with_env_and_persona( spec: OpenApiSpec, persona: Option<Arc<Persona>>, ) -> Self

Create a new registry from an OpenAPI spec with environment-based validation options and persona

Source

pub fn new_with_options(spec: OpenApiSpec, options: ValidationOptions) -> Self

Construct with explicit options

Source

pub fn new_with_options_and_persona( spec: OpenApiSpec, options: ValidationOptions, persona: Option<Arc<Persona>>, ) -> Self

Construct with explicit options and persona

Source

pub fn with_custom_fixture_loader( self, loader: Arc<CustomFixtureLoader>, ) -> Self

Set custom fixture loader

Source

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.

Source

pub fn routes(&self) -> &[OpenApiRoute]

Get all routes

Source

pub fn spec(&self) -> &OpenApiSpec

Get the OpenAPI specification

Source

pub fn build_router(self) -> Router

Build an Axum router from the OpenAPI spec (simplified)

Source

pub fn build_router_with_latency( self, latency_injector: LatencyInjector, ) -> Router

Build an Axum router from the OpenAPI spec with latency injection support

Source

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

Source

pub fn build_router_with_injectors_and_overrides( self, latency_injector: LatencyInjector, failure_injector: Option<FailureInjector>, response_rewriter: Option<Arc<dyn ResponseRewriter>>, overrides_enabled: bool, ) -> Router

Build an Axum router from the OpenAPI spec with latency, failure injection, and a response-rewriter hook (typically wrapping core’s Overrides + templating::expand_tokens).

Source

pub fn get_route(&self, path: &str, method: &str) -> Option<&OpenApiRoute>

Get route by path and method

Source

pub fn get_routes_for_path(&self, path: &str) -> Vec<&OpenApiRoute>

Get all routes for a specific path

Source

pub fn validate_request( &self, path: &str, method: &str, body: Option<&Value>, ) -> Result<()>

Validate request against OpenAPI spec (legacy body-only)

Source

pub fn check_request_content_type( &self, path: &str, method: &str, actual_content_type: Option<&str>, ) -> Result<(), String>

Round 28 — Srikanth’s content-type-mismatch finding on 0.3.171: the bench-side probe was correctly sending Content-Type: application/xml against a JSON-only endpoint, but mockforge’s server-side conformance validator was accepting it because the existing path checked the BODY against the JSON schema directly (ignoring the actual Content-Type header). This method gives the route handler a way to flag Content-Type mismatches before the body validation runs.

Returns Err(message) when the operation’s request body declares one or more content keys AND the actual Content-Type doesn’t match any of them; Ok(()) otherwise (no requestBody declared, no Content-Type sent, or a match found). The comparison is type/subtype only (parameters like ; charset=... and ; boundary=... are stripped).

Source

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

Source

pub fn run_validation_with_recording( &self, path_template: &str, method: &str, path_params: &Map<String, Value>, query_params: &Map<String, Value>, header_map: &Map<String, Value>, cookie_map: &Map<String, Value>, body: Option<&Value>, ) -> Result<(), (u16, Value)>

Issue #79 round 13 — run the standard request-validation bookend (validate → build error payload → record to the conformance ring buffer) and return Ok(()) if validation passed, or Err((status_code, payload)) if it failed. Centralises the logic that previously lived inline at build_router_with_context (line ~686) so the MockAI and AI handlers can share it instead of silently bypassing validation.

Callers should short-circuit with the returned status + payload on Err; the violation has already been recorded to mockforge_foundation::conformance_violations by the time this function returns.

Source

pub fn run_validation_with_recording_ex( &self, path_template: &str, method: &str, path_params: &Map<String, Value>, query_params: &Map<String, Value>, header_map: &Map<String, Value>, cookie_map: &Map<String, Value>, body: Option<&Value>, body_present: bool, ) -> Result<(), (u16, Value)>

Same as Self::run_validation_with_recording, but with an explicit body-presence flag so a non-JSON body isn’t mistaken for a missing one (issue #925).

Source

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.

body is the request body parsed as JSON, or None when it was absent OR could not be parsed as JSON. Because those two cases are indistinguishable here, prefer Self::validate_request_with_all_ex, which takes an explicit body-presence flag (see issue #925).

Source

pub fn validate_request_with_all_ex( &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>, body_present: bool, ) -> Result<()>

Same as Self::validate_request_with_all, but the caller states explicitly whether a request body was present on the wire.

Issue #925 — the handlers used to derive body presence from serde_json::from_slice(&bytes).ok(), so ANY non-JSON body (application/octet-stream file uploads, application/xml, application/x-www-form-urlencoded, raw text) collapsed to None and the validator reported body: Request body is required but not provided. Every PUT carrying a file body 400’d while JSON POSTs passed, which is why the bug looked method-specific. body_present lets us tell “absent” apart from “present but not JSON”.

Source

pub fn paths(&self) -> Vec<String>

Get all paths defined in the spec

Source

pub fn methods(&self) -> Vec<String>

Get all HTTP methods supported

Source

pub fn get_operation( &self, path: &str, method: &str, ) -> Option<OpenApiOperation>

Get operation details for a route

Source

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

Source

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

Source

pub fn build_router_with_ai( &self, ai_generator: Option<Arc<dyn AiGenerator + Send + Sync>>, ) -> Router

Build router with AI generator support

Source

pub fn build_router_with_mockai( &self, mockai: Option<Arc<RwLock<dyn MockAiBehavior + Send + Sync>>>, ) -> Router

Build router with MockAI (Behavioral Mock Intelligence) support

This method integrates MockAI for intelligent, context-aware response generation, mutation detection, validation error generation, and pagination intelligence.

§Arguments
  • mockai - Optional MockAI instance for intelligent behavior
§Returns

Axum router with MockAI-powered response generation

Trait Implementations§

Source§

impl Clone for OpenApiRouteRegistry

Source§

fn clone(&self) -> OpenApiRouteRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more