Skip to content

Commit 0a9d21e

Browse files
committed
Update To OpenAPI.json
1 parent 0075ace commit 0a9d21e

10 files changed

Lines changed: 332 additions & 111 deletions

File tree

build_log.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
cargo : Compiling rustapi-macros v0.1.0 (C:\Users\tunay\Documents\GitHub\RustAPI\crates\ru
2+
stapi-macros)
3+
At line:1 char:1
4+
+ cargo check -p hello-world 2>&1 | Out-File -Encoding UTF8 build_log.t ...
5+
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
+ CategoryInfo : NotSpecified: ( Compiling ru...rustapi-macros):String) [], R
7+
emoteException
8+
+ FullyQualifiedErrorId : NativeCommandError
9+
10+
Checking rustapi-core v0.1.0 (C:\Users\tunay\Documents\GitHub\RustAPI\crates\rustapi-core
11+
)
12+
error[E0615]: attempted to take value of method `path` on type `&Attribute`
13+
--> crates\rustapi-macros\src\lib.rs:91:35
14+
|
15+
91 | if let Some(ident) = attr.path.segments.last().map(|s| &s.ident) {
16+
| ^^^^ method, not a field
17+
|
18+
help: use parentheses to call the method
19+
|
20+
91 | if let Some(ident) = attr.path().segments.last().map(|s| &s.ident) {
21+
| ++
22+
23+
For more information about this error, try `rustc --explain E0615`.
24+
error: could not compile `rustapi-macros` (lib) due to 1 previous error
25+
warning: build failed, waiting for other jobs to finish...
26+
warning: unused import: `self`
27+
--> crates\rustapi-core\src\extract.rs:378:37
28+
|
29+
378 | use rustapi_openapi::utoipa_types::{self, openapi};
30+
| ^^^^
31+
|
32+
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
33+
34+
warning: unused variable: `state`
35+
--> crates\rustapi-core\src\app.rs:62:27
36+
|
37+
62 | pub fn state<S>(self, state: S) -> Self
38+
| ^^^^^ help: if this is intentional, prefix it with an undersco
39+
re: `_state`
40+
|
41+
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
42+
43+
warning: variable does not need to be mutable
44+
--> crates\rustapi-core\src\app.rs:160:26
45+
|
46+
160 | fn route_with_method(mut self, path: &str, method: http::Method, handler: crate::ha
47+
ndler::BoxedHandler) -> Self {
48+
| ----^^^^
49+
| |
50+
| help: remove this `mut`
51+
|
52+
= note: `#[warn(unused_mut)]` (part of `#[warn(unused)]`) on by default
53+
54+
error[E0382]: use of partially moved value: `self.operation`
55+
--> crates\rustapi-core\src\handler.rs:335:26
56+
|
57+
329 | let tags = if let Some(mut tags) = self.operation.tags {
58+
| -------- value partially moved here
59+
...
60+
335 | self.operation = self.operation.tags(tags);
61+
| ^^^^^^^^^^^^^^ value used here after partial move
62+
|
63+
= note: partial move occurs because value has type `Vec<std::string::String>`, which does
64+
not implement the `Copy` trait
65+
help: borrow this binding in the pattern to avoid moving the value
66+
|
67+
329 | let tags = if let Some(ref mut tags) = self.operation.tags {
68+
| +++
69+
70+
For more information about this error, try `rustc --explain E0382`.
71+
warning: `rustapi-core` (lib) generated 3 warnings
72+
error: could not compile `rustapi-core` (lib) due to 1 previous error; 3 warnings emitted

crates/rustapi-core/src/app.rs

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ impl RustApi {
3232
pub fn new() -> Self {
3333
// Initialize tracing if not already done
3434
let _ = tracing_subscriber::registry()
35-
.with(EnvFilter::try_from_default_env().unwrap_or_else(|_| {
36-
EnvFilter::new("info,rustapi=debug")
37-
}))
35+
.with(
36+
EnvFilter::try_from_default_env()
37+
.unwrap_or_else(|_| EnvFilter::new("info,rustapi=debug")),
38+
)
3839
.with(tracing_subscriber::fmt::layer())
3940
.try_init();
4041

4142
Self {
4243
router: Router::new(),
43-
openapi_spec: rustapi_openapi::OpenApiSpec::new("RustAPI Application", "1.0.0"),
44+
openapi_spec: rustapi_openapi::OpenApiSpec::new("RustAPI Application", "1.0.0")
45+
.register::<rustapi_openapi::ErrorSchema>()
46+
.register::<rustapi_openapi::ValidationErrorSchema>()
47+
.register::<rustapi_openapi::FieldErrorSchema>(),
4448
}
4549
}
4650

@@ -59,17 +63,17 @@ impl RustApi {
5963
/// RustApi::new()
6064
/// .state(AppState::new())
6165
/// ```
62-
pub fn state<S>(self, state: S) -> Self
66+
pub fn state<S>(self, _state: S) -> Self
6367
where
6468
S: Clone + Send + Sync + 'static,
6569
{
66-
// For now, state is handled by the router/handlers directly capturing it
67-
// or through a middleware. The current router (matchit) implementation
70+
// For now, state is handled by the router/handlers directly capturing it
71+
// or through a middleware. The current router (matchit) implementation
6872
// doesn't support state injection directly in the same way axum does.
6973
// This is a placeholder for future state management.
7074
self
7175
}
72-
76+
7377
/// Register an OpenAPI schema
7478
///
7579
/// # Example
@@ -85,7 +89,7 @@ impl RustApi {
8589
self.openapi_spec = self.openapi_spec.register::<T>();
8690
self
8791
}
88-
92+
8993
/// Configure OpenAPI info (title, version, description)
9094
pub fn openapi_info(mut self, title: &str, version: &str, description: Option<&str>) -> Self {
9195
self.openapi_spec = rustapi_openapi::OpenApiSpec::new(title, version);
@@ -151,39 +155,46 @@ impl RustApi {
151155
};
152156

153157
// Register operation in OpenAPI spec
154-
self.openapi_spec = self.openapi_spec.path(route.path, route.method, route.operation);
155-
158+
self.openapi_spec = self
159+
.openapi_spec
160+
.path(route.path, route.method, route.operation);
161+
156162
self.route_with_method(route.path, method_enum, route.handler)
157163
}
158164

159165
/// Helper to mount a single method handler
160-
fn route_with_method(mut self, path: &str, method: http::Method, handler: crate::handler::BoxedHandler) -> Self {
166+
fn route_with_method(
167+
self,
168+
path: &str,
169+
method: http::Method,
170+
handler: crate::handler::BoxedHandler,
171+
) -> Self {
161172
use crate::router::MethodRouter;
162173
// use http::Method; // Removed
163-
174+
164175
// This is simplified. In a real implementation we'd merge with existing router at this path
165-
// For now we assume one handler per path or we simply allow overwriting for this MVP step
176+
// For now we assume one handler per path or we simply allow overwriting for this MVP step
166177
// (matchit router doesn't allow easy merging/updating existing entries without rebuilding)
167-
//
178+
//
168179
// TOOD: Enhance Router to support method merging
169-
180+
170181
let path = if !path.starts_with('/') {
171182
format!("/{}", path)
172183
} else {
173184
path.to_string()
174185
};
175-
176-
// Check if we already have this path?
186+
187+
// Check if we already have this path?
177188
// For MVP, valid assumption: user calls .route() or .mount() once per path-method-combo
178189
// But we need to handle multiple methods on same path.
179-
// Our Router wrapper currently just inserts.
180-
190+
// Our Router wrapper currently just inserts.
191+
181192
// Since we can't easily query matchit, we'll just insert.
182193
// Limitations: strictly sequential mounting for now.
183-
194+
184195
let mut handlers = std::collections::HashMap::new();
185196
handlers.insert(method, handler);
186-
197+
187198
let method_router = MethodRouter::from_boxed(handlers);
188199
self.route(&path, method_router)
189200
}
@@ -223,7 +234,7 @@ impl RustApi {
223234
let title = self.openapi_spec.info.title.clone();
224235
let version = self.openapi_spec.info.version.clone();
225236
let description = self.openapi_spec.info.description.clone();
226-
237+
227238
self.docs_with_info(path, &title, &version, description.as_deref())
228239
}
229240

@@ -249,14 +260,15 @@ impl RustApi {
249260
if let Some(desc) = description {
250261
self.openapi_spec.info.description = Some(desc.to_string());
251262
}
252-
263+
253264
let path = path.trim_end_matches('/');
254265
let openapi_path = format!("{}/openapi.json", path);
255-
266+
256267
// Clone values for closures
257-
let spec_json = serde_json::to_string_pretty(&self.openapi_spec.to_json()).unwrap_or_default();
268+
let spec_json =
269+
serde_json::to_string_pretty(&self.openapi_spec.to_json()).unwrap_or_default();
258270
let openapi_url = openapi_path.clone();
259-
271+
260272
// Add OpenAPI JSON endpoint
261273
let spec_handler = move || {
262274
let json = spec_json.clone();
@@ -268,7 +280,7 @@ impl RustApi {
268280
.unwrap()
269281
}
270282
};
271-
283+
272284
// Add Swagger UI endpoint
273285
let docs_handler = move || {
274286
let url = openapi_url.clone();
@@ -277,7 +289,7 @@ impl RustApi {
277289
html
278290
}
279291
};
280-
292+
281293
self.route(&openapi_path, get(spec_handler))
282294
.route(path, get(docs_handler))
283295
}

0 commit comments

Comments
 (0)