Skip to content

Commit

Permalink
Merge pull request #164 from myyrakle/feat/#163
Browse files Browse the repository at this point in the history
[#163] rename RupringDoc => RupringDto
  • Loading branch information
myyrakle authored Dec 1, 2024
2 parents 0f5f2ec + 6894fb1 commit 4b51542
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# rupring

![](https://img.shields.io/badge/language-Rust-red) ![](https://img.shields.io/badge/version-0.10.0-brightgreen) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/myyrakle/rupring/blob/master/LICENSE)
![](https://img.shields.io/badge/language-Rust-red) ![](https://img.shields.io/badge/version-0.11.0-brightgreen) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/myyrakle/rupring/blob/master/LICENSE)

Spring Comes to Rust

## Get Started

required dependency list

```toml
rupring = "0.9.1"
rupring = "0.11.0"
serde = { version="1.0.193", features=["derive"] }
```

Expand Down
4 changes: 2 additions & 2 deletions rupring/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rupring"
version = "0.10.0"
version = "0.11.0"
edition = "2021"
license = "MIT"
authors = ["myyrakle <[email protected]>"]
Expand All @@ -14,7 +14,7 @@ homepage = "https://github.com/myyrakle/rupring/blob/master/README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rupring_macro={ version="0.8.2", path="../rupring_macro" }
rupring_macro={ version="0.11.0", path="../rupring_macro" }
hyper = { version = "1", features = ["full"] }
tokio = { version = "1", features = ["full"] }
http-body-util = "0.1.0"
Expand Down
4 changes: 2 additions & 2 deletions rupring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ impl<T: IModule + Clone + Copy + Sync + Send + 'static> RupringFactory<T> {
}
}

/// RupringDoc derive macro
pub use rupring_macro::RupringDoc;
/// RupringDto derive macro
pub use rupring_macro::RupringDto;

#[cfg(test)]
mod test_proc_macro;
Expand Down
22 changes: 11 additions & 11 deletions rupring/src/swagger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ pub fn echo(
}
```
Using the RupringDoc derive macro, you can perform document definition for Request Parameter.
Using the RupringDto derive macro, you can perform document definition for Request Parameter.
```rust
use rupring::RupringDoc;
use rupring::RupringDto;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct CreateUserRequest {
#[desc = "user name"]
#[example = "foobar"]
Expand All @@ -35,7 +35,7 @@ pub struct CreateUserRequest {
pub password: String,
}
```
### RupringDoc attribute Details
### RupringDto attribute Details
1. `#[desc = ""]` or `#[description = ""]`: Description of the field.
2. `#[example = ""]`: Example value of the field.
3. `#[name = "id"]`: If the field name is different from the variable name, you can add this annotation.
Expand All @@ -46,10 +46,10 @@ pub struct CreateUserRequest {
Then, you can specify request information in the API through the params attribute as follows.
```rust
use rupring::RupringDoc;
use rupring::RupringDto;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct CreateUserRequest {
#[desc = "user name"]
#[example = "foobar"]
Expand All @@ -73,12 +73,12 @@ pub fn create_user(request: rupring::Request, _: rupring::Response) -> rupring::
}
```
Response documentation can also be defined through the RupringDoc macro and response attribute.
Response documentation can also be defined through the RupringDto macro and response attribute.
```rust
use rupring::RupringDoc;
use rupring::RupringDto;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct GetUserResponse {
pub id: i32,
pub username: String,
Expand All @@ -96,10 +96,10 @@ pub fn get_user(request: rupring::Request, _: rupring::Response) -> rupring::Res
If you want to activate BearerAuth for the API, activate the auth attribute as follows. (The default is BearerAuth.
```rust
use rupring::RupringDoc;
use rupring::RupringDto;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct GetUserResponse {
pub id: i32,
pub username: String,
Expand Down
16 changes: 8 additions & 8 deletions rupring_example/src/domains/users/dto.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use rupring::RupringDoc;
use rupring::RupringDto;
use serde::{Deserialize, Serialize};

pub mod foo {
use rupring::RupringDoc;
use rupring::RupringDto;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct Bar {
pub a: i32,
pub b: String,
}
}

#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct CreateUserRequest {
#[desc = "user name"]
#[example = "foobar"]
Expand All @@ -27,7 +27,7 @@ pub struct CreateUserRequest {
#[derive(Debug, Serialize, Deserialize)]
pub struct CreateUserResponse {}

#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct UpdateUserRequest {
#[serde(skip_serializing)]
#[path_param = "id"]
Expand Down Expand Up @@ -55,22 +55,22 @@ pub struct GetUserRequest {
pub id: i32,
}

#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct GetUserResponse {
pub id: i32,
pub username: String,
pub email: String,
}

#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct ListUsersRequest {
#[query = "offset"]
pub offset: i32,
#[query = "limit"]
pub limit: i32,
}

#[derive(Debug, Serialize, Deserialize, RupringDoc)]
#[derive(Debug, Serialize, Deserialize, RupringDto)]
pub struct ListUsersResponse {
pub users: Vec<GetUserResponse>,
pub total: i32,
Expand Down
2 changes: 1 addition & 1 deletion rupring_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rupring_macro"
version = "0.8.2"
version = "0.11.1"
edition = "2021"
description = "rupring macro"
license = "MIT"
Expand Down
6 changes: 3 additions & 3 deletions rupring_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ pub fn PatchMapping(attr: TokenStream, item: TokenStream) -> TokenStream {
}

/**
## What is RupringDoc?
## What is RupringDto?
- This is a macro used to automatically generate Swagger documents.
- It also provides functions such as Request Validation.
Expand All @@ -611,7 +611,7 @@ pub fn PatchMapping(attr: TokenStream, item: TokenStream) -> TokenStream {
9. ignore: Ignore the field.
*/
#[proc_macro_derive(
RupringDoc,
RupringDto,
attributes(
example,
description,
Expand All @@ -625,7 +625,7 @@ pub fn PatchMapping(attr: TokenStream, item: TokenStream) -> TokenStream {
ignore,
)
)]
pub fn derive_rupring_doc(item: TokenStream) -> TokenStream {
pub fn derive_rupring_dto(item: TokenStream) -> TokenStream {
let ast = syn::parse_macro_input!(item as syn::ItemStruct);
let struct_name = parse::find_struct_name(&ast);

Expand Down

0 comments on commit 4b51542

Please sign in to comment.