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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! A rendered API reference, mounted in one line and dropped by `--release`.
//!
//! ```text
//! cargo run -p kynos --example docs_ui --features docs # /docs is up
//! cargo run -p kynos --example docs_ui --features docs --release # it is not
//! ```
//!
//! Then open <http://localhost:3000/docs>, or watch it not be there:
//!
//! ```text
//! curl -sI localhost:3000/docs
//! ```
//!
//! [`document.rs`](document.rs) emits the description and serves it by hand.
//! This is the half after that: the page a human opens, and the switch that
//! keeps it off in production.
//!
//! Five things are worth noticing:
//!
//! * **One line, and no context.** Two handlers, two page constants, an enum, a
//! `Provider` context and the `Inject` that read it were what this file
//! needed to serve its own description. `Router::docs` is all of it now, and
//! this router's context is `()`. What the framework owns is the ordering:
//! the page fetches a description that has to describe the two routes serving
//! it, so the bytes cannot exist until the router is built.
//! * **The switch is a build profile, and the feature is not the switch.** Two
//! decisions in two places, on purpose. `docs` decides whether the wiring is
//! *compiled*; `debug_assertions` decides whether this deployment *mounts*
//! it. So a debug binary and a `--release` binary are genuinely two artifacts
//! publishing two documents — which is the honest reading of `--release`
//! rather than a cost, because a production binary that cannot serve a
//! reference cannot be misconfigured into serving one. Where one artifact
//! with both behaviours is what you want, the condition is an `if` over
//! anything you like, including the environment; only the line below changes.
//! * **Turning the reference on widens the published contract.** The two routes
//! become two `paths` keys, so a client generated from a docs-enabled build
//! carries two operations a `--release` build does not. The assertion below
//! states it rather than leaving it to be discovered, and
//! [`kynos::router::docs`] is where the argument for not hiding them lives.
//! * **The page is an ordinary described operation.** `/docs` appears in the
//! document saying `text/html; charset=utf-8`, with an empty schema — honest,
//! because HTML has no JSON Schema to state.
//! * **What you write here is what the page shows.** Each handler's first
//! doc-comment paragraph is that operation's summary, and each field's is the
//! property description, so the rendered reference is this file's prose.
//!
//! Kynos ships the wiring and no reference UI: each built-in page is a script
//! tag naming a CDN, so a client behind a proxy that blocks it sees an empty
//! page. An air-gapped or strict-CSP deployment vendors the bundle with
//! [`assets.rs`](assets.rs)'s embedded set and points a `Docs::custom` page at
//! it. [`kynos::router::docs`] carries the rest.
//!
//! This document stays on 3.1 — no `QUERY`, no stream response. Both renderers
//! document OpenAPI 3.1 support and neither documents 3.2, and `document.rs` is
//! where a 3.2 document lives.
use Ipv4Addr;
use ;
use ;
/// A user of the service.
/// What `/users/{id}` captures.
/// Lists users.
///
/// This paragraph is the operation's description, and the one above it is the
/// summary. Both are what the reference renders, which is the shortest argument
/// for keeping them true.
async
/// Fetches one user.
async
/// What no type can know about this API.
async