tamasfe / aide

An API documentation library
Apache License 2.0
412 stars 68 forks source link

redoc breaks when there is Json<Struct> #95

Closed JakkuSakura closed 10 months ago

JakkuSakura commented 11 months ago

The following code will break redoc

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct Request {
}

pub async fn request(
    Json(request): Json<Request>,
) -> impl IntoApiResponse {
    (StatusCode::OK, Json(())).into_response()
}
  ApiRouter::new()
        .api_route("/foo", post(request))

I got

Something went wrong...
Invalid reference token: definitions
Stack trace
Error: Invalid reference token: definitions
    at o.get (http://localhost:3300/redoc:18:261574)
    at Yc (http://localhost:3300/redoc:49:71447)
    at eu (http://localhost:3300/redoc:49:76077)
    at nu.generateExample (http://localhost:3300/redoc:49:78343)
    at new nu (http://localhost:3300/redoc:49:77771)
    at http://localhost:3300/redoc:49:78906
    at Array.map (<anonymous>)
    at new au (http://localhost:3300/redoc:49:78877)
    at new su (http://localhost:3300/redoc:49:79673)
    at get requestBody (http://localhost:3300/redoc:49:82742)

ReDoc Version: 2.0.0
Commit: 5fb4daa
JakkuSakura commented 10 months ago

It is caused by #/definitions/ being the default definition path, if aide::gen::extract_module(true) is not called. Docs of aide::gen::extract_module says the default is enabled, but SchemaSettings is not fully initialized in GenContext::new()