1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use regex::Regex;
use serde_derive::Serialize;
use crate::dsl::schema::Annotations;
use crate::dsl::schema::Schema;
pub mod deserialization;
#[derive(Clone, Debug, Serialize)]
pub enum IntegerBound {
Inclusive(i64),
Exclusive(i64),
}
#[derive(Clone, Debug)]
pub struct IntegerObjectBounds {
pub minimum: Option<IntegerBound>,
pub maximum: Option<IntegerBound>,
pub multiple_of: Option<i64>,
}
#[derive(Clone, Debug)]
pub struct ArrayObjectBounds {
pub minimum_number_of_items: Option<i64>,
pub maximum_number_of_items: Option<i64>,
pub items: Option<ArrayItemObjectBounds>,
pub unique_items: Option<ArrayUniqueItemBound>,
pub additional_items: Option<Schema>,
}
#[derive(Clone, Debug)]
pub enum ArrayUniqueItemBound {
All,
Specific(Vec<String>),
}
#[derive(Clone, Debug)]
pub enum ArrayItemObjectBounds {
AllItems(Box<Schema>),
RespectiveItems(Vec<Schema>),
}
impl IntegerBound {
pub fn inner(&self) -> &i64 {
match self {
IntegerBound::Exclusive(value) => value,
IntegerBound::Inclusive(value) => value,
}
}
}
#[derive(Clone, Debug)]
pub struct StringLength {
pub minimum: Option<i64>,
pub maximum: Option<i64>,
}
#[derive(Clone, Debug)]
pub enum StringObjectBounds {
PossibleValues(Vec<EnumerationValue>),
Pattern(Regex),
Length(StringLength),
}
#[derive(Clone, Debug)]
pub enum BooleanObjectBounds {
DefaultValue(bool),
}
#[derive(Clone, Debug)]
pub struct EnumerationValue {
pub annotations: Annotations,
pub value: String,
}
impl From<&str> for EnumerationValue {
fn from(value: &str) -> Self {
let value = value.to_string();
let annotations = Annotations {
title: Some(value.clone()),
help: None,
warning: None,
description: None,
};
EnumerationValue {
value: value.clone(),
annotations,
}
}
}