Skip to main content

ParameterValidator

Struct ParameterValidator 

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

Parameter validator that uses JSON Schema

Implementations§

Source§

impl ParameterValidator

Source

pub fn new(schema: Value) -> Result<Self, String>

Create a new parameter validator from a JSON Schema

The schema should describe all parameters with their types and constraints. Each property MUST have a “source” field indicating where the parameter comes from.

§Errors

Returns an error if the schema is invalid or malformed.

Source

pub fn requires_headers(&self) -> bool

Whether this validator needs access to request headers.

Source

pub fn requires_cookies(&self) -> bool

Whether this validator needs access to request cookies.

Source

pub fn has_params(&self) -> bool

Whether the validator has any parameter definitions.

Source

pub fn schema(&self) -> &Value

Get the underlying JSON Schema

Source

pub fn validate_and_extract( &self, query_params: &Value, raw_query_params: &HashMap<String, Vec<String>>, path_params: &HashMap<String, String>, headers: &HashMap<String, String>, cookies: &HashMap<String, String>, ) -> Result<Value, ValidationError>

Validate and extract parameters from the request

This builds a JSON object from query/path/header/cookie params and validates it. It performs type coercion (e.g., “123” → 123) based on the schema.

Returns the validated JSON object that can be directly converted to Python kwargs.

§Errors

Returns a validation error if parameter validation fails.

Trait Implementations§

Source§

impl Clone for ParameterValidator

Source§

fn clone(&self) -> ParameterValidator

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ParameterValidator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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, 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> 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.