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

Ability to skip module path segments #30

Closed joaquin041 closed 1 month ago

joaquin041 commented 1 month ago

Hello! First of all, great library :)

I started using it to autodiscover some routes in my project, but I found that there is no way of having file paths and modules that are not directly hanging from "src" or "tests". In my case, I am trying to specify the path like this: #[utoipauto(paths = "(./src/lib/bin/module from crate::bin)"]

And the modules that are getting resolved are like: crate::lib::bin::module::etc

So I am getting a "could not find 'lib' in 'bin'" error. Which is expected, because 'lib' doesn't exist as a module. I would expect that if I am able to specify the module that the file is in, the module file path would be resolved in that module. So it would look like: crate::bin::module::etc -> removing "lib" as we know that the module starts in "bin", same thing that is done with "src"

Does that make sense? Or there's something I am missing? Thank you for your time.

joaquin041 commented 1 month ago

Tried solving it in https://github.com/ProbablyClem/utoipauto/pull/31

DenuxPlays commented 1 month ago

I don't get it.

Shouldn't the from keyword indicate that its from another crate but using crate:: syntax symbols that it's in the same crate?

joaquin041 commented 1 month ago

Exactly, what I am trying to indicate with crate:: is that even if it is in the same crate, it is not living in the assumed "src" folder. Ideally, with the path would be enough, but there is not always a direct translation between path and crate.

I believe that this comment https://github.com/ProbablyClem/utoipauto/blob/main/utoipauto-core/src/file_utils.rs#L79 explains it. This assumption is not always true. Modules can live in other folders that are not "src", and by using the crate name it can be inferred.

DenuxPlays commented 1 month ago

Ah okay understand it now.