Skip to main content

fiberplane_models/providers/schema/
config_schema.rs

1use super::fields::*;
2#[cfg(feature = "fp-bindgen")]
3use fp_bindgen::prelude::Serializable;
4use serde::{Deserialize, Serialize};
5
6/// Defines the fields that should be included in a provider's config.
7///
8/// Config data can be encoded as either JSON or YAML, so values must be
9/// representable in both.
10pub type ConfigSchema = Vec<ConfigField>;
11
12#[derive(Debug, Deserialize, Serialize)]
13#[cfg_attr(
14    feature = "fp-bindgen",
15    derive(Serializable),
16    fp(rust_module = "fiberplane_models::providers")
17)]
18#[non_exhaustive]
19#[serde(tag = "type", rename_all = "snake_case")]
20pub enum ConfigField {
21    Checkbox(CheckboxField),
22    Integer(IntegerField),
23    Select(SelectField),
24    Text(TextField),
25}
26
27impl From<CheckboxField> for ConfigField {
28    fn from(field: CheckboxField) -> Self {
29        Self::Checkbox(field)
30    }
31}
32
33impl From<IntegerField> for ConfigField {
34    fn from(field: IntegerField) -> Self {
35        Self::Integer(field)
36    }
37}
38
39impl From<SelectField> for ConfigField {
40    fn from(field: SelectField) -> Self {
41        Self::Select(field)
42    }
43}
44
45impl From<TextField> for ConfigField {
46    fn from(field: TextField) -> Self {
47        Self::Text(field)
48    }
49}