Skip to content
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
7 changes: 5 additions & 2 deletions utoipa-rapidoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = ["Juha Kukkonen <[email protected]>"]
rust-version.workspace = true

[package.metadata.docs.rs]
features = ["actix-web", "axum", "rocket"]
features = ["actix-web", "axum", "rocket", "hyperlane"]
rustdoc-args = ["--cfg", "doc_cfg"]

[dependencies]
Expand All @@ -28,7 +28,10 @@ axum = { version = "0.8.0", default-features = false, features = [
], optional = true }

[dev-dependencies]
utoipa-rapidoc = { path = ".", features = ["actix-web", "axum", "rocket"] }
utoipa-rapidoc = { path = ".", features = ["actix-web", "axum", "rocket", "hyperlane"] }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(doc_cfg)'] }

[features]
hyperlane = []
49 changes: 42 additions & 7 deletions utoipa-rapidoc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ pub struct RapiDoc {
path: Cow<'static, str>,
spec_url: Cow<'static, str>,
html: Cow<'static, str>,
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
openapi: Option<utoipa::openapi::OpenApi>,
}

Expand All @@ -177,7 +182,12 @@ impl RapiDoc {
path: Cow::Borrowed(""),
spec_url: spec_url.into(),
html: Cow::Borrowed(DEFAULT_HTML),
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
openapi: None,
}
}
Expand All @@ -203,10 +213,20 @@ impl RapiDoc {
/// ApiDoc::openapi()
/// );
/// ```
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
#[cfg_attr(
doc_cfg,
doc(cfg(any(feature = "actix-web", feature = "rocket", feature = "axum")))
doc(cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
)))
)]
pub fn with_openapi<U: Into<Cow<'static, str>>>(
spec_url: U,
Expand Down Expand Up @@ -243,10 +263,20 @@ impl RapiDoc {
/// ApiDoc::openapi()
/// );
/// ```
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
#[cfg_attr(
doc_cfg,
doc(cfg(any(feature = "actix-web", feature = "rocket", feature = "axum")))
doc(cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
)))
)]
pub fn with_url<U: Into<Cow<'static, str>>, S: Into<Cow<'static, str>>>(
url: U,
Expand Down Expand Up @@ -283,7 +313,12 @@ impl RapiDoc {
/// RapiDoc::new("https://petstore3.swagger.io/api/v3/openapi.json")
/// .path("/rapidoc");
/// ```
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
pub fn path<U: Into<Cow<'static, str>>>(mut self, path: U) -> Self {
self.path = path.into();

Expand Down
7 changes: 5 additions & 2 deletions utoipa-redoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = ["Juha Kukkonen <[email protected]>"]
rust-version.workspace = true

[package.metadata.docs.rs]
features = ["actix-web", "axum", "rocket"]
features = ["actix-web", "axum", "rocket", "hyperlane"]
rustdoc-args = ["--cfg", "doc_cfg"]

[dependencies]
Expand All @@ -26,7 +26,10 @@ rocket = { version = "0.5", features = ["json"], optional = true }
axum = { version = "0.8.0", default-features = false, optional = true }

[dev-dependencies]
utoipa-redoc = { path = ".", features = ["actix-web", "axum", "rocket"] }
utoipa-redoc = { path = ".", features = ["actix-web", "axum", "rocket", "hyperlane"] }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(doc_cfg)'] }

[features]
hyperlane = []
5 changes: 3 additions & 2 deletions utoipa-swagger-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ url = ["dep:url"]
vendored = ["dep:utoipa-swagger-ui-vendored"]
# cache swagger ui zip
cache = ["dep:dirs", "dep:sha2"]
hyperlane = []

[dependencies]
rust-embed = { version = "8" }
Expand All @@ -41,10 +42,10 @@ http = "1.2"
similar = "2.5"
tokio = { version = "1", features = ["macros"] }
tower = "0.5"
utoipa-swagger-ui = { path = ".", features = ["actix-web", "axum", "rocket"] }
utoipa-swagger-ui = { path = ".", features = ["actix-web", "axum", "rocket", "hyperlane"] }

[package.metadata.docs.rs]
features = ["actix-web", "axum", "rocket", "vendored", "cache"]
features = ["actix-web", "axum", "rocket", "vendored", "cache", "hyperlane"]
no-default-features = true
rustdoc-args = ["--cfg", "doc_cfg"]

Expand Down
63 changes: 54 additions & 9 deletions utoipa-swagger-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ mod rocket;

use rust_embed::RustEmbed;
use serde::Serialize;
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
use utoipa::openapi::OpenApi;

include!(concat!(env!("OUT_DIR"), "/embed.rs"));
Expand Down Expand Up @@ -187,10 +192,20 @@ include!(concat!(env!("OUT_DIR"), "/embed.rs"));
#[non_exhaustive]
#[derive(Clone)]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
#[cfg_attr(
doc_cfg,
doc(cfg(any(feature = "actix-web", feature = "rocket", feature = "axum")))
doc(cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
)))
)]
pub struct SwaggerUi {
path: Cow<'static, str>,
Expand All @@ -199,10 +214,20 @@ pub struct SwaggerUi {
external_urls: Vec<(Url<'static>, serde_json::Value)>,
}

#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
#[cfg_attr(
doc_cfg,
doc(cfg(any(feature = "actix-web", feature = "rocket", feature = "axum")))
doc(cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
)))
)]
impl SwaggerUi {
/// Create a new [`SwaggerUi`] for given path.
Expand Down Expand Up @@ -782,10 +807,20 @@ impl<'a> Config<'a> {
/// is called on.
///
/// Current config will be returned with configured default values.
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
#[cfg_attr(
doc_cfg,
doc(cfg(any(feature = "actix-web", feature = "rocket", feature = "axum")))
doc(cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
)))
)]
fn configure_defaults<I: IntoIterator<Item = U>, U: Into<Url<'a>>>(mut self, urls: I) -> Self {
let Config {
Expand Down Expand Up @@ -1509,15 +1544,25 @@ fn format_config(config: &Config, file: String) -> Result<String, Box<dyn Error>
}

/// Is used to provide general way to deliver multiple types of OpenAPI docs via `utoipa-swagger-ui`.
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
#[derive(Clone)]
enum ApiDoc {
Utoipa(utoipa::openapi::OpenApi),
Value(serde_json::Value),
}

// Delegate serde's `Serialize` to the variant itself.
#[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))]
#[cfg(any(
feature = "actix-web",
feature = "rocket",
feature = "axum",
feature = "hyperlane"
))]
impl Serialize for ApiDoc {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down