vos_core/schema/
mod.rs

1use std::{
2    cmp::Ordering,
3    collections::{BTreeMap, BTreeSet},
4    convert::Infallible,
5    fmt::{Display, Formatter},
6    str::FromStr,
7};
8use vos_error::for_3rd::{Url, Version};
9use indexmap::IndexMap;
10use serde::{Deserialize, Serialize};
11use vos_error::{for_3rd::EmailAddress, VosResult};
12use crate::*;
13
14pub mod authors;
15pub mod document;
16pub mod edition;
17pub mod endpoint;
18pub mod environment;
19pub mod license;
20pub mod objects;
21use vos_error::VosError;
22#[derive(Clone, Debug, Serialize, Deserialize)]
23pub struct Project {
24    pub kind: ProjectKind,
25    pub license: ProjectLicense,
26    pub edition: Version ,
27    pub version: Version,
28    pub authors: BTreeSet<ProjectAuthor>,
29    pub description: Document,
30    pub environments: Vec<Environment>,
31    pub endpoints: BTreeMap<String, Endpoint>,
32    pub extra: BTreeMap<String, Object>,
33}
34
35impl Default for Project {
36    fn default() -> Self {
37        Self {
38            kind: Default::default(),
39            license: Default::default(),
40            edition: Version {
41                major: 2020,
42                minor: 0,
43                patch: 0,
44                pre: Default::default(),
45                build: Default::default()
46            },
47            version: Version {
48                major: 0,
49                minor: 0,
50                patch: 0,
51                pre: Default::default(),
52                build: Default::default()
53            },
54            authors: Default::default(),
55            description: Default::default(),
56            environments: vec![],
57            endpoints: Default::default(),
58            extra: Default::default()
59        }
60    }
61}
62
63#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
64pub enum ProjectKind {
65    Server,
66    Client,
67    Library,
68}
69
70impl Default for ProjectKind {
71    fn default() -> Self {
72        Self::Library
73    }
74}
75
76#[derive(Clone, Debug, Default, Serialize, Deserialize)]
77pub struct Module {
78    schemas: IndexMap<String, Schema>,
79    objects: IndexMap<String, Object>,
80}
81
82#[derive(Clone, Debug, Serialize, Deserialize)]
83#[serde(tag = "type")]
84pub enum Schema {
85    String(StringConstraint),
86    Integer(IntegerConstraint),
87    Decimal(DecimalConstraint),
88    List(ListConstraint),
89    Dict(DictConstraint),
90}
91
92impl Project {
93    #[inline]
94    pub fn extra<K, V>(&mut self, key: K, value: V) -> Option<Object>
95    where
96        K: Into<String>,
97        V: Into<Object>,
98    {
99        self.extra.insert(key.into(), value.into())
100    }
101    #[inline]
102    pub fn document(&mut self, document: &str) {
103        self.description.push(document)
104    }
105}