vector_config/external/
no_proxy.rs

1use std::cell::RefCell;
2
3use serde_json::Value;
4
5use crate::{
6    Configurable, GenerateError, Metadata, ToValue,
7    schema::{SchemaGenerator, SchemaObject, generate_array_schema},
8};
9
10impl Configurable for no_proxy::NoProxy {
11    fn metadata() -> Metadata {
12        // Any schema that maps to a scalar type needs to be marked as transparent... and since we
13        // generate a schema equivalent to a string, we need to mark ourselves as transparent, too.
14        Metadata::with_transparent(true)
15    }
16
17    fn generate_schema(
18        generator: &RefCell<SchemaGenerator>,
19    ) -> Result<SchemaObject, GenerateError> {
20        // `NoProxy` (de)serializes itself as a vector of strings, without any constraints on the string value itself, so
21        // we just... do that.
22        generate_array_schema(&String::as_configurable_ref(), generator)
23    }
24}
25
26impl ToValue for no_proxy::NoProxy {
27    fn to_value(&self) -> Value {
28        serde_json::to_value(self).expect("Could not convert no-proxy list to JSON")
29    }
30}