Skip to content

Default import #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/target
*target
/Cargo.lock
git_cmd.md
git_cmd.md
26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[package]
name = "utoipa_auto_discovery"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
authors = ["RxDiscovery"]
rust-version = "1.69"
keywords = ["utoipa","openapi","swagger", "path", "auto"]
authors = ["RxDiscovery", "ProbablyClem"]
rust-version = "1.69"
keywords = ["utoipa", "openapi", "swagger", "path", "auto"]
description = "Rust Macros to automate the addition of Paths/Schemas to Utoipa crate, simulating Reflection during the compilation phase"
categories = ["parsing","development-tools::procedural-macro-helpers","web-programming"]
categories = [
"parsing",
"development-tools::procedural-macro-helpers",
"web-programming",
]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/rxdiscovery/utoipa_auto_discovery"
homepage = "https://github.com/rxdiscovery/utoipa_auto_discovery"


[lib]
proc-macro = true

[dependencies]
quote = "1.0.28"
syn = { version ="2.0.18", features = [ "full" ]}
proc-macro2 = "1.0.59"

[dependencies]
utoipa-auto-macro = { version = "0.4.0", path = "./utoipa-auto-macro" }


[build-dependencies]
[dev-dependencies]
utoipa = { version = "4.1.0", features = ["preserve_path_order"] }
71 changes: 67 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,75 @@ then add the `#[utoipa_auto_discovery]` macro just before the #[derive(OpenApi)]
Put `#[utoipa_auto_discovery]` before #[derive(OpenApi)] and `#[openapi]` macros.

```rust
#[utoipa_auto_discovery(paths = "( MODULE_TREE::MODULE_NAME => MODULE_SRC_FILE_PATH ) ; ( MODULE_TREE::MODULE_NAME => MODULE_SRC_FILE_PATH ) ; ... ;")]
#[utoipa_auto_discovery(paths = "MODULE_SRC_FILE_PATH, MODULE_SRC_FILE_PATH, ...")]
```

the paths receives a String which must respect this structure :

`" ( MODULE_TREE_PATH => MODULE_SRC_FILE_PATH ) ;"`
`MODULE_SRC_FILE_PATH, MODULE_SRC_FILE_PATH, ...`"`

you can add several pairs (Module Path => Src Path ) by separating them with a semicolon ";".
you can add several paths by separating them with a coma ",".

### Import from src folder

If no path is specified, the macro will automatically scan the `src` folder and add all the methods carrying the `#[utoipa::path(...)]` macro.
Here's an example of how to add all the methods contained in the src folder.

```rust
...

use utoipa_auto_discovery::utoipa_auto_discovery;

...
#[utoipa_auto_discovery]
#[derive(OpenApi)]
#[openapi(
components(
schemas(TestDTO)
),
tags(
(name = "todo", description = "Todo management endpoints.")
),
modifiers(&SecurityAddon)
)]

pub struct ApiDoc;

...

```

### Import from module

Here's an example of how to add all the methods contained in the rest module.

```rust
...

use utoipa_auto_discovery::utoipa_auto_discovery;

...
#[utoipa_auto_discovery(
paths = "./src/rest"
)]
#[derive(OpenApi)]
#[openapi(
components(
schemas(TestDTO)
),
tags(
(name = "todo", description = "Todo management endpoints.")
),
modifiers(&SecurityAddon)
)]

pub struct ApiDoc;

...

```

### Import from filename

Here's an example of how to add all the methods contained in the test_controller and test2_controller modules.
you can also combine automatic and manual addition, as here we've added a method manually to the documentation "other_controller::get_users".
Expand All @@ -97,7 +158,7 @@ use utoipa_auto_discovery::utoipa_auto_discovery;

...
#[utoipa_auto_discovery(
paths = "( crate::rest::test_controller => ./src/rest/test_controller.rs ) ; ( crate::rest::test2_controller => ./src/rest/test2_controller.rs )"
paths = "./src/rest/test_controller.rs,./src/rest/test2_controller.rs "
)]
#[derive(OpenApi)]
#[openapi(
Expand Down Expand Up @@ -149,4 +210,6 @@ sub-modules within a module containing methods tagged with utoipa::path are also
# Features

- [x] automatic path detection
- [x] automatic import from module
- [x] automatic import from src folder
- [ ] automatic schema detection (in progress)
Loading