-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Path proc macro resolve basic properties
- Loading branch information
Showing
11 changed files
with
579 additions
and
110 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
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
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,84 +1,32 @@ | ||
use std::collections::HashMap; | ||
|
||
use actix_web::{delete, HttpResponse, Responder}; | ||
use serde_json::json; | ||
// use utoipa::openapi_spec; | ||
use utoipa::{api_operation, Component, OpenApi}; | ||
use utoipa::{path, OpenApi}; | ||
|
||
// mod api { | ||
// use super::*; | ||
|
||
/// Delete foo entity | ||
/// | ||
/// Delete foo entity by what | ||
#[api_operation(delete, responses = [ | ||
#[crate::path(responses = [ | ||
(200, "success", String), | ||
(400, "my bad error", u64), | ||
(404, "vault not found"), | ||
(500, "internal server error") | ||
])] | ||
fn foo_delete() {} | ||
#[delete("/foo")] | ||
async fn foo_delete() -> impl Responder { | ||
HttpResponse::Ok().json(json!({"ok": "OK"})) | ||
} | ||
// } | ||
|
||
#[test] | ||
fn derive_openapi() { | ||
// use crate::api::__path_foo_delete; | ||
#[derive(OpenApi, Default)] | ||
#[openapi(handler_files = ["tests/utoipa_gen_test.rs"])] | ||
#[openapi(handler_files = [], handlers = [foo_delete])] | ||
struct ApiDoc; | ||
|
||
println!("{:?}", ApiDoc::openapi().to_json()) | ||
} | ||
|
||
#[test] | ||
fn derive_component_struct() { | ||
/// Mode defines user type | ||
#[derive(Component)] | ||
#[component(default = "Mode1", example = "Mode2")] | ||
enum Mode { | ||
/// Mode1 is admin user | ||
Mode1, | ||
Mode2, | ||
// Mode3(usize), | ||
// Mode4 { x: String }, | ||
// Mode5(usize, String), | ||
} | ||
|
||
#[derive(Component)] | ||
struct Book { | ||
#[component(default = "crate::random_default", example = "Book 1")] | ||
name: String, | ||
|
||
#[component( | ||
default = "test", | ||
example = "base64 text", | ||
format = "ComponentFormat::Byte" | ||
)] | ||
hash: String, | ||
} | ||
|
||
/// This is user component | ||
/// | ||
/// User component is being used to store user information | ||
#[derive(Component)] | ||
// #[component()] | ||
struct User { | ||
/// This is a database id of a user | ||
#[component(default = 1)] | ||
id: u64, | ||
// username: String, | ||
/// User authenticated roles | ||
roles: Vec<String>, | ||
/// Foobar hashmap | ||
foobar: HashMap<String, i64>, | ||
/// Optional value is user enabled | ||
enabled: Option<bool>, | ||
// random: Option<Vec<String>>, | ||
// mode: Option<Mode>, | ||
// book: Book, | ||
long_property: String, | ||
} | ||
|
||
#[derive(OpenApi, Default)] | ||
#[openapi(handler_files = [], components = [User, Book, Mode])] | ||
struct ApiDoc; | ||
|
||
println!("{}", ApiDoc::openapi().to_json().unwrap()); | ||
} | ||
|
||
fn random_default() -> String { | ||
"random".to_string() | ||
} |
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
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
Oops, something went wrong.