-
Notifications
You must be signed in to change notification settings - Fork 120
Open
Description
Thank you for this project! I've been struggling with documenting an API I build, and keeping that documentation up to date. I'm trying to add okapi to my project to have the documentation be created automatically. Unfortunately, I'm running into some issues:
As it stands, Rocket is able to provide neat Rust error messages. Consider the following example:
#![feature(decl_macro, proc_macro_hygiene)]
use rocket::{get, routes};
use rocket_contrib::json::Json;
#[derive(serde::Serialize)]
struct Response {
reply: String,
}
#[get("/")]
fn my_controller() -> Json<Response> {
Json(Response {
reply: 0,
})
}
fn main() {
rocket::ignite()
.mount("/", routes![my_controller])
.launch();
}
This fails with a compile error:
[me@mycomputer tmp]$ cargo check
Checking tmp v0.1.0 (/home/me/code/rust/tmp)
error[E0308]: mismatched types
--> src/main.rs:17:16
|
17 | reply: 0,
| ^
| |
| expected struct `std::string::String`, found integer
| help: try using a conversion method: `0.to_string()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `tmp`.
However, when the code is changed to use Okapi:
#![feature(decl_macro, proc_macro_hygiene)]
use rocket::get;
use rocket_contrib::json::Json;
use rocket_okapi::{openapi, routes_with_openapi};
use schemars::JsonSchema;
#[derive(serde::Serialize, JsonSchema)]
struct Response {
reply: String,
}
#[openapi]
#[get("/")]
fn my_controller() -> Json<Response> {
Json(Response {
reply: 0,
})
}
fn main() {
rocket::ignite()
.mount("/", routes_with_openapi![my_controller])
.launch();
}
The error message changes:
[me@mycomputer tmp]$ cargo check
Checking tmp v0.1.0 (/home/me/code/rust/tmp)
error[E0308]: mismatched types
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `tmp`.
The useful information about what caused the compilation error is gone, making it really hard to debug. Is there any way to get it back?
jonnius and sd2k
Metadata
Metadata
Assignees
Labels
No labels