dev_scope/models/v1alpha/
known_error.rs

1use crate::models::core::ModelMetadata;
2use crate::models::v1alpha::V1AlphaApiVersion;
3use crate::models::{HelpMetadata, InternalScopeModel, ScopeModel};
4use derive_builder::Builder;
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8/// Definition of the known error
9#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
10#[serde(rename_all = "camelCase")]
11#[schemars(deny_unknown_fields)]
12pub struct KnownErrorSpec {
13    /// Text that the user can use to fix the issue
14    pub help: String,
15
16    /// A Regex used to determine if the line is an error.
17    pub pattern: String,
18}
19
20#[derive(Serialize, Deserialize, Debug, strum::Display, Clone, PartialEq, JsonSchema)]
21pub enum KnownErrorKind {
22    #[strum(serialize = "ScopeKnownError")]
23    ScopeKnownError,
24}
25
26/// Resource used to define a `ScopeKnownError`.
27/// A known error is a specific error that a user may run into.
28#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Builder, JsonSchema)]
29#[builder(setter(into))]
30#[serde(rename_all = "camelCase")]
31#[schemars(deny_unknown_fields)]
32pub struct V1AlphaKnownError {
33    /// API version of the resource
34    pub api_version: V1AlphaApiVersion,
35    /// The type of resource.
36    pub kind: KnownErrorKind,
37    /// Standard set of options including name, description for the resource.
38    /// Together `kind` and `metadata.name` are required to be unique. If there are duplicate, the
39    /// resources "closest" to the execution dir will take precedence.
40    pub metadata: ModelMetadata,
41    /// Options for the resource.
42    pub spec: KnownErrorSpec,
43}
44
45impl HelpMetadata for V1AlphaKnownError {
46    fn metadata(&self) -> &ModelMetadata {
47        &self.metadata
48    }
49
50    fn full_name(&self) -> String {
51        format!("{}/{}", self.kind(), self.name())
52    }
53}
54
55impl ScopeModel<KnownErrorSpec> for V1AlphaKnownError {
56    fn api_version(&self) -> String {
57        Self::int_api_version()
58    }
59
60    fn kind(&self) -> String {
61        Self::int_kind()
62    }
63
64    fn spec(&self) -> &KnownErrorSpec {
65        &self.spec
66    }
67}
68
69impl InternalScopeModel<KnownErrorSpec, V1AlphaKnownError> for V1AlphaKnownError {
70    fn int_api_version() -> String {
71        V1AlphaApiVersion::ScopeV1Alpha.to_string()
72    }
73
74    fn int_kind() -> String {
75        KnownErrorKind::ScopeKnownError.to_string()
76    }
77
78    #[cfg(test)]
79    fn examples() -> Vec<String> {
80        vec!["v1alpha/KnownError.yaml".to_string()]
81    }
82}