vector_config/
http.rs

1use std::cell::RefCell;
2
3use http::StatusCode;
4use serde_json::Value;
5use vector_config_common::{attributes::CustomAttribute, constants};
6
7use crate::{
8    Configurable, GenerateError, Metadata, ToValue,
9    num::NumberClass,
10    schema::{SchemaGenerator, SchemaObject, generate_number_schema},
11};
12
13impl ToValue for StatusCode {
14    fn to_value(&self) -> Value {
15        serde_json::to_value(self.as_u16()).expect("Could not convert HTTP status code to JSON")
16    }
17}
18
19impl Configurable for StatusCode {
20    fn referenceable_name() -> Option<&'static str> {
21        Some("http::StatusCode")
22    }
23
24    fn is_optional() -> bool {
25        true
26    }
27
28    fn metadata() -> Metadata {
29        let mut metadata = Metadata::default();
30        metadata.set_description("HTTP response status code");
31        metadata.add_custom_attribute(CustomAttribute::kv(
32            constants::DOCS_META_NUMERIC_TYPE,
33            NumberClass::Unsigned,
34        ));
35        metadata
36    }
37
38    fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> {
39        Ok(generate_number_schema::<u16>())
40    }
41}