pub struct ResponseModelConfig {
pub include: Option<HashSet<String>>,
pub exclude: Option<HashSet<String>>,
pub by_alias: bool,
pub exclude_unset: bool,
pub exclude_defaults: bool,
pub exclude_none: bool,
}Expand description
Configuration for response model serialization.
This provides FastAPI-compatible options for controlling how response data is serialized and validated before sending to clients.
§Examples
use fastapi_core::ResponseModelConfig;
use std::collections::HashSet;
// Only include specific fields
let config = ResponseModelConfig::new()
.include(["id", "name", "email"].into_iter().map(String::from).collect());
// Exclude sensitive fields
let config = ResponseModelConfig::new()
.exclude(["password", "internal_notes"].into_iter().map(String::from).collect());
// Use field aliases in output
let config = ResponseModelConfig::new()
.by_alias(true);Fields§
§include: Option<HashSet<String>>Only include these fields in the response. If None, all fields are included (subject to exclude).
exclude: Option<HashSet<String>>Exclude these fields from the response.
by_alias: boolUse serde aliases in output field names.
exclude_unset: boolExclude fields that were not explicitly set. Requires the type to track which fields were set.
exclude_defaults: boolExclude fields that have their default values.
exclude_none: boolExclude fields with None values.
Implementations§
Source§impl ResponseModelConfig
impl ResponseModelConfig
Sourcepub fn by_alias(self, value: bool) -> Self
pub fn by_alias(self, value: bool) -> Self
Use serde aliases in output.
Note: This option is stored but not yet implemented in filter_json.
Full implementation requires compile-time serde attribute introspection.
Sourcepub fn exclude_unset(self, value: bool) -> Self
pub fn exclude_unset(self, value: bool) -> Self
Exclude unset fields.
Note: This option is stored but not yet implemented in filter_json.
Full implementation requires the type to track which fields were explicitly set.
Sourcepub fn exclude_defaults(self, value: bool) -> Self
pub fn exclude_defaults(self, value: bool) -> Self
Exclude fields with default values.
Note: This option is stored but not yet implemented in filter_json.
Full implementation requires compile-time default value comparison.
Sourcepub fn exclude_none(self, value: bool) -> Self
pub fn exclude_none(self, value: bool) -> Self
Exclude fields with None values.
Sourcepub fn has_filtering(&self) -> bool
pub fn has_filtering(&self) -> bool
Check if any filtering is configured.
Sourcepub fn filter_json(&self, value: Value) -> Value
pub fn filter_json(&self, value: Value) -> Value
Apply filtering to a JSON value.
This filters the JSON according to the configuration:
- Applies include whitelist
- Applies exclude blacklist
- Removes None values if exclude_none is set
Trait Implementations§
Source§impl Clone for ResponseModelConfig
impl Clone for ResponseModelConfig
Source§fn clone(&self) -> ResponseModelConfig
fn clone(&self) -> ResponseModelConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more