fiberplane_models/
templates.rs

1use crate::names::Name;
2use base64uuid::Base64Uuid;
3#[cfg(feature = "fp-bindgen")]
4use fp_bindgen::prelude::Serializable;
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7use time::OffsetDateTime;
8use typed_builder::TypedBuilder;
9
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11#[cfg_attr(
12    feature = "fp-bindgen",
13    derive(Serializable),
14    fp(rust_module = "fiberplane_models::templates")
15)]
16#[non_exhaustive]
17#[serde(rename_all = "camelCase")]
18pub enum TemplateParameterType {
19    String,
20    Number,
21    Boolean,
22    // Note: we may add the nested types in the future.
23    // If we do, we should add it in a non-breaking way
24    // so that serialized objects created with this schema
25    // can still be deserialized.
26    Object,
27    Array,
28    /// We can only extract the parameter type from function parameters
29    /// that have default values
30    Unknown,
31}
32
33impl Default for TemplateParameterType {
34    fn default() -> Self {
35        Self::Unknown
36    }
37}
38
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TypedBuilder)]
40#[cfg_attr(
41    feature = "fp-bindgen",
42    derive(Serializable),
43    fp(rust_module = "fiberplane_models::templates")
44)]
45#[non_exhaustive]
46#[serde(rename_all = "camelCase")]
47pub struct TemplateParameter {
48    #[builder(setter(into))]
49    pub name: String,
50    #[builder(default)]
51    #[serde(rename = "type")]
52    pub ty: TemplateParameterType,
53    #[builder(default, setter(into, strip_option))]
54    pub default_value: Option<Value>,
55}
56
57#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TypedBuilder)]
58#[cfg_attr(
59    feature = "fp-bindgen",
60    derive(Serializable),
61    fp(rust_module = "fiberplane_models::templates")
62)]
63#[non_exhaustive]
64#[serde(rename_all = "camelCase")]
65pub struct Template {
66    pub id: Base64Uuid,
67    pub name: Name,
68    pub description: String,
69    pub body: String,
70    #[serde(with = "time::serde::rfc3339")]
71    pub created_at: OffsetDateTime,
72    #[serde(with = "time::serde::rfc3339")]
73    pub updated_at: OffsetDateTime,
74    pub parameters: Vec<TemplateParameter>,
75}