fkl_parser/mir/implementation/http_impl/
api_contract.rs

1use serde::Deserialize;
2use serde::Serialize;
3use crate::mir::authorization::HttpAuthorization;
4use crate::mir::implementation::validation::Validation;
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
7pub struct HttpEndpoint {
8  pub name: String,
9  pub description: String,
10  pub path: String,
11  pub auth: Option<HttpAuthorization>,
12  pub method: HttpMethod,
13  pub request: Option<Request>,
14  pub response: Option<Response>,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
18pub enum HttpMethod {
19  GET,
20  POST,
21  PUT,
22  DELETE,
23  PATCH,
24  HEAD,
25  OPTIONS,
26  TRACE,
27  CUSTOM(String),
28}
29
30impl Default for HttpMethod {
31  fn default() -> Self {
32    HttpMethod::GET
33  }
34}
35
36impl HttpMethod {
37  pub fn from(method: &str) -> Self {
38    match method.to_lowercase().as_str() {
39      "get" => HttpMethod::GET,
40      "post" => HttpMethod::POST,
41      "put" => HttpMethod::PUT,
42      "delete" => HttpMethod::DELETE,
43      "patch" => HttpMethod::PATCH,
44      "head" => HttpMethod::HEAD,
45      "options" => HttpMethod::OPTIONS,
46      "trace" => HttpMethod::TRACE,
47      _ => HttpMethod::CUSTOM(method.to_string()),
48    }
49  }
50}
51
52impl HttpEndpoint {
53  pub fn new(name: String) -> Self {
54    HttpEndpoint {
55      name,
56      ..Default::default()
57    }
58  }
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
62pub struct Request {
63  pub name: String,
64  pub pre_validate: Option<Validation>,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
68pub struct Response {
69  pub name: String,
70  pub post_validate: Option<Validation>,
71}
72