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
//! Model for endpoints

use super::{Attributes, Loc, RpChannel, RpPathSpec};
use linked_hash_map::LinkedHashMap;

#[derive(Debug, Clone, Serialize)]
pub enum RpHttpMethod {
    GET,
    POST,
    PUT,
    UPDATE,
    DELETE,
    PATCH,
    HEAD,
}

#[derive(Debug, Clone, Serialize, Default)]
pub struct RpEndpointHttp {
    /// Path specification.
    pub path: Option<RpPathSpec>,
    /// Argument that is the body of the request.
    pub body: Option<String>,
    /// HTTP method.
    pub method: Option<RpHttpMethod>,
}

#[derive(Debug, Clone, Serialize)]
pub struct RpEndpoint {
    /// Name of the endpoint. Guaranteed to be unique.
    pub id: Loc<String>,
    /// Name of the endpoint. This is the name which is being sent over the wire.
    pub name: String,
    /// Comments for documentation.
    pub comment: Vec<String>,
    /// Attributes associated with the endpoint.
    pub attributes: Attributes,
    /// Request type that this endpoint expects.
    pub arguments: LinkedHashMap<String, (Loc<String>, Loc<RpChannel>)>,
    /// Response type that this endpoint responds with.
    pub response: Option<Loc<RpChannel>>,
    /// HTTP configuration.
    pub http: RpEndpointHttp,
}

impl RpEndpoint {
    pub fn id_parts<F>(&self, filter: F) -> Vec<String>
    where
        F: Fn(&str) -> String,
    {
        vec![filter(self.id.as_str())]
    }

    /// Get the name of the endpoint.
    pub fn name(&self) -> &str {
        self.name.as_str()
    }
}