Skip to content

Commit

Permalink
Add rapidoc support (#723)
Browse files Browse the repository at this point in the history
Add rapidoc support for utoipa and update todo examples. Add new
warp-rapidoc example to demonstrate rapidoc without predefined framework
integration.

Add utoipa-rapidoc CI setup.
  • Loading branch information
juhaku authored Aug 7, 2023
1 parent 30551f6 commit 56b6326
Show file tree
Hide file tree
Showing 28 changed files with 877 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- utoipa-gen
- utoipa-swagger-ui
- utoipa-redoc
- utoipa-rapidoc
fail-fast: true
runs-on: ubuntu-latest

Expand Down Expand Up @@ -53,6 +54,8 @@ jobs:
changes=true
elif [[ "$change" == "utoipa-redoc" && "${{ matrix.crate }}" == "utoipa-redoc" && $changes == false ]]; then
changes=true
elif [[ "$change" == "utoipa-rapidoc" && "${{ matrix.crate }}" == "utoipa-rapidoc" && $changes == false ]]; then
changes=true
fi
done < <(git diff --name-only ${{ github.sha }}~ ${{ github.sha }} | grep .rs | awk -F \/ '{print $1}')
echo "${{ matrix.crate }} changes: $changes"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- utoipa-gen
- utoipa-swagger-ui
- utoipa-redoc
- utoipa-rapidoc
runs-on: ubuntu-latest

steps:
Expand Down
16 changes: 14 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
[workspace]
resolver = "2"
members = ["utoipa", "utoipa-gen", "utoipa-swagger-ui", "utoipa-redoc"]
members = [
"utoipa",
"utoipa-gen",
"utoipa-swagger-ui",
"utoipa-redoc",
"utoipa-rapidoc",
]

[workspace.metadata.publish]
order = ["utoipa-gen", "utoipa", "utoipa-swagger-ui", "utoipa-redoc"]
order = [
"utoipa-gen",
"utoipa",
"utoipa-swagger-ui",
"utoipa-redoc",
"utoipa-rapidoc",
]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Refer to the existing [examples](./examples) for building the "todo" app in the
- **[tide](https://github.com/http-rs/tide)**
- **[rocket](https://github.com/SergioBenitez/Rocket)** (`0.4` and `0.5.0-rc3`)

All examples include a [Swagger-UI](https://github.com/swagger-api/swagger-ui) or [Redoc](https://github.com/Redocly/redoc).
All examples include a [Swagger-UI](https://github.com/swagger-api/swagger-ui) unless stated otherwise.

There are also examples of building multiple OpenAPI docs in one application, each separated in Swagger UI.
These examples exist only for the **actix** and **warp** frameworks.
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ with the library.
All examples have their own README.md, and can be seen using two steps:

1. Run `cargo run`
2. Browse to `http://localhost:8080/swagger-ui/` or `http://localhost:8080/redoc`.
2. Browse to `http://localhost:8080/swagger-ui/` or `http://localhost:8080/redoc` or `http://localhost:8080/rapidoc`.

`Todo-actix`, `todo-axum` and `rocket-todo` has both Swagger UI and Redoc setup others have Swagger UI
`Todo-actix`, `todo-axum` and `rocket-todo` have Swagger UI, Redoc and RapiDoc setup, others have Swagger UI
if not explicitly stated otherwise.
1 change: 1 addition & 0 deletions examples/rocket-todo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rocket = { version = "0.5.0-rc.3", features = ["json"] }
utoipa = { path = "../../utoipa", features = ["rocket_extras"] }
utoipa-swagger-ui = { path = "../../utoipa-swagger-ui", features = ["rocket"] }
utoipa-redoc = { path = "../../utoipa-redoc", features = ["rocket"] }
utoipa-rapidoc = { path = "../../utoipa-rapidoc", features = ["rocket"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
env_logger = "0.10.0"
Expand Down
4 changes: 3 additions & 1 deletion examples/rocket-todo/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# todo-rocket ~ utoipa with utoipa-swagger-ui and utoipa-redoc example
# todo-rocket ~ utoipa with utoipa-swagger-ui, utoipa-redoc and utoipa-rapidoc example

This is a demo `rocket` application with in-memory storage to manage Todo items. The API
demonstrates `utoipa` with `utoipa-swagger-ui` functionalities.
Expand All @@ -9,6 +9,8 @@ Just run command below to run the demo application and browse to `http://localho

If you prefer Redoc just head to `http://localhost:8000/redoc` and view the Open API.

RapiDoc can be found from `http://localhost:8000/redoc`.

```bash
cargo run
```
Expand Down
12 changes: 12 additions & 0 deletions examples/rocket-todo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use utoipa::{
openapi::security::{ApiKey, ApiKeyValue, SecurityScheme},
Modify, OpenApi,
};
use utoipa_rapidoc::RapiDoc;
use utoipa_redoc::{Redoc, Servable};
use utoipa_swagger_ui::SwaggerUi;

Expand Down Expand Up @@ -52,6 +53,17 @@ fn rocket() -> Rocket<Build> {
"/",
SwaggerUi::new("/swagger-ui/<_..>").url("/api-docs/openapi.json", ApiDoc::openapi()),
)
// There is no need to create RapiDoc::with_openapi because the OpenApi is served
// via SwaggerUi instead we only make rapidoc to point to the existing doc.
.mount(
"/",
RapiDoc::new("/api-docs/openapi.json").path("/rapidoc")
)
// Alternative to above
// .mount(
// "/",
// RapiDoc::with_openapi("/api-docs/openapi2.json", ApiDoc::openapi()).path("/rapidoc")
// )
.mount("/", Redoc::with_url("/redoc", ApiDoc::openapi()))
.mount(
"/todo",
Expand Down
1 change: 1 addition & 0 deletions examples/todo-actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ futures = "0.3"
utoipa = { path = "../../utoipa", features = ["actix_extras"] }
utoipa-swagger-ui = { path = "../../utoipa-swagger-ui", features = ["actix-web"] }
utoipa-redoc = { path = "../../utoipa-redoc", features = ["actix-web"] }
utoipa-rapidoc = { path = "../../utoipa-rapidoc", features = ["actix-web"] }

[workspace]
4 changes: 3 additions & 1 deletion examples/todo-actix/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# todo-actix ~ utoipa with utoipa-swagger-ui and utoipa-redoc example
# todo-actix ~ utoipa with utoipa-swagger-ui, utoipa-redoc and utoipa-rapidoc example

This is a demo `actix-web` application with in-memory storage to manage Todo items. The API
demonstrates `utoipa` with `utoipa-swagger-ui` functionalities.
Expand All @@ -9,6 +9,8 @@ Just run command below to run the demo application and browse to `http://localho

If you prefer Redoc just head to `http://localhost:8000/redoc` and view the Open API.

RapiDoc can be found from `http://localhost:8000/rapidoc`.

```bash
cargo run
```
Expand Down
6 changes: 6 additions & 0 deletions examples/todo-actix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use utoipa::{
openapi::security::{ApiKey, ApiKeyValue, SecurityScheme},
Modify, OpenApi,
};
use utoipa_rapidoc::RapiDoc;
use utoipa_redoc::{Redoc, Servable};
use utoipa_swagger_ui::SwaggerUi;

Expand Down Expand Up @@ -74,6 +75,11 @@ async fn main() -> Result<(), impl Error> {
.service(
SwaggerUi::new("/swagger-ui/{_:.*}").url("/api-docs/openapi.json", openapi.clone()),
)
// There is no need to create RapiDoc::with_openapi because the OpenApi is served
// via SwaggerUi instead we only make rapidoc to point to the existing doc.
.service(RapiDoc::new("/api-docs/openapi.json").path("/rapidoc"))
// Alternative to above
// .service(RapiDoc::with_openapi("/api-docs/openapi2.json", openapi.clone()).path("/rapidoc"))
})
.bind((Ipv4Addr::UNSPECIFIED, 8080))?
.run()
Expand Down
1 change: 1 addition & 0 deletions examples/todo-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tower = "0.4"
utoipa = { path = "../../utoipa", features = ["axum_extras"] }
utoipa-swagger-ui = { path = "../../utoipa-swagger-ui", features = ["axum"] }
utoipa-redoc = { path = "../../utoipa-redoc", features = ["axum"] }
utoipa-rapidoc = { path = "../../utoipa-rapidoc", features = ["axum"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
env_logger = "0.10.0"
Expand Down
4 changes: 3 additions & 1 deletion examples/todo-axum/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# todo-axum ~ utoipa with utoipa-swagger-ui and utoipa-redoc example
# todo-axum ~ utoipa with utoipa-swagger-ui, utoipa-redoc and utoipa-rapidoc example

This is a demo `axum` application with in-memory storage to manage Todo items. The API
demonstrates `utoipa` with `utoipa-swagger-ui` functionalities.
Expand All @@ -9,6 +9,8 @@ Just run command below to run the demo application and browse to `http://localho

If you prefer Redoc just head to `http://localhost:8000/redoc` and view the Open API.

RapiDoc can be found from `http://localhost:8000/rapidoc`.

```bash
cargo run
```
Expand Down
6 changes: 6 additions & 0 deletions examples/todo-axum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use utoipa::{
openapi::security::{ApiKey, ApiKeyValue, SecurityScheme},
Modify, OpenApi,
};
use utoipa_rapidoc::RapiDoc;
use utoipa_redoc::{Redoc, Servable};
use utoipa_swagger_ui::SwaggerUi;

Expand Down Expand Up @@ -52,6 +53,11 @@ async fn main() -> Result<(), Error> {
let app = Router::new()
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
.merge(Redoc::with_url("/redoc", ApiDoc::openapi()))
// There is no need to create `RapiDoc::with_openapi` because the OpenApi is served
// via SwaggerUi instead we only make rapidoc to point to the existing doc.
.merge(RapiDoc::new("/api-docs/openapi.json").path("/rapidoc"))
// Alternative to above
// .merge(RapiDoc::with_openapi("/api-docs/openapi2.json", ApiDoc::openapi()).path("/rapidoc"))
.route(
"/todo",
routing::get(todo::list_todos).post(todo::create_todo),
Expand Down
23 changes: 23 additions & 0 deletions examples/todo-warp-rapidoc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "todo-warp-rapidoc"
description = "Simple warp todo example api with utoipa and utoipa-rapidoc"
version = "0.1.0"
edition = "2021"
license = "MIT"
authors = [
"Elli Example <example@example.com>"
]

[dependencies]
tokio = { version = "1", features = ["full"] }
warp = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
env_logger = "0.10.0"
log = "0.4"
futures = "0.3"
utoipa = { path = "../../utoipa" }
utoipa-rapidoc = { path = "../../utoipa-rapidoc" }

[workspace]

12 changes: 12 additions & 0 deletions examples/todo-warp-rapidoc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# warp with utoipa-rapidoc

This is simple Todo app example with warp and utoipa-rapidoc OpenAPI viewer.

For security restricted endpoints the super secret API key is: `utoipa-rocks`.

Head to `http://localhost:8080/rapidoc` for the demo.

run
```rust
RUST_LOG=debug cargo run
```
Loading

0 comments on commit 56b6326

Please sign in to comment.