lenso_capability_http_endpoint/
lib.rs1mod authoring;
4mod extract;
5pub mod response;
6
7#[allow(unknown_lints)]
8#[allow(
9 clippy::chunks_exact_to_as_chunks,
10 clippy::manual_div_ceil,
11 clippy::manual_is_multiple_of,
12 clippy::verbose_bit_mask
13)]
14mod generated {
15 include!("generated.rs");
16}
17
18pub use authoring::{EndpointFuture, EndpointRoute, HttpEndpoint, MiddlewareOutcome};
19pub use extract::{ExtractorFuture, ExtractorRejection, FromRequest, Json, Path, Query, RequestId};
20pub use generated::*;
21pub use lenso_capability_http_endpoint_macros::endpoint;
22
23#[doc(hidden)]
24pub use authoring::{__private, validate_endpoint_routes};
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn endpoint_contract_round_trips_routes_credentials_parameters_and_bytes() {
32 let description = DescribeResponse {
33 routes: vec![DescribeResponseRoutesItem {
34 method: "GET".to_owned(),
35 openapi: Some(std::collections::BTreeMap::from([(
36 "summary".to_owned(),
37 serde_json::json!("Read an order"),
38 )])),
39 path: "/orders/{order_id}".to_owned(),
40 route_id: "orders.read".to_owned(),
41 }],
42 };
43 let wire = encode_describe_response(&description).unwrap();
44 assert_eq!(decode_describe_response(&wire).unwrap(), description);
45
46 let request = HandleRequest {
47 body: Bytes::from(vec![0, 1, 2]),
48 credential: Some(HandleRequestCredential {
49 scheme: "bearer".to_owned(),
50 value: "token".to_owned(),
51 }),
52 headers: vec![HandleRequestHeadersItem {
53 name: "accept".to_owned(),
54 value: "application/json".to_owned(),
55 }],
56 method: "GET".to_owned(),
57 path: "/orders/42".to_owned(),
58 path_parameters: vec![HandleRequestPathParametersItem {
59 name: "order_id".to_owned(),
60 value: "42".to_owned(),
61 }],
62 query: Some("include=items".to_owned()),
63 request_id: "request-1".to_owned(),
64 route_id: "orders.read".to_owned(),
65 };
66 let wire = encode_handle_request(&request).unwrap();
67 assert!(wire.contains(r#""body":"AAEC""#));
68 assert_eq!(decode_handle_request(&wire).unwrap(), request);
69 }
70
71 #[test]
72 fn endpoint_contract_values_support_cross_lane_transfer() {
73 fn assert_send<T: Send>() {}
74
75 const { assert!(CROSS_LANE_TRANSFER) };
76 assert_send::<DescribeRequest>();
77 assert_send::<DescribeResponse>();
78 assert_send::<DescribeError>();
79 assert_send::<HandleRequest>();
80 assert_send::<HandleResponse>();
81 assert_send::<HandleError>();
82 }
83}