openapi_lambda/
lib.rs

1#![doc = include_str!("../README.md")]
2#![warn(missing_docs)]
3
4use aws_lambda_events::apigw::ApiGatewayProxyResponse;
5
6// These are documented public exports since either the generated `Api` traits or the `Middleware`
7// depends on them.
8pub use async_trait;
9pub use aws_lambda_events::apigw::ApiGatewayProxyRequestContext;
10pub use aws_lambda_events::encodings::Body;
11pub use aws_lambda_events::http::{HeaderMap, HeaderName};
12pub use http::{Response, StatusCode};
13pub use lambda_runtime::{Context as LambdaContext, LambdaEvent};
14
15/// Error handling.
16pub mod error;
17
18pub use error::EventError;
19
20mod middleware;
21
22pub use middleware::{Middleware, UnauthenticatedMiddleware};
23
24/// Request/response model-related types and re-exports.
25pub mod models;
26
27mod runtime;
28
29pub use runtime::run_lambda;
30
31/// HTTP response.
32pub type HttpResponse = Response<Body>;
33
34/// Serialize an [`HttpResponse`] as an [`ApiGatewayProxyResponse`].
35pub fn http_response_to_apigw(response: HttpResponse) -> ApiGatewayProxyResponse {
36  let (parts, body) = response.into_parts();
37  ApiGatewayProxyResponse {
38    status_code: parts.status.as_u16() as i64,
39    headers: Default::default(),
40    multi_value_headers: parts.headers,
41    body: Some(body),
42    is_base64_encoded: false,
43  }
44}
45
46// Used by generated code. Not part of the public API. Not bound by SemVer. Each release of
47// `openapi-lambda-codegen` is guaranteed to be compatible only with the identical version number
48// of `openapi-lambda`.
49#[doc(hidden)]
50#[path = "private/mod.rs"]
51pub mod __private;