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