1mod config;
33mod schemas;
34mod spec;
35#[cfg(feature = "swagger-ui")]
36mod swagger;
37
38pub use config::OpenApiConfig;
39pub use schemas::{ErrorSchema, FieldErrorSchema, ValidationErrorSchema};
40pub use spec::{
41 ApiInfo, MediaType, OpenApiSpec, Operation, OperationModifier, Parameter, PathItem,
42 RequestBody, ResponseModifier, ResponseSpec, SchemaRef,
43};
44
45pub use utoipa::ToSchema as Schema;
47pub use utoipa::IntoParams;
49
50pub mod utoipa_types {
52 pub use utoipa::{openapi, IntoParams, Modify, OpenApi, ToSchema};
53}
54
55use bytes::Bytes;
56use http::{header, Response, StatusCode};
57use http_body_util::Full;
58
59pub fn openapi_json(spec: &OpenApiSpec) -> Response<Full<Bytes>> {
61 match serde_json::to_string_pretty(&spec.to_json()) {
62 Ok(json) => Response::builder()
63 .status(StatusCode::OK)
64 .header(header::CONTENT_TYPE, "application/json")
65 .body(Full::new(Bytes::from(json)))
66 .unwrap(),
67 Err(_) => Response::builder()
68 .status(StatusCode::INTERNAL_SERVER_ERROR)
69 .body(Full::new(Bytes::from("Failed to serialize OpenAPI spec")))
70 .unwrap(),
71 }
72}
73
74#[cfg(feature = "swagger-ui")]
76pub fn swagger_ui_html(openapi_url: &str) -> Response<Full<Bytes>> {
77 let html = swagger::generate_swagger_html(openapi_url);
78 Response::builder()
79 .status(StatusCode::OK)
80 .header(header::CONTENT_TYPE, "text/html; charset=utf-8")
81 .body(Full::new(Bytes::from(html)))
82 .unwrap()
83}