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
139
140
141
142
143
144
145
146
//! OpenAPI 3.0 specification generation and Swagger UI integration for Armature
//!
//! This crate provides tools for generating OpenAPI specifications and serving
//! interactive API documentation via Swagger UI.
//!
//! ## Features
//!
//! - 📝 **Programmatic API** - Build OpenAPI specs with fluent builder
//! - 📊 **Swagger UI response helper** - `swagger_ui_response` renders an interactive
//! Swagger UI page, loading its JS/CSS assets from a CDN (not self-contained; requires
//! network access and is incompatible with a strict CSP)
//! - 📤 **JSON/YAML Export** - Multiple export formats
//! - 🔒 **Type-Safe** - Strongly typed OpenAPI 3.0 specification
//! - 🔐 **Auth Schemes** - Bearer, API Key, OAuth2, OpenID Connect
//! - 📋 **Schema Support** - Request/response schemas
//!
//! ## Quick Start - Basic API Spec
//!
//! ```
//! use armature_openapi::OpenApiBuilder;
//!
//! let spec = OpenApiBuilder::new("My API", "1.0.0")
//! .description("A wonderful API")
//! .server("http://localhost:3000", None)
//! .build();
//!
//! assert_eq!(spec.info.title, "My API");
//! assert_eq!(spec.info.version, "1.0.0");
//! assert_eq!(spec.servers.len(), 1);
//! ```
//!
//! ## Adding Authentication
//!
//! ```
//! use armature_openapi::{OpenApiBuilder, ApiKeyLocation};
//!
//! let spec = OpenApiBuilder::new("Secure API", "1.0.0")
//! .add_bearer_auth("bearer")
//! .add_api_key_auth("api_key", "X-API-Key", ApiKeyLocation::Header)
//! .build();
//!
//! assert!(spec.components.is_some());
//! let components = spec.components.unwrap();
//! assert!(components.security_schemes.contains_key("bearer"));
//! assert!(components.security_schemes.contains_key("api_key"));
//! ```
//!
//! ## Adding Paths and Operations
//!
//! ```
//! use armature_openapi::{OpenApiBuilder, PathItem, Operation, Response};
//! use std::collections::HashMap;
//!
//! let mut get_operation = Operation::default();
//! get_operation.summary = Some("Get user by ID".to_string());
//! get_operation.operation_id = Some("getUserById".to_string());
//!
//! let mut responses = HashMap::new();
//! responses.insert("200".to_string(), Response {
//! description: "Successful response".to_string(),
//! content: None,
//! });
//! get_operation.responses = responses;
//!
//! let mut path_item = PathItem::default();
//! path_item.get = Some(get_operation);
//!
//! let mut spec = OpenApiBuilder::new("User API", "1.0.0").build();
//! spec.paths.insert("/users/{id}".to_string(), path_item);
//!
//! assert!(spec.paths.contains_key("/users/{id}"));
//! assert!(spec.paths.get("/users/{id}").unwrap().get.is_some());
//! ```
//!
//! ## Swagger UI Configuration
//!
//! ```
//! use armature_openapi::{OpenApiBuilder, SwaggerConfig};
//!
//! let spec = OpenApiBuilder::new("My API", "1.0.0")
//! .description("API with Swagger UI")
//! .build();
//!
//! let swagger_config = SwaggerConfig::new("/api-docs", spec)
//! .with_title("My API Documentation");
//!
//! // Configuration ready
//! assert_eq!(swagger_config.path, "/api-docs");
//! assert_eq!(swagger_config.title, "My API Documentation");
//! ```
//!
//! ## Adding Multiple Servers
//!
//! ```
//! use armature_openapi::OpenApiBuilder;
//!
//! let spec = OpenApiBuilder::new("Multi-Env API", "1.0.0")
//! .server("https://api.production.com", Some("Production server".to_string()))
//! .server("https://api.staging.com", Some("Staging server".to_string()))
//! .server("http://localhost:3000", Some("Local development".to_string()));
//!
//! let built_spec = spec.build();
//!
//! assert_eq!(built_spec.servers.len(), 3);
//! assert_eq!(built_spec.servers[0].url, "https://api.production.com");
//! assert_eq!(built_spec.servers[1].url, "https://api.staging.com");
//! assert_eq!(built_spec.servers[2].url, "http://localhost:3000");
//! assert_eq!(built_spec.servers[0].description, Some("Production server".to_string()));
//! ```
//!
//! ## README Quick Start
//!
//! This mirrors the example in `README.md` verbatim, so it is guaranteed to compile.
//!
//! ```
//! use armature_openapi::{OpenApiBuilder, SwaggerConfig, swagger_ui_response, spec_json_response};
//!
//! // Build the spec by hand with the fluent builder.
//! let spec = OpenApiBuilder::new("My API", "1.0.0")
//! .description("A wonderful API")
//! .server("http://localhost:3000", None)
//! .build();
//!
//! // Wrap it in a SwaggerConfig to serve it.
//! let config = SwaggerConfig::new("/api-docs", spec).with_title("My API Documentation");
//!
//! // `swagger_ui_response(&config)` returns an `HttpResponse` rendering the Swagger UI HTML page.
//! // `spec_json_response(&config)` returns an `HttpResponse` serving the raw spec as JSON.
//! let ui_response = swagger_ui_response(&config).unwrap();
//! let json_response = spec_json_response(&config).unwrap();
//!
//! assert_eq!(config.path, "/api-docs");
//! assert_eq!(config.title, "My API Documentation");
//! assert_eq!(ui_response.status, 200);
//! assert_eq!(json_response.status, 200);
//! ```
pub use *;
pub use *;
pub use *;
pub use *;