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
//! Documented re-exports of [`swaggapi_macro`]
/// Turns a function into a documented api handler
///
/// Unlike `#[handler]` it uses the http method `DELETE`,
/// for everything else please refer to [``#[handler]``](handler)
pub use delete;
/// Turns a function into a documented api handler
///
/// Unlike `#[handler]` it uses the http method `GET`,
/// for everything else please refer to [``#[handler]``](handler)
pub use get;
/// Turns a function into a documented api handler
///
/// ```rust
/// /// The first line is a `summary` available in openapi
/// ///
/// /// The entire docstring is available as `description` in openapi
/// #[swaggapi::handler(Get, "/")]
/// async fn index() -> &'static str {
/// "Hello World"
/// }
///
/// /// Deletes the entire application's state
/// ///
/// /// This endpoint is very dangerous and can only be used by admins.
/// #[swaggapi::delete("/deleteAll", tags("admin", "dangerous"))]
/// async fn delete_all() -> () {
/// // ...
/// }
/// ```
///
/// ## Arguments
/// - `method`: The HTTP method this handler should respond to
/// - **required**
/// - one of `Get`, `Post,` `Put`, `Delete`, `Head`, `Options`, `Patch`, `Trace`, for example `method = Get`
///
/// - `path`: The HTTP url this handler should respond on
///
/// Note, the [`ApiContext`](crate::ApiContext) can be used to apply a common prefix to a set of handlers.
/// - **required**
/// - a string literal, for example `path = "/"`
///
/// - `tags`: A list of tags, mostly used to group handlers
///
/// Read the [OpenAPI specification](https://swagger.io/specification/v3/) for the full details
/// - optional
/// - list of string literal, for example `tags("foo", "bar)`
///
/// ## Positional arguments
/// Since `method` and `path` are required, they can alternatively be passed as positional arguments:
/// - `#[handler(Get, "/")]`
/// - `#[handler(Get, path = "/")]`
/// - `#[handler("/", method = Get)]`
///
/// ## Variants
/// The first argument `method` can be replaced with the usage of one specialized variant of `#[handler]`:
/// - [`#[get(...)]`](get) is equivalent to `#[handler(Get, ...)]`
/// - [`#[post(...)]`](post) is equivalent to `#[handler(Post, ...)]`
/// - [`#[put(...)]`](put) is equivalent to `#[handler(Put, ...)]`
/// - [`#[delete(...)]`](delete) is equivalent to `#[handler(Delete, ...)]`
/// - [`#[head(...)]`](head) is equivalent to `#[handler(Head, ...)]`
/// - [`#[options(...)]`](options) is equivalent to `#[handler(Options, ...)]`
/// - [`#[patch(...)]`](patch) is equivalent to `#[handler(Patch, ...)]`
/// - [`#[trace(...)]`](trace) is equivalent to `#[handler(Trace, ...)]`
pub use handler;
/// Turns a function into a documented api handler
///
/// Unlike `#[handler]` it uses the http method `HEAD`,
/// for everything else please refer to [``#[handler]``](handler)
pub use head;
/// Turns a function into a documented api handler
///
/// Unlike `#[handler]` it uses the http method `OPTIONS`,
/// for everything else please refer to [``#[handler]``](handler)
pub use options;
/// Turns a function into a documented api handler
///
/// Unlike `#[handler]` it uses the http method `PATCH`,
/// for everything else please refer to [``#[handler]``](handler)
pub use patch;
/// Turns a function into a documented api handler
///
/// Unlike `#[handler]` it uses the http method `POST`,
/// for everything else please refer to [``#[handler]``](handler)
pub use post;
/// Turns a function into a documented api handler
///
/// Unlike `#[handler]` it uses the http method `PUT`,
/// for everything else please refer to [``#[handler]``](handler)
pub use put;
/// Turns a function into a documented api handler
///
/// Unlike `#[handler]` it uses the http method `TRACE`,
/// for everything else please refer to [``#[handler]``](handler)
pub use trace;
/// Derives [`SwaggapiPage`](trait@crate::SwaggapiPage) for a unit struct
///
/// ```rust
/// # use swaggapi_macro::SwaggapiPage;
/// #[derive(SwaggapiPage)]
/// #[page(title = "My custom subset of api endpoints")]
/// struct MyCustomApiPAge;
/// ```
///
/// ## Arguments
/// are passed through the helper `#[page(...)]`.
///
/// All arguments are of shape `key = "value"`
/// where the list of keys and their description
/// can be taken from [`SwaggapiPageBuilder`](crate::SwaggapiPageBuilder)'s methods.
///
/// ### Noteworthy differences from the builder:
/// - `filename` will default to the struct's identifier (followed by `.json`)
pub use SwaggapiPage;