ProbablyClem / utoipauto

Rust Macros to automate the addition of Paths/Schemas to Utoipa crate, simulating Reflection during the compilation phase
Apache License 2.0
108 stars 10 forks source link

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

Closed bengsparks closed 2 months ago

bengsparks commented 4 months ago

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

squadgazzz commented 4 months ago

I think I have the same issue, not sure if my config is wrong: https://github.com/cowprotocol/services/blob/a88873892a962d5aab54dff79f7485bbd3e03756/crates/solvers/src/api/mod.rs#L52-L67

After cargo build, the yml file is changed, and there are no schemas... https://github.com/cowprotocol/services/blob/utoipauto/broken-example/crates/solvers/openapi.yml

ProbablyClem commented 3 months ago

Should be fixed in the new 0.1.11 release Does it work ?

leelhn2345 commented 3 months ago

Should be fixed in the new 0.1.11 release Does it work ?

Hi, are you asking if the new 0.1.11 release works? According to crates.io, the latest version of this crate is still 0.1.10

DenuxPlays commented 2 months ago

Should be fixed in the new 0.1.11 release Does it work ?

Hi, are you asking if the new 0.1.11 release works? According to crates.io, the latest version of this crate is still 0.1.10

v0.1.11 is now availble on crates.io Does it work?

bengsparks commented 2 months ago

Rebuilding my MRE repo with v0.1.11 looks good on my end; thanks very much

DenuxPlays commented 2 months ago

@ProbablyClem I think this can be closed now.