fiberplane_models/providers/schema/fields/
file_field.rs

1#[cfg(feature = "fp-bindgen")]
2use fp_bindgen::prelude::Serializable;
3use serde::{Deserialize, Serialize};
4
5/// Defines a field that allows files to be uploaded as part of the query data.
6///
7/// Query data that includes files will be encoded using "multipart/form-data".
8#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
9#[cfg_attr(
10    feature = "fp-bindgen",
11    derive(Serializable),
12    fp(rust_module = "fiberplane_models::providers")
13)]
14#[non_exhaustive]
15#[serde(rename_all = "camelCase")]
16pub struct FileField {
17    /// Name of the field as it will be included in the encoded query or config
18    /// object.
19    pub name: String,
20
21    /// Suggested label to display along the field.
22    pub label: String,
23
24    /// Whether multiple files may be uploaded.
25    pub multiple: bool,
26
27    /// Whether a file is required.
28    pub required: bool,
29}
30
31impl FileField {
32    /// Creates a new file field with all default values.
33    pub fn new() -> Self {
34        Default::default()
35    }
36
37    /// Marks the field as allowing multiple files to be uploaded.
38    pub fn multiple(self) -> Self {
39        Self {
40            multiple: true,
41            ..self
42        }
43    }
44
45    /// Marks the field as required.
46    pub fn required(self) -> Self {
47        Self {
48            required: true,
49            ..self
50        }
51    }
52
53    pub fn with_label(self, label: &str) -> Self {
54        Self {
55            label: label.to_owned(),
56            ..self
57        }
58    }
59
60    pub fn with_name(self, name: &str) -> Self {
61        Self {
62            name: name.to_owned(),
63            ..self
64        }
65    }
66}