From 1f10c64c462acd0fc629c3ed439211413e7603fc Mon Sep 17 00:00:00 2001 From: Fankai Liu Date: Mon, 18 Sep 2023 22:12:58 +0800 Subject: [PATCH 1/3] Implement ToSchema for PhantomData --- crates/oapi/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/oapi/src/lib.rs b/crates/oapi/src/lib.rs index 09c79b694..048343e53 100644 --- a/crates/oapi/src/lib.rs +++ b/crates/oapi/src/lib.rs @@ -45,6 +45,7 @@ pub use salvo_oapi_macros::ToResponses; pub use salvo_oapi_macros::ToSchema; use std::collections::{BTreeMap, HashMap, LinkedList}; +use std::marker::PhantomData; use salvo_core::http::StatusError; use salvo_core::{extract::Extractible, writing}; @@ -258,6 +259,12 @@ impl ToSchema for Option { } } +impl ToSchema for PhantomData { + fn to_schema(_components: &mut Components) -> RefOr { + Schema::Object(Object::default()).into() + } +} + impl ToSchema for BTreeMap { fn to_schema(components: &mut Components) -> RefOr { schema!(#[inline]BTreeMap).into() From 2439838063203249f0f6f797de56c2ad3634a16d Mon Sep 17 00:00:00 2001 From: Fankai Liu Date: Sat, 28 Oct 2023 16:06:05 +0800 Subject: [PATCH 2/3] Add introduction of salvo-cli --- README.md | 12 ++++++++++++ README.zh-hans.md | 13 +++++++++++++ README.zh-hant.md | 12 ++++++++++++ 3 files changed, 37 insertions(+) diff --git a/README.md b/README.md index 3a4fadcff..e4c67f89e 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,18 @@ Salvo is an extremely simple and powerful Rust web backend framework. Only basic ## ⚡️ Quick Start You can view samples [here](https://github.com/salvo-rs/salvo/tree/main/examples), or view [official website](https://salvo.rs). +### 🛠️ Salvo-cli +Salvo CLI is a command-line tool that simplifies the creation of new Salvo projects, supporting templates for web APIs, websites, databases (including SQLite, PostgreSQL, and MySQL via SQLx, SeaORM, Diesel, Rbatis), and basic middleware. +You can use [salvo-cli](https://github.com/salvo-rs/salvo-cli) to create a new Salvo project: +#### install +```bash +cargo install salvo-cli +``` +#### create a new salvo project +```bash +salvo-cli new project_name +``` +___ ### Hello World with ACME and HTTP3 diff --git a/README.zh-hans.md b/README.zh-hans.md index 5ce5ef1c0..c5575f375 100644 --- a/README.zh-hans.md +++ b/README.zh-hans.md @@ -53,6 +53,19 @@ Salvo(赛风) 是一个极其简单且功能强大的 Rust Web 后端框架. 仅 你可以查看[实例代码](https://github.com/salvo-rs/salvo/tree/main/examples), 或者访问[官网](https://salvo.rs). +### 🛠️ Salvo-cli +Salvo CLI是一个命令行工具,可以简化创建新的Salvo项目的过程,支持Web API、网站、数据库(包括通过SQLx、SeaORM、Diesel、Rbatis支持的SQLite、PostgreSQL、MySQL)和基本的中间件的模板。 +你可以使用 [salvo-cli](https://github.com/salvo-rs/salvo-cli) 来创建一个新的 Salvo 项目: +#### 安装 +```bash +cargo install salvo-cli +``` +#### 创建一个salvo项目 +```bash +salvo-cli new project_name +``` +___ + ### Hello World with ACME and HTTP3 轻轻松松实现一个支持 ACME 自动获取证书的,支持 HTTP3 的服务器. diff --git a/README.zh-hant.md b/README.zh-hant.md index 765d21bec..3b60f1619 100644 --- a/README.zh-hant.md +++ b/README.zh-hant.md @@ -52,7 +52,19 @@ Salvo(賽風) 是一個極其簡單且功能強大的 Rust Web 後端框架. 僅 ## ⚡️ 快速開始 你可以查看[實例代碼](https://github.com/salvo-rs/salvo/tree/main/examples), 或者訪問[官網](https://salvo.rs). +### 🛠️ Salvo-cli +Salvo CLI是一個命令行工具,可以簡化創建新的Salvo項目的過程,支援Web API、網站、資料庫(包括透過SQLx、SeaORM、Diesel、Rbatis支援的SQLite、PostgreSQL、MySQL)和基本的中介軟體的模板。 +你可以使用 [salvo-cli](https://github.com/salvo-rs/salvo-cli) 来來創建一個新的 Salvo 項目: +#### 安裝 +```bash +cargo install salvo-cli +``` +#### 創建一個新的salvo項目 +```bash +salvo-cli new project_name +``` +___ ### Hello World with ACME and HTTP3 輕輕鬆鬆實現一個支持 ACME 自動獲取證書的,支持 HTTP3 的服務器. From a04ffd20cfd28beb3e766372b0490048f92154fc Mon Sep 17 00:00:00 2001 From: Fankai Liu Date: Tue, 21 Nov 2023 20:12:22 +0800 Subject: [PATCH 3/3] Optimization: take an uncommon name to avoid bugs with the same name as the user's --- crates/oapi-macros/src/endpoint/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/oapi-macros/src/endpoint/mod.rs b/crates/oapi-macros/src/endpoint/mod.rs index deace69e9..95b10d027 100644 --- a/crates/oapi-macros/src/endpoint/mod.rs +++ b/crates/oapi-macros/src/endpoint/mod.rs @@ -192,7 +192,7 @@ fn handle_fn(salvo: &Ident, oapi: &Ident, sig: &Signature) -> syn::Result<(Token let idv = id.to_token_stream().to_string(); let idv = idv.trim_start_matches('_'); extract_ts.push(quote! { - let #id: #ty = match <#ty as #salvo::Extractible>::extract_with_arg(req, #idv).await { + let #id: #ty = match <#ty as #salvo::Extractible>::extract_with_arg(__macro_generated_req, #idv).await { Ok(data) => { data }, @@ -223,7 +223,7 @@ fn handle_fn(salvo: &Ident, oapi: &Ident, sig: &Signature) -> syn::Result<(Token if sig.asyncness.is_none() { quote! { #[inline] - async fn handle(&self, req: &mut #salvo::Request, depot: &mut #salvo::Depot, res: &mut #salvo::Response, ctrl: &mut #salvo::FlowCtrl) { + async fn handle(&self, __macro_generated_req: &mut #salvo::Request, depot: &mut #salvo::Depot, res: &mut #salvo::Response, ctrl: &mut #salvo::FlowCtrl) { #(#extract_ts)* Self::#name(#(#call_args),*) } @@ -231,7 +231,7 @@ fn handle_fn(salvo: &Ident, oapi: &Ident, sig: &Signature) -> syn::Result<(Token } else { quote! { #[inline] - async fn handle(&self, req: &mut #salvo::Request, depot: &mut #salvo::Depot, res: &mut #salvo::Response, ctrl: &mut #salvo::FlowCtrl) { + async fn handle(&self, __macro_generated_req: &mut #salvo::Request, depot: &mut #salvo::Depot, res: &mut #salvo::Response, ctrl: &mut #salvo::FlowCtrl) { #(#extract_ts)* Self::#name(#(#call_args),*).await } @@ -245,17 +245,17 @@ fn handle_fn(salvo: &Ident, oapi: &Ident, sig: &Signature) -> syn::Result<(Token if sig.asyncness.is_none() { quote! { #[inline] - async fn handle(&self, req: &mut #salvo::Request, depot: &mut #salvo::Depot, res: &mut #salvo::Response, ctrl: &mut #salvo::FlowCtrl) { + async fn handle(&self, __macro_generated_req: &mut #salvo::Request, depot: &mut #salvo::Depot, res: &mut #salvo::Response, ctrl: &mut #salvo::FlowCtrl) { #(#extract_ts)* - #salvo::Writer::write(Self::#name(#(#call_args),*), req, depot, res).await; + #salvo::Writer::write(Self::#name(#(#call_args),*), __macro_generated_req, depot, res).await; } } } else { quote! { #[inline] - async fn handle(&self, req: &mut #salvo::Request, depot: &mut #salvo::Depot, res: &mut #salvo::Response, ctrl: &mut #salvo::FlowCtrl) { + async fn handle(&self, __macro_generated_req: &mut #salvo::Request, depot: &mut #salvo::Depot, res: &mut #salvo::Response, ctrl: &mut #salvo::FlowCtrl) { #(#extract_ts)* - #salvo::Writer::write(Self::#name(#(#call_args),*).await, req, depot, res).await; + #salvo::Writer::write(Self::#name(#(#call_args),*).await, __macro_generated_req, depot, res).await; } } }