endpoint_libs/model/
endpoint.rs1use crate::model::{Field, Type};
2use serde::*;
3
4#[derive(Debug, Serialize, Deserialize, Default)]
6pub struct EndpointSchema {
7 pub name: String,
9
10 pub code: u32,
12
13 pub parameters: Vec<Field>,
15
16 pub returns: Vec<Field>,
18
19 #[serde(default)]
21 pub stream_response: Option<Type>,
22
23 #[serde(default)]
25 pub description: String,
26
27 #[serde(default)]
29 pub json_schema: serde_json::Value,
30
31 pub roles: Vec<String>,
33}
34
35impl EndpointSchema {
36 pub fn new(
38 name: impl Into<String>,
39 code: u32,
40 parameters: Vec<Field>,
41 returns: Vec<Field>,
42 ) -> Self {
43 Self {
44 name: name.into(),
45 code,
46 parameters,
47 returns,
48 stream_response: None,
49 description: "".to_string(),
50 json_schema: Default::default(),
51 roles: Vec::new(),
52 }
53 }
54
55 pub fn with_stream_response_type(mut self, stream_response: Type) -> Self {
57 self.stream_response = Some(stream_response);
58 self
59 }
60
61 pub fn with_description(mut self, desc: impl Into<String>) -> Self {
63 self.description = desc.into();
64 self
65 }
66
67 pub fn with_roles(mut self, roles: Vec<String>) -> Self {
69 self.roles = roles;
70 self
71 }
72}