utoipauto icon indicating copy to clipboard operation
utoipauto copied to clipboard

`#[derive(utoipa::ToSchema)]` detection fails

Open bengsparks opened this issue 10 months ago • 3 comments

It seems the detection of utoipa::ToSchema is buggy. I have uploaded an MRE here that I invite you to try out at your convenience.

Generating and comparing both openapi.working.yaml and openapi.broken.yaml indicate that the latter is missing the schema for the Person struct, whereas the former includes it.

$ diff src/broken.rs src/working.rs -U1000

--- src/broken.rs       2024-04-16 14:53:32
+++ src/working.rs      2024-04-16 14:53:35
@@ -1,19 +1,19 @@
-use utoipa::OpenApi;
+use utoipa::{OpenApi, ToSchema};
 use utoipauto;
 
-#[derive(utoipa::ToSchema)]
+#[derive(ToSchema)]
 pub struct Person {
     /// Id of person
     id: i64,
     /// Name of person
     name: String,
 }
 
 pub fn gen_my_openapi() -> String {
-    #[utoipauto::utoipauto(paths = "./src/broken.rs")]
+    #[utoipauto::utoipauto(paths = "./src/working.rs")]
     #[derive(OpenApi)]
     #[openapi()]
     struct ApiDoc;
 
     ApiDoc::openapi().to_pretty_json().unwrap()
 }

It seems the discovery mechanism of utoipauto fails to account for the fully qualified reference to utoipa::ToSchema, and only matches on ToSchema. I suspect the issue lies somewhere here? I also assume the same bug affects discovery of utoipa::ToResponse

bengsparks avatar Apr 16 '24 13:04 bengsparks