-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from kotborealis/dyn-spec
Dyn spec
- Loading branch information
Showing
22 changed files
with
127 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
Cargo.lock | ||
.idea |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
name = "actix-web-swagger-ui" | ||
version = "0.1.0" | ||
authors = ["Tarkin25 <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
exclude = [ | ||
".idea" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
name = "rocket-swagger-ui" | ||
version = "0.1.5" | ||
authors = ["kotborealis <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
exclude = [ | ||
".idea" | ||
] | ||
|
@@ -17,4 +17,5 @@ repository = "https://github.com/kotborealis/swagger-ui" | |
swagger-ui = { version = "0.1", path = "../swagger-ui" } | ||
rocket = "0.4.7" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0.64" | ||
serde_json = "1.0.64" | ||
derive_builder = "0.12.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target | ||
Cargo.lock | ||
.idea | ||
.idea | ||
.dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
name = "swagger-ui" | ||
version = "0.1.5" | ||
authors = ["kotborealis <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
exclude = [ | ||
".idea" | ||
] | ||
|
@@ -24,4 +24,14 @@ serde = { version = "1.0", features = ["derive"] } | |
serde_json = "1.0.64" | ||
|
||
rocket-swagger-ui = { version = "0.1", optional = true } | ||
# actix-web-swagger-ui = { version = "0.1", optional = true } | ||
# actix-web-swagger-ui = { version = "0.1", optional = true } | ||
|
||
[build-dependencies] | ||
reqwest = { version = "0.11.20", features = ["json", "stream", "rustls"] } | ||
futures = "0.3.28" | ||
futures-executor = "0.3.28" | ||
tokio = { version = "1.32.0", features = ["full"] } | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
anyhow = "1.0.75" | ||
async-recursion = "1.0.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use std::path::PathBuf; | ||
use anyhow::Context; | ||
use async_recursion::async_recursion; | ||
use serde::Deserialize; | ||
use futures::StreamExt; | ||
use reqwest::{Client, IntoUrl}; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(rename_all="snake_case")] | ||
enum EntryType { | ||
File, | ||
Dir | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct FolderEntry { | ||
name: String, | ||
url: String, | ||
r#type: EntryType, | ||
download_url: Option<String> | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum OneOrMany<T> { | ||
/// Single value | ||
One(T), | ||
/// Array of values | ||
Vec(Vec<T>), | ||
} | ||
impl<T> From<OneOrMany<T>> for Vec<T> { | ||
fn from(from: OneOrMany<T>) -> Self { | ||
match from { | ||
OneOrMany::One(val) => vec![val], | ||
OneOrMany::Vec(vec) => vec, | ||
} | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let out_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?).join(".dist"); | ||
download_folder("https://api.github.com/repos/swagger-api/swagger-ui/contents/dist", out_dir).await?; | ||
Ok(()) | ||
} | ||
|
||
#[async_recursion] | ||
async fn download_folder(url: &str, to: impl Into<PathBuf> + Send + 'static) -> anyhow::Result<()> { | ||
let entries: Vec<_> = reqwest()?.get(url).send().await.with_context(||format!("failed to query folder data for {url}"))?.json::<OneOrMany<FolderEntry>>().await.with_context(||format!("failed to parse json for {url}"))?.into(); | ||
let ref path = to.into(); | ||
futures::future::try_join_all(entries.into_iter().map(|entry| async move { | ||
match entry.r#type { | ||
EntryType::File => download_file(entry.download_url.unwrap(), path.clone().join(entry.name)).await, | ||
EntryType::Dir => download_folder(&entry.url, path.clone().join(entry.name)).await | ||
} | ||
})).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn download_file(url: impl IntoUrl + Send, to: impl Into<PathBuf> + Send) -> anyhow::Result<()> { | ||
let path = to.into(); | ||
if let Some(parent) = path.parent() { | ||
tokio::fs::create_dir_all(parent).await?; | ||
} | ||
let mut byte_stream = reqwest()?.get(url).send().await?.bytes_stream(); | ||
let mut tmp_file = tokio::fs::File::create(path).await?; | ||
while let Some(item) = byte_stream.next().await { | ||
tokio::io::copy(&mut item?.as_ref(), &mut tmp_file).await?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn reqwest() -> anyhow::Result<Client> { | ||
Ok(Client::builder() | ||
.user_agent("reqwest") | ||
.build()?) | ||
} |
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.