GREsau / GREsau/okapi

Okapi obfuscates compiler errors

Open
#12 15 comments 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
740
Forks
127
PR merge metrics
No merged PRs in 30d

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 {
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 {
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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.