From 8cc2775fe4dbe9625b9ec2b6c9e1d07993a86649 Mon Sep 17 00:00:00 2001 From: GW_MC <72297530+GWMCwing@users.noreply.github.com> Date: Sun, 28 Dec 2025 16:08:29 +0800 Subject: [PATCH] feat: auto format generated code, and ignore clippy lint in agent-client --- justfile | 6 + public/agent-client/Cargo.toml | 6 + public/agent-client/src/apis/configuration.rs | 5 +- public/agent-client/src/apis/mod.rs | 23 ++- .../agent-client/src/apis/nginx_agent_api.rs | 181 +++++++++++------- public/agent-client/src/lib.rs | 2 +- public/agent-client/src/models/status_resp.rs | 7 +- .../src/models/validate_and_reload_body.rs | 3 +- .../src/models/validate_and_reload_resp.rs | 8 +- .../agent-client/src/models/validate_body.rs | 3 +- .../src/models/write_config_body.rs | 3 +- 11 files changed, 149 insertions(+), 98 deletions(-) diff --git a/justfile b/justfile index c71224b..214e543 100644 --- a/justfile +++ b/justfile @@ -67,6 +67,12 @@ generate-agent-client: --additional-properties=supportMultipleResponses=true \ --additional-properties=topLevelApiClient=true \ --additional-properties=useSingleRequestParameter=true + # format generated code + cd public/agent-client && \ + cargo fmt + # append lint allows/forbids to the end of Cargo.toml to disable warnings in generated code and forbid unsafe code + cd public/agent-client && \ + echo '\n[lints.clippy]\nall = "allow"\n[lints.rust]\nunsafe_code = "forbid"\n' >> Cargo.toml generate-all: generate-entity generate-openapi generate-agent-client diff --git a/public/agent-client/Cargo.toml b/public/agent-client/Cargo.toml index 7f79316..d02f475 100644 --- a/public/agent-client/Cargo.toml +++ b/public/agent-client/Cargo.toml @@ -19,3 +19,9 @@ default = ["native-tls"] native-tls = ["reqwest/native-tls"] rustls-tls = ["reqwest/rustls-tls"] mockall = ["dep:mockall"] + +[lints.clippy] +all = "allow" +[lints.rust] +unsafe_code = "forbid" + diff --git a/public/agent-client/src/apis/configuration.rs b/public/agent-client/src/apis/configuration.rs index 819dc17..7fc9ec4 100644 --- a/public/agent-client/src/apis/configuration.rs +++ b/public/agent-client/src/apis/configuration.rs @@ -4,12 +4,10 @@ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 0.1.0 - * + * * Generated by: https://openapi-generator.tech */ - - #[derive(Debug, Clone)] pub struct Configuration { pub base_path: String, @@ -29,7 +27,6 @@ pub struct ApiKey { pub key: String, } - impl Configuration { pub fn new() -> Configuration { Configuration::default() diff --git a/public/agent-client/src/apis/mod.rs b/public/agent-client/src/apis/mod.rs index 188ea6a..f596e46 100644 --- a/public/agent-client/src/apis/mod.rs +++ b/public/agent-client/src/apis/mod.rs @@ -16,7 +16,7 @@ pub enum Error { ResponseError(ResponseContent), } -impl fmt::Display for Error { +impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (module, e) = match self { Error::Reqwest(e) => ("reqwest", e.to_string()), @@ -28,7 +28,7 @@ impl fmt::Display for Error { } } -impl error::Error for Error { +impl error::Error for Error { fn source(&self) -> Option<&(dyn error::Error + 'static)> { Some(match self { Error::Reqwest(e) => e, @@ -39,19 +39,19 @@ impl error::Error for Error { } } -impl From for Error { +impl From for Error { fn from(e: reqwest::Error) -> Self { Error::Reqwest(e) } } -impl From for Error { +impl From for Error { fn from(e: serde_json::Error) -> Self { Error::Serde(e) } } -impl From for Error { +impl From for Error { fn from(e: std::io::Error) -> Self { Error::Io(e) } @@ -78,8 +78,10 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String value, )); } - }, - serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), + } + serde_json::Value::String(s) => { + params.push((format!("{}[{}]", prefix, key), s.clone())) + } _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), } } @@ -96,7 +98,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String enum ContentType { Json, Text, - Unsupported(String) + Unsupported(String), } impl From<&str> for ContentType { @@ -128,7 +130,9 @@ pub struct ApiClient { impl ApiClient { pub fn new(configuration: Arc) -> Self { Self { - nginx_agent_api: Box::new(nginx_agent_api::NginxAgentApiClient::new(configuration.clone())), + nginx_agent_api: Box::new(nginx_agent_api::NginxAgentApiClient::new( + configuration.clone(), + )), } } } @@ -159,4 +163,3 @@ impl Api for MockApiClient { &self.nginx_agent_api_mock } } - diff --git a/public/agent-client/src/apis/nginx_agent_api.rs b/public/agent-client/src/apis/nginx_agent_api.rs index 057870d..28421a3 100644 --- a/public/agent-client/src/apis/nginx_agent_api.rs +++ b/public/agent-client/src/apis/nginx_agent_api.rs @@ -4,48 +4,55 @@ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 0.1.0 - * + * * Generated by: https://openapi-generator.tech */ - +use super::{configuration, Error}; +use crate::apis::ContentType; +use crate::{apis::ResponseContent, models}; use async_trait::async_trait; #[cfg(feature = "mockall")] use mockall::automock; use reqwest; +use serde::{de::Error as _, Deserialize, Serialize}; use std::sync::Arc; -use serde::{Deserialize, Serialize, de::Error as _}; -use crate::{apis::ResponseContent, models}; -use super::{Error, configuration}; -use crate::apis::ContentType; #[cfg_attr(feature = "mockall", automock)] #[async_trait] pub trait NginxAgentApi: Send + Sync { - /// GET /status /// - /// - async fn status(&self, ) -> Result, Error>; + /// + async fn status(&self) -> Result, Error>; /// POST /validate /// - /// - async fn validate(&self, params: ValidateParams ) -> Result, Error>; + /// + async fn validate( + &self, + params: ValidateParams, + ) -> Result, Error>; /// POST /validate_and_reload /// - /// - async fn validate_and_reload(&self, params: ValidateAndReloadParams ) -> Result, Error>; + /// + async fn validate_and_reload( + &self, + params: ValidateAndReloadParams, + ) -> Result, Error>; /// POST /write_config /// - /// - async fn write_config(&self, params: WriteConfigParams ) -> Result, Error>; + /// + async fn write_config( + &self, + params: WriteConfigParams, + ) -> Result, Error>; } pub struct NginxAgentApiClient { - configuration: Arc + configuration: Arc, } impl NginxAgentApiClient { @@ -54,40 +61,38 @@ impl NginxAgentApiClient { } } - /// struct for passing parameters to the method [`NginxAgentApi::validate`] #[derive(Clone, Debug)] pub struct ValidateParams { - pub validate_body: models::ValidateBody + pub validate_body: models::ValidateBody, } /// struct for passing parameters to the method [`NginxAgentApi::validate_and_reload`] #[derive(Clone, Debug)] pub struct ValidateAndReloadParams { - pub validate_and_reload_body: models::ValidateAndReloadBody + pub validate_and_reload_body: models::ValidateAndReloadBody, } /// struct for passing parameters to the method [`NginxAgentApi::write_config`] #[derive(Clone, Debug)] pub struct WriteConfigParams { - pub write_config_body: models::WriteConfigBody + pub write_config_body: models::WriteConfigBody, } - #[async_trait] impl NginxAgentApi for NginxAgentApiClient { - async fn status(&self, ) -> Result, Error> { - - + async fn status(&self) -> Result, Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; let local_var_uri_str = format!("{}/status", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = local_var_req_builder + .header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } let local_var_req = local_var_req_builder.build()?; @@ -97,32 +102,43 @@ impl NginxAgentApi for NginxAgentApiClient { let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_result = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Ok(local_var_result) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } - async fn validate(&self, params: ValidateParams ) -> Result, Error> { - - let ValidateParams { - validate_body, - } = params; - + async fn validate( + &self, + params: ValidateParams, + ) -> Result, Error> { + let ValidateParams { validate_body } = params; let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; let local_var_uri_str = format!("{}/validate", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = local_var_req_builder + .header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } local_var_req_builder = local_var_req_builder.json(&validate_body); @@ -133,32 +149,46 @@ impl NginxAgentApi for NginxAgentApiClient { let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_result = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Ok(local_var_result) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } - async fn validate_and_reload(&self, params: ValidateAndReloadParams ) -> Result, Error> { - + async fn validate_and_reload( + &self, + params: ValidateAndReloadParams, + ) -> Result, Error> { let ValidateAndReloadParams { validate_and_reload_body, } = params; - let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/validate_and_reload", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let local_var_uri_str = + format!("{}/validate_and_reload", local_var_configuration.base_path); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = local_var_req_builder + .header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } local_var_req_builder = local_var_req_builder.json(&validate_and_reload_body); @@ -169,32 +199,43 @@ impl NginxAgentApi for NginxAgentApiClient { let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_result = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Ok(local_var_result) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } - async fn write_config(&self, params: WriteConfigParams ) -> Result, Error> { - - let WriteConfigParams { - write_config_body, - } = params; - + async fn write_config( + &self, + params: WriteConfigParams, + ) -> Result, Error> { + let WriteConfigParams { write_config_body } = params; let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; let local_var_uri_str = format!("{}/write_config", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = local_var_req_builder + .header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } local_var_req_builder = local_var_req_builder.json(&write_config_body); @@ -205,16 +246,25 @@ impl NginxAgentApi for NginxAgentApiClient { let local_var_content = local_var_resp.text().await?; if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_result = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Ok(local_var_result) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } - } /// struct for typed successes of method [`NginxAgentApi::status`] @@ -277,4 +327,3 @@ pub enum WriteConfigError { Status500(serde_json::Value), UnknownValue(serde_json::Value), } - diff --git a/public/agent-client/src/lib.rs b/public/agent-client/src/lib.rs index edc482e..cfbd3aa 100644 --- a/public/agent-client/src/lib.rs +++ b/public/agent-client/src/lib.rs @@ -1,9 +1,9 @@ #![allow(unused_imports)] #![allow(clippy::too_many_arguments)] -extern crate serde_repr; extern crate serde; extern crate serde_json; +extern crate serde_repr; extern crate url; pub mod apis; diff --git a/public/agent-client/src/models/status_resp.rs b/public/agent-client/src/models/status_resp.rs index a6ae9c5..08800d5 100644 --- a/public/agent-client/src/models/status_resp.rs +++ b/public/agent-client/src/models/status_resp.rs @@ -4,7 +4,7 @@ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 0.1.0 - * + * * Generated by: https://openapi-generator.tech */ @@ -19,9 +19,6 @@ pub struct StatusResp { impl StatusResp { pub fn new(ok: bool) -> StatusResp { - StatusResp { - ok, - } + StatusResp { ok } } } - diff --git a/public/agent-client/src/models/validate_and_reload_body.rs b/public/agent-client/src/models/validate_and_reload_body.rs index 94f4d9a..c488fd2 100644 --- a/public/agent-client/src/models/validate_and_reload_body.rs +++ b/public/agent-client/src/models/validate_and_reload_body.rs @@ -4,7 +4,7 @@ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 0.1.0 - * + * * Generated by: https://openapi-generator.tech */ @@ -27,4 +27,3 @@ impl ValidateAndReloadBody { } } } - diff --git a/public/agent-client/src/models/validate_and_reload_resp.rs b/public/agent-client/src/models/validate_and_reload_resp.rs index a982edd..cd52e9d 100644 --- a/public/agent-client/src/models/validate_and_reload_resp.rs +++ b/public/agent-client/src/models/validate_and_reload_resp.rs @@ -4,7 +4,7 @@ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 0.1.0 - * + * * Generated by: https://openapi-generator.tech */ @@ -21,10 +21,6 @@ pub struct ValidateAndReloadResp { impl ValidateAndReloadResp { pub fn new(rc: i32, ro: String) -> ValidateAndReloadResp { - ValidateAndReloadResp { - rc, - ro, - } + ValidateAndReloadResp { rc, ro } } } - diff --git a/public/agent-client/src/models/validate_body.rs b/public/agent-client/src/models/validate_body.rs index 1ad01b4..77a1076 100644 --- a/public/agent-client/src/models/validate_body.rs +++ b/public/agent-client/src/models/validate_body.rs @@ -4,7 +4,7 @@ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 0.1.0 - * + * * Generated by: https://openapi-generator.tech */ @@ -27,4 +27,3 @@ impl ValidateBody { } } } - diff --git a/public/agent-client/src/models/write_config_body.rs b/public/agent-client/src/models/write_config_body.rs index b9b0d6d..286cce9 100644 --- a/public/agent-client/src/models/write_config_body.rs +++ b/public/agent-client/src/models/write_config_body.rs @@ -4,7 +4,7 @@ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 0.1.0 - * + * * Generated by: https://openapi-generator.tech */ @@ -30,4 +30,3 @@ impl WriteConfigBody { } } } -