fiberplane_models/providers/schema/fields/
label_field.rs

1#[cfg(feature = "fp-bindgen")]
2use fp_bindgen::prelude::Serializable;
3use serde::{Deserialize, Serialize};
4
5/// Defines a field that allows labels to be selected.
6///
7/// For JSON/YAML encoding, the value will be represented as a string or an
8/// array of strings, depending on the value of the `multiple` field. In the
9/// case of "application/x-www-form-urlencoded", the value is always a single
10/// string and multiple labels will be space-separated.
11#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
12#[cfg_attr(
13    feature = "fp-bindgen",
14    derive(Serializable),
15    fp(rust_module = "fiberplane_models::providers")
16)]
17#[non_exhaustive]
18#[serde(rename_all = "camelCase")]
19pub struct LabelField {
20    /// Name of the field as it will be included in the encoded query or config
21    /// object.
22    pub name: String,
23
24    /// Suggested label to display along the field (not to be confused with
25    /// labels to be selected).
26    pub label: String,
27
28    /// Whether multiple labels may be selected.
29    pub multiple: bool,
30
31    /// Suggested placeholder to display when there is no value.
32    pub placeholder: String,
33
34    /// Whether a value is required.
35    pub required: bool,
36}
37
38impl LabelField {
39    /// Creates a new label field with all default values.
40    pub fn new() -> Self {
41        Default::default()
42    }
43
44    /// Marks the field as allowing multiple labels to be selected.
45    pub fn multiple(self) -> Self {
46        Self {
47            multiple: true,
48            ..self
49        }
50    }
51
52    /// Marks the field as required.
53    pub fn required(self) -> Self {
54        Self {
55            required: true,
56            ..self
57        }
58    }
59
60    pub fn with_label(self, label: &str) -> Self {
61        Self {
62            label: label.to_owned(),
63            ..self
64        }
65    }
66
67    pub fn with_name(self, name: &str) -> Self {
68        Self {
69            name: name.to_owned(),
70            ..self
71        }
72    }
73
74    pub fn with_placeholder(self, placeholder: &str) -> Self {
75        Self {
76            placeholder: placeholder.to_owned(),
77            ..self
78        }
79    }
80}