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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use schemars::JsonSchema;
use serde::Serialize;
use serde_json::Value;

use crate::apipath::ApiPath;
use crate::oasgen::Oas3Builder;
use crate::okapi3::{Map, Operation, OperationInfo, Parameter, RefOr, Responses};
use crate::xtests::Test;

impl Oas3Builder {
    pub fn delete<
        I: JsonSchema + Serialize,
        O: JsonSchema + Serialize,
        E: JsonSchema + Serialize,
    >(
        &mut self,
        web_path: &ApiPath,
        document_name: String,
        operation_description: Option<String>,
    ) {
        self.delete_with_tests::<I, O, E>(web_path, document_name, operation_description, &[])
    }

    pub fn delete_with_tests<
        I: JsonSchema + Serialize,
        O: JsonSchema + Serialize,
        E: JsonSchema + Serialize,
    >(
        &mut self,
        web_path: &ApiPath,
        document_name: String,
        operation_description: Option<String>,
        tests: &[Test],
    ) {
        let operation_id = format!("delete{}", document_name);
        let method = http::Method::DELETE;

        let mut resps = Responses::default();

        let status = "202".to_owned();
        let resp = self.create_response::<O>(document_name);
        resps.responses.insert(status, resp.into());

        self.add_error_responses::<E>(&mut resps);

        let request_body = self.create_request_body::<I>();

        let mut parameters: Vec<RefOr<Parameter>> = vec![];
        self.add_path_params(web_path.clone(), &mut parameters);

        let mut extensions: Map<String, Value> = Map::default();
        extensions.insert("x-tests".to_owned(), serde_json::to_value(tests).unwrap());

        self.generator.add_operation(OperationInfo {
            path: web_path.to_string(),
            method,
            operation: Operation {
                operation_id: Some(operation_id),
                description: operation_description,
                responses: resps,
                request_body,
                parameters,
                extensions,
                ..Operation::default()
            },
        })
    }

    pub fn delete_by_key<O: JsonSchema + Serialize, E: JsonSchema + Serialize>(
        &mut self,
        web_path: &ApiPath,
        document_name: String,
        operation_description: Option<String>,
    ) {
        self.delete_by_key_with_tests::<O, E>(web_path, document_name, operation_description, &[])
    }

    pub fn delete_by_key_with_tests<O: JsonSchema + Serialize, E: JsonSchema + Serialize>(
        &mut self,
        web_path: &ApiPath,
        document_name: String,
        operation_description: Option<String>,
        tests: &[Test],
    ) {
        let operation_id = format!("delete{}", document_name);
        let method = http::Method::DELETE;

        let mut resps = Responses::default();

        let status = "202".to_owned();
        let resp = self.create_response::<O>(document_name);
        resps.responses.insert(status, resp.into());

        self.add_error_responses::<E>(&mut resps);

        let mut parameters: Vec<RefOr<Parameter>> = vec![];
        self.add_path_params(web_path.clone(), &mut parameters);

        let mut extensions: Map<String, Value> = Map::default();
        extensions.insert("x-tests".to_owned(), serde_json::to_value(tests).unwrap());

        self.generator.add_operation(OperationInfo {
            path: web_path.to_string(),
            method,
            operation: Operation {
                operation_id: Some(operation_id),
                description: operation_description,
                responses: resps,
                request_body: None,
                parameters,
                extensions,
                ..Operation::default()
            },
        })
    }
}