From 73adf2b1cf6b86f30e1c2bc5d24587e2d5f597eb Mon Sep 17 00:00:00 2001 From: Erin Power Date: Mon, 7 Feb 2022 10:03:26 +0100 Subject: [PATCH] Add matches to auto-generated docs --- Cargo.toml | 2 +- docs/src/SUMMARY.md | 5 +++-- docs/src/filters/matches.md | 6 ++++++ src/config/config_type.rs | 4 +++- src/filters/matches.rs | 12 ++++++++---- src/metadata.rs | 4 +++- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dfb88aae7f..50defcab1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ eyre = "0.6.5" stable-eyre = "0.2.2" ipnetwork = "0.18.0" futures = "0.3.17" -schemars = "0.8.8" +schemars = { version = "0.8.8", features = ["bytes"] } [target.'cfg(target_os = "linux")'.dependencies] sys-info = "0.9.0" diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index e8b919d62f..35f4502e4e 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -11,13 +11,14 @@ - [Proxy Configuration](./proxy-configuration.md) - [Filters](./filters.md) - [Capture Bytes](./filters/capture_bytes.md) - - [Concatenate Bytes](./filters/concatenate_bytes.md) - [Compress](./filters/compress.md) + - [Concatenate Bytes](./filters/concatenate_bytes.md) - [Debug](./filters/debug.md) + - [Firewall](./filters/firewall.md) - [Load Balancer](./filters/load_balancer.md) - [Local Rate Limit](./filters/local_rate_limit.md) + - [Matches](./filters/matches.md) - [Token Router](./filters/token_router.md) - - [Firewall](./filters/firewall.md) - [Writing Custom Filters](./filters/writing_custom_filters.md) - [Integrations](./integrations.md) - [Administration](./admin.md) diff --git a/docs/src/filters/matches.md b/docs/src/filters/matches.md index 0456b953b2..3b09649bdc 100644 --- a/docs/src/filters/matches.md +++ b/docs/src/filters/matches.md @@ -40,4 +40,10 @@ static: # quilkin::Builder::from(std::sync::Arc::new(config)).validate().unwrap(); ``` +### Configuration Options ([Rust Doc](../../api/quilkin/filters/matches/struct.Config.html)) + +```yaml +{{#include ../../../target/quilkin.extensions.filters.matches.v1alpha1.yaml}} +``` + View the [Matches](../../api/quilkin/filters/matches/struct.Config.html) filter documentation for more details. diff --git a/src/config/config_type.rs b/src/config/config_type.rs index db42137884..c1f5d19763 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -22,11 +22,13 @@ use crate::filters::{ConvertProtoConfigError, Error}; /// The configuration of a [`Filter`][crate::filters::Filter] from either a /// static or dynamic source. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, schemars::JsonSchema)] pub enum ConfigType { /// Static configuration from YAML. + #[schemars(with = "serde_json::Value")] Static(serde_yaml::Value), /// Dynamic configuration from Protobuf. + #[schemars(skip)] Dynamic(prost_types::Any), } diff --git a/src/filters/matches.rs b/src/filters/matches.rs index f579060f02..d07c7830e1 100644 --- a/src/filters/matches.rs +++ b/src/filters/matches.rs @@ -163,6 +163,10 @@ impl FilterFactory for MatchesFactory { NAME } + fn config_schema(&self) -> schemars::schema::RootSchema { + schemars::schema_for!(Config) + } + fn create_filter(&self, args: CreateFilterArgs) -> Result { let (config_json, config) = self .require_config(args.config)? @@ -177,7 +181,7 @@ impl FilterFactory for MatchesFactory { } /// Configuration for the [`factory`]. -#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq)] +#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq, schemars::JsonSchema)] #[serde(deny_unknown_fields)] pub struct Config { /// Configuration for [`Filter::read`]. @@ -231,7 +235,7 @@ impl TryFrom for DirectionalConfig { } /// Configuration for a specific direction. -#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq)] +#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq, schemars::JsonSchema)] pub struct DirectionalConfig { /// The key for the metadata to compare against. #[serde(rename = "metadataKey")] @@ -245,7 +249,7 @@ pub struct DirectionalConfig { /// A specific match branch. The filter is run when `value` matches the value /// defined in `metadata_key`. -#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq)] +#[derive(Debug, serde::Deserialize, serde::Serialize, PartialEq, schemars::JsonSchema)] pub struct Branch { /// The value to compare against the dynamic metadata. pub value: crate::metadata::Value, @@ -273,7 +277,7 @@ impl TryFrom for Branch { } /// The behaviour when the none of branches match. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, schemars::JsonSchema)] pub enum Fallthrough { /// The packet will be passed onto the next filter. Pass, diff --git a/src/metadata.rs b/src/metadata.rs index c261a0a083..d235f40735 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -23,7 +23,9 @@ pub type DynamicMetadata = HashMap, Value>; pub const KEY: &str = "quilkin.dev"; -#[derive(Clone, Debug, PartialOrd, serde::Serialize, serde::Deserialize, Eq, Ord)] +#[derive( + Clone, Debug, PartialOrd, serde::Serialize, serde::Deserialize, Eq, Ord, schemars::JsonSchema, +)] #[serde(untagged)] pub enum Value { Bool(bool),