-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b5a538e
Showing
26 changed files
with
1,694 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/target | ||
Cargo.lock | ||
*.iml | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "utoipa" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[workspace] | ||
members = [ | ||
"utoipa-gen" | ||
] | ||
|
||
[features] | ||
swagger_ui = ["rust-embed", "mime_guess"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
serde = { version = "1.0.130", features = ["derive"] } | ||
log = "0.4.14" | ||
serde_json = "1.0.68" | ||
rust-embed = { version = "6.2.0", optional = true } | ||
actix-web = { version = "3.3.2", optional = true } | ||
mime_guess = { version = "2.0.3", optional = true } | ||
utoipa-gen = { path = "./utoipa-gen" } |
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,14 @@ | ||
use std::process::Command; | ||
|
||
const SWAGGER_UI_DIST_ZIP: &str = "swagger-ui-3.52.5"; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed={}.zip", SWAGGER_UI_DIST_ZIP); | ||
|
||
Command::new("unzip") | ||
.arg(&format!("{}.zip", SWAGGER_UI_DIST_ZIP)) | ||
.arg(&format!("{}/dist/**", SWAGGER_UI_DIST_ZIP)) | ||
.args(&["-d", "target"]) | ||
.status() | ||
.unwrap(); | ||
} |
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,34 @@ | ||
use std::fmt::Display; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
Serde(serde_json::Error), | ||
Io(std::io::Error), | ||
} | ||
|
||
impl Display for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Serde(error) => write!(f, "serde: {}", error), | ||
Self::Io(error) => write!(f, "io: {}", error), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for Error { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
None | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for Error { | ||
fn from(io: std::io::Error) -> Self { | ||
Self::Io(io) | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for Error { | ||
fn from(serde: serde_json::Error) -> Self { | ||
Self::Serde(serde) | ||
} | ||
} |
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,11 @@ | ||
pub mod error; | ||
pub mod openapi; | ||
#[cfg(feature = "swagger_ui")] | ||
pub mod swagger_ui; | ||
pub mod types; | ||
|
||
pub use utoipa_gen::*; | ||
|
||
pub trait OpenApi { | ||
fn openapi() -> openapi::OpenApi; | ||
} |
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,39 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[non_exhaustive] | ||
#[derive(Serialize, Deserialize, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Contact { | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub name: Option<String>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub url: Option<String>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub email: Option<String>, | ||
} | ||
|
||
impl Contact { | ||
pub fn new() -> Self { | ||
Default::default() | ||
} | ||
|
||
pub fn with_name<S: AsRef<str>>(mut self, name: S) -> Self { | ||
self.name = Some(name.as_ref().to_string()); | ||
|
||
self | ||
} | ||
|
||
pub fn with_url<S: AsRef<str>>(mut self, url: S) -> Self { | ||
self.url = Some(url.as_ref().to_string()); | ||
|
||
self | ||
} | ||
|
||
pub fn with_email<S: AsRef<str>>(mut self, email: S) -> Self { | ||
self.email = Some(email.as_ref().to_string()); | ||
|
||
self | ||
} | ||
} |
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,24 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[non_exhaustive] | ||
#[derive(Serialize, Deserialize, Default, Clone)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ExternalDocs { | ||
pub url: String, | ||
pub description: Option<String>, | ||
} | ||
|
||
impl ExternalDocs { | ||
pub fn new<S: AsRef<str>>(url: S) -> Self { | ||
Self { | ||
url: url.as_ref().to_string(), | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn with_description<S: AsRef<str>>(mut self, description: S) -> Self { | ||
self.description = Some(description.as_ref().to_string()); | ||
|
||
self | ||
} | ||
} |
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,58 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::{contact::Contact, licence::Licence}; | ||
|
||
#[non_exhaustive] | ||
#[derive(Serialize, Deserialize, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Info { | ||
pub title: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub description: Option<String>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub terms_of_service: Option<String>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub contact: Option<Contact>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub licence: Option<Licence>, | ||
|
||
pub version: String, | ||
} | ||
|
||
impl Info { | ||
pub fn new<S: AsRef<str>>(title: S, version: S) -> Self { | ||
Self { | ||
title: title.as_ref().to_string(), | ||
version: version.as_ref().to_string(), | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn with_description<S: AsRef<str>>(mut self, description: S) -> Self { | ||
self.description = Some(description.as_ref().to_string()); | ||
|
||
self | ||
} | ||
|
||
pub fn with_terms_of_service<S: AsRef<str>>(mut self, terms_of_service: S) -> Self { | ||
self.terms_of_service = Some(terms_of_service.as_ref().to_string()); | ||
|
||
self | ||
} | ||
|
||
pub fn with_contact(mut self, contanct: Contact) -> Self { | ||
self.contact = Some(contanct); | ||
|
||
self | ||
} | ||
|
||
pub fn with_licence(mut self, licence: Licence) -> Self { | ||
self.licence = Some(licence); | ||
|
||
self | ||
} | ||
} |
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,26 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[non_exhaustive] | ||
#[derive(Serialize, Deserialize, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Licence { | ||
pub name: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub url: Option<String>, | ||
} | ||
|
||
impl Licence { | ||
pub fn new<S: AsRef<str>>(name: S) -> Self { | ||
Self { | ||
name: name.as_ref().to_string(), | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn with_url<S: AsRef<str>>(mut self, url: S) -> Self { | ||
self.url = Some(url.as_ref().to_string()); | ||
|
||
self | ||
} | ||
} |
Oops, something went wrong.