Skip to main content

nautobot_openapi/models/
custom_field.rs

1/*
2 * API Documentation
3 *
4 * Source of truth and network automation platform
5 *
6 * The version of the OpenAPI document: 3.1.0 (3.1)
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11/// CustomField : Extends the built-in ModelSerializer to enforce calling full_clean() on a copy of the associated instance during validation. (DRF does not do this by default; see <https://github.com/encode/django-rest-framework/issues/3144>)
12
13#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
14pub struct CustomField {
15    #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
16    pub id: Option<uuid::Uuid>,
17    #[serde(rename = "object_type", skip_serializing_if = "Option::is_none")]
18    pub object_type: Option<String>,
19    /// Human friendly display value
20    #[serde(rename = "display", skip_serializing_if = "Option::is_none")]
21    pub display: Option<String>,
22    #[serde(rename = "url", skip_serializing_if = "Option::is_none")]
23    pub url: Option<String>,
24    #[serde(rename = "natural_slug", skip_serializing_if = "Option::is_none")]
25    pub natural_slug: Option<String>,
26    #[serde(rename = "content_types")]
27    pub content_types: Vec<String>,
28    #[serde(rename = "type")]
29    pub r#type: Box<crate::models::CustomFieldType>,
30    #[serde(rename = "filter_logic", skip_serializing_if = "Option::is_none")]
31    pub filter_logic: Option<Box<crate::models::CustomFieldFilterLogic>>,
32    #[serde(rename = "label")]
33    pub label: String,
34    /// Human-readable grouping that this custom field belongs to.
35    #[serde(rename = "grouping", skip_serializing_if = "Option::is_none")]
36    pub grouping: Option<String>,
37    /// Internal field name. Please use underscores rather than dashes in this key.
38    #[serde(rename = "key", skip_serializing_if = "Option::is_none")]
39    pub key: Option<String>,
40    /// A helpful description for this field.
41    #[serde(rename = "description", skip_serializing_if = "Option::is_none")]
42    pub description: Option<String>,
43    /// If true, this field is required when creating new objects or editing an existing object.
44    #[serde(rename = "required", skip_serializing_if = "Option::is_none")]
45    pub required: Option<bool>,
46    /// Default value for the field (must be a JSON value). Encapsulate strings with double quotes (e.g. \"Foo\").
47    #[serde(
48        rename = "default",
49        default,
50        with = "::serde_with::rust::double_option",
51        skip_serializing_if = "Option::is_none"
52    )]
53    pub default: Option<Option<serde_json::Value>>,
54    /// Fields with higher weights appear lower in a form.
55    #[serde(rename = "weight", skip_serializing_if = "Option::is_none")]
56    pub weight: Option<i32>,
57    /// Minimum allowed value (for numeric fields) or length (for text fields).
58    #[serde(
59        rename = "validation_minimum",
60        default,
61        with = "::serde_with::rust::double_option",
62        skip_serializing_if = "Option::is_none"
63    )]
64    pub validation_minimum: Option<Option<i64>>,
65    /// Maximum allowed value (for numeric fields) or length (for text fields).
66    #[serde(
67        rename = "validation_maximum",
68        default,
69        with = "::serde_with::rust::double_option",
70        skip_serializing_if = "Option::is_none"
71    )]
72    pub validation_maximum: Option<Option<i64>>,
73    /// Regular expression to enforce on text field values. Use ^ and $ to force matching of entire string. For example, <code>^[A-Z]{3}$</code> will limit values to exactly three uppercase letters. Regular expression on select and multi-select will be applied at <code>Custom Field Choices</code> definition.
74    #[serde(rename = "validation_regex", skip_serializing_if = "Option::is_none")]
75    pub validation_regex: Option<String>,
76    /// Hide this field from the object's primary information tab. It will appear in the \"Advanced\" tab instead.
77    #[serde(rename = "advanced_ui", skip_serializing_if = "Option::is_none")]
78    pub advanced_ui: Option<bool>,
79    /// A JSON-encoded dictionary of filter parameters defining possible objects that can use this custom field.
80    #[serde(
81        rename = "scope_filter",
82        default,
83        with = "::serde_with::rust::double_option",
84        skip_serializing_if = "Option::is_none"
85    )]
86    pub scope_filter: Option<Option<serde_json::Value>>,
87    #[serde(
88        rename = "created",
89        default,
90        with = "::serde_with::rust::double_option",
91        skip_serializing_if = "Option::is_none"
92    )]
93    pub created: Option<Option<String>>,
94    #[serde(
95        rename = "last_updated",
96        default,
97        with = "::serde_with::rust::double_option",
98        skip_serializing_if = "Option::is_none"
99    )]
100    pub last_updated: Option<Option<String>>,
101    #[serde(rename = "notes_url", skip_serializing_if = "Option::is_none")]
102    pub notes_url: Option<String>,
103}
104
105impl CustomField {
106    /// Extends the built-in ModelSerializer to enforce calling full_clean() on a copy of the associated instance during validation. (DRF does not do this by default; see <https://github.com/encode/django-rest-framework/issues/3144>)
107    pub fn new(
108        content_types: Vec<String>,
109        r#type: crate::models::CustomFieldType,
110        label: String,
111    ) -> CustomField {
112        CustomField {
113            id: None,
114            object_type: None,
115            display: None,
116            url: None,
117            natural_slug: None,
118            content_types,
119            r#type: Box::new(r#type),
120            filter_logic: None,
121            label,
122            grouping: None,
123            key: None,
124            description: None,
125            required: None,
126            default: None,
127            weight: None,
128            validation_minimum: None,
129            validation_maximum: None,
130            validation_regex: None,
131            advanced_ui: None,
132            scope_filter: None,
133            created: None,
134            last_updated: None,
135            notes_url: None,
136        }
137    }
138}