Skip to main content

nominal_api/conjure/objects/scout/webhook/template/api/
validation_result.rs

1/// Result of template validation
2#[derive(
3    Debug,
4    Clone,
5    conjure_object::serde::Serialize,
6    conjure_object::serde::Deserialize,
7    PartialEq,
8    Eq,
9    PartialOrd,
10    Ord,
11    Hash
12)]
13#[serde(crate = "conjure_object::serde")]
14#[conjure_object::private::staged_builder::staged_builder]
15#[builder(crate = conjure_object::private::staged_builder, update, inline)]
16pub struct ValidationResult {
17    #[serde(rename = "valid")]
18    valid: bool,
19    #[builder(default, into)]
20    #[serde(
21        rename = "evaluatedPayload",
22        skip_serializing_if = "Option::is_none",
23        default
24    )]
25    evaluated_payload: Option<String>,
26    #[builder(default, list(item(type = super::ValidationError)))]
27    #[serde(rename = "errors", skip_serializing_if = "Vec::is_empty", default)]
28    errors: Vec<super::ValidationError>,
29    #[builder(default, list(item(type = super::ValidationWarning)))]
30    #[serde(rename = "warnings", skip_serializing_if = "Vec::is_empty", default)]
31    warnings: Vec<super::ValidationWarning>,
32}
33impl ValidationResult {
34    /// Constructs a new instance of the type.
35    #[inline]
36    pub fn new(valid: bool) -> Self {
37        Self::builder().valid(valid).build()
38    }
39    /// Whether the template is syntactically valid and produces valid JSON
40    #[inline]
41    pub fn valid(&self) -> bool {
42        self.valid
43    }
44    /// Evaluated JSON payload if template is valid
45    #[inline]
46    pub fn evaluated_payload(&self) -> Option<&str> {
47        self.evaluated_payload.as_ref().map(|o| &**o)
48    }
49    /// List of validation errors
50    #[inline]
51    pub fn errors(&self) -> &[super::ValidationError] {
52        &*self.errors
53    }
54    /// List of validation warnings
55    #[inline]
56    pub fn warnings(&self) -> &[super::ValidationWarning] {
57        &*self.warnings
58    }
59}