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

Correctly convert paths containing 'src' to module paths #1

Closed tnibler closed 9 months ago

tnibler commented 9 months ago

When using utoipa in a subcrate of a cargo workspace, macro invocations may look like:

#[utoipauto(paths = "./subcrate/src/module/thing.rs")]

Before this change, expanded code looks like:

        let mut openapi = utoipa::openapi::OpenApiBuilder::new()
            .info(...)
            .paths(
                utoipa::openapi::path::PathsBuilder::new()
                    .path(
                        crate::src::module::thing::__path_get_endpoint::path(),
                        crate::src::module::thing::__path_get_endpoint::path_item(
                            Some("crate::src::module::thing"),
                        ),
                    ),
            )
            .build();

where crate::src::module::thing is incorrect and should be crate::module::thing.

This commit changes the path -> module path conversion logic to the following:

ProbablyClem commented 9 months ago

I just fixed it and released 0.1.2 with the fix, using replace Let me know if it fixes your issue...

ProbablyClem commented 9 months ago

Thanks for your contribution, however, you can't use local deps otherwise it can't be published to crates.io. There must be a way but I couln't find it... Can you submit a new PR with just the parsing from enum and add tests cases. Thanks

tnibler commented 9 months ago

Woops sorry didn't realize. Now it's only the one change.

ProbablyClem commented 9 months ago

The /src issue has been fixed with a replace in the latest 0.1.2 release. Why would your solution be better ? Btw, please add tests when you submit a PR

ProbablyClem commented 9 months ago

I used your solution because it fixed #2 Thanks for your help