Closed
Description
Description
The generated client code for rust has a few problems:
- It uses the deprecated futures v0.1, when it should use the newer futures v0.3
- The return types of the api methods aren't strongly typed:
Box<dyn Future<Item = ::std::collections::HashMap<String, serde_json::Value>, Error = Error<serde_json::Value>>>
The models are properly generated but the return type of the methods don't reference the generated models at all.
- Some models aren't generated at all when defined as such in the schema:
openapi-generator version
openapi-generator-cli 5.0.0-SNAPSHOT
commit : 46216cd
built : 2020-04-28T13:03:54Z
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
OpenAPI declaration file content or url
https://api.slack.com/specs/openapi/v2/slack_web.json
Command line used for generation
java -jar ~/Downloads/openapi.jar generate -g rust -i https://api.slack.com/specs/openapi/v2/slack_web.json -o rust
Steps to reproduce
run the command above
Related issues/PRs
Suggest a fix/enhancement
- The generated client code should use the
reqwest
crate with async/await. - Change the api for methods from:
pub trait UsersApi {
fn users_conversations(&self, params: UsersConversationsParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_delete_photo(&self, params: UsersDeletePhotoParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_get_presence(&self, params: UsersGetPresenceParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_identity(&self, params: UsersIdentityParams) -> Result<serde_json::Value, Error>;
fn users_info(&self, params: UsersInfoParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_list(&self, params: UsersListParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_lookup_by_email(&self, params: UsersLookupByEmailParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_profile_get(&self, params: UsersProfileGetParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_profile_set(&self, params: UsersProfileSetParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_set_active(&self, params: UsersSetActiveParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_set_photo(&self, params: UsersSetPhotoParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
fn users_set_presence(&self, params: UsersSetPresenceParams) -> Result<::std::collections::HashMap<String, serde_json::Value>, Error>;
}
to:
pub async fn conversations(config: &Configuration, params: UsersConversationsParams) -> Result;
pub async fn delete_photo(config: &Configuration, params: UsersDeletePhotoParams) -> Result;
pub async fn get_presence(config: &Configuration, params: UsersGetPresenceParams) -> Result;
pub async fn identity(config: &Configuration, params: UsersIdentityParams) -> Result;
pub async fn info(config: &Configuration, params: UsersInfoParams) -> Result;
pub async fn list(config: &Configuration, params: UsersListParams) -> Result;
pub async fn lookup_by_email(config: &Configuration, params: UsersLookupByEmailParams) -> Result;
pub async fn profile_get(config: &configuration, params: UsersProfileGetParams) -> Result;
pub async fn profile_set(config: &Configuration, params: UsersProfileSetParams) -> Result;
pub async fn set_active(config: &Configuration, params: UsersSetActiveParams) -> Result;
pub async fn set_photo(config: &Configuration, params: UsersSetPhotoParams) -> Result;
pub async fn set_presence(config: &Configuration, params: UsersSetPresenceParams) -> Result;
- Error and sucess return types should be strongly typed.
- Instead of making each param an argument on the method, the generated client code should aggregate the params into a struct that can be passed to the api method. e.g
Instead of:
fn users_list(&self, cursor: Option<&str>, token: Option<&str>, limit: Option<i32>, include_locale: Option<bool>)
do:
#[derive(Default)]
struct UsersListParams {
cursor: Option<&str>,
token: Option<&str>,
limit: Option<i32>,
include_locale: Option<bool>,
}
fn users_list(&self, params: UsersListParams)
I'm willing to sponsor work on this issue to the tune of $500.
cc @wing328