Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !5677

[Rust Client] Update Rust generator

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/MikailBag/rust-update-5.0 into 5.0.x 5 years ago
  • Overview 0
  • Commits 4
  • Pipelines 0
  • Changes 87

Created by: MikailBag

Now generated client depends on hyper 0.13 and tokio 0.2. It means client can be easily used in modern async/await based projects.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language. @frol @richardwhiuk. (Should I ping all?)

P.S. It seems that some files are included by error (e.g. docs). How should I avoid it?

Compare
  • 5.0.x (base)

and
  • latest version
    873a4791
    4 commits, 2 years ago

87 files
+ 2813
- 571

    Preferences

    File browser
    Compare changes
modules/openapi-g‎enerator/src/main‎
java/org/openapitoo‎ls/codegen/languages‎
RustClientC‎odegen.java‎ +3 -2
resourc‎es/rust‎
hy‎per‎
api.mu‎stache‎ +9 -8
api_mod.‎mustache‎ +31 -3
client.‎mustache‎ +1 -1
configurati‎on.mustache‎ +4 -4
Cargo.m‎ustache‎ +8 -12
lib.mu‎stache‎ +1 -0
reque‎st.rs‎ +105 -77
samples/client‎/petstore/rust‎
.openapi-‎generator‎
VER‎SION‎ +1 -1
do‎cs‎
ApiResp‎onse.md‎ +13 -0
Categ‎ory.md‎ +12 -0
InlineO‎bject.md‎ +2 -2
InlineOb‎ject1.md‎ +2 -2
Orde‎r.md‎ +16 -0
Pet‎.md‎ +16 -0
PetA‎pi.md‎ +251 -0
Store‎Api.md‎ +127 -0
Tag‎.md‎ +12 -0
Use‎r.md‎ +18 -0
UserA‎pi.md‎ +245 -0
hy‎per‎
fileResp‎onseTest‎
.openapi-‎generator‎
VER‎SION‎ +1 -1
do‎cs‎
Defaul‎tApi.md‎ +1 -1
s‎rc‎
ap‎is‎
clie‎nt.rs‎ +1 -1
configur‎ation.rs‎ +4 -4
default‎_api.rs‎ +8 -7
mod‎.rs‎ +31 -3
reque‎st.rs‎ +105 -77
lib‎.rs‎ +1 -0
Cargo‎.toml‎ +8 -10
READ‎ME.md‎ +1 -1
pets‎tore‎
.openapi-‎generator‎
VER‎SION‎ +1 -1
do‎cs‎
PetA‎pi.md‎ +8 -8
Store‎Api.md‎ +4 -4
UserA‎pi.md‎ +8 -8
s‎rc‎
ap‎is‎
clie‎nt.rs‎ +1 -1
configur‎ation.rs‎ +4 -4
mod‎.rs‎ +31 -3
pet_a‎pi.rs‎ +44 -36
reque‎st.rs‎ +105 -77
store_‎api.rs‎ +23 -19
user_‎api.rs‎ +43 -35
lib‎.rs‎ +1 -0
Cargo‎.toml‎ +8 -10
READ‎ME.md‎ +20 -20
rust‎-test‎
.openapi-‎generator‎
VER‎SION‎ +1 -1
do‎cs‎
Defaul‎tApi.md‎ +1 -1
s‎rc‎
ap‎is‎
clie‎nt.rs‎ +1 -1
configur‎ation.rs‎ +4 -4
default‎_api.rs‎ +8 -7
mod‎.rs‎ +31 -3
reque‎st.rs‎ +105 -77
lib‎.rs‎ +1 -0
Cargo‎.toml‎ +8 -10
READ‎ME.md‎ +1 -1
req‎west‎
fileResp‎onseTest‎
.openapi-‎generator‎
VER‎SION‎ +1 -1
s‎rc‎
lib‎.rs‎ +1 -0
Cargo‎.toml‎ +4 -5
pets‎tore‎
.openapi-‎generator‎
VER‎SION‎ +1 -1
s‎rc‎
lib‎.rs‎ +1 -0
Cargo‎.toml‎ +4 -5
rust‎-test‎
.openapi-‎generator‎
VER‎SION‎ +1 -1
s‎rc‎
lib‎.rs‎ +1 -0
Cargo‎.toml‎ +4 -5
s‎rc‎
ap‎is‎
clie‎nt.rs‎ +35 -0
configur‎ation.rs‎ +41 -0
mod‎.rs‎ +90 -0
pet_a‎pi.rs‎ +150 -0
reque‎st.rs‎ +267 -0
store_‎api.rs‎ +84 -0
user_‎api.rs‎ +156 -0
mod‎els‎
api_res‎ponse.rs‎ +36 -0
categ‎ory.rs‎ +33 -0
inline_o‎bject.rs‎ +2 -1
inline_ob‎ject_1.rs‎ +2 -1
mod‎.rs‎ +16 -0
orde‎r.rs‎ +56 -0
pet‎.rs‎ +56 -0
tag‎.rs‎ +33 -0
use‎r.rs‎ +52 -0
lib‎.rs‎ +12 -0
.giti‎gnore‎ +2 -1
.openapi-gen‎erator-ignore‎ +23 -0
.trav‎is.yml‎ +1 -0
Cargo‎.toml‎ +15 -2
READ‎ME.md‎ +70 -0
git_p‎ush.sh‎ +58 -0
tes‎t.sh‎ +5 -0
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java
+ 3
- 2
  • View file @ 873a4791


@@ -456,9 +456,10 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
@SuppressWarnings("unchecked")
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
for (CodegenOperation operation : operations) {
// http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put)
// http method verb conversion, depending on client library (e.g. Hyper: PUT => PUT, Reqwest: PUT => put)
if (HYPER_LIBRARY.equals(getLibrary())) {
operation.httpMethod = StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
// question to reviewer - is this toUpperCase() no-op?
operation.httpMethod = operation.httpMethod.toUpperCase(Locale.ROOT);
} else if (REQWEST_LIBRARY.equals(getLibrary())) {
operation.httpMethod = operation.httpMethod.toLowerCase(Locale.ROOT);
}
modules/openapi-generator/src/main/resources/rust/hyper/api.mustache
+ 9
- 8
  • View file @ 873a4791


@@ -11,11 +11,11 @@ use futures::Future;
use super::{Error, configuration};
use super::request as __internal_request;
pub struct {{{classname}}}Client<C: hyper::client::Connect> {
pub struct {{{classname}}}Client<C: hyper::client::connect::Connect + Clone + Send + Sync + 'static> {
configuration: Rc<configuration::Configuration<C>>,
}
impl<C: hyper::client::Connect> {{{classname}}}Client<C> {
impl<C: hyper::client::connect::Connect + Clone + Send + Sync + 'static> {{{classname}}}Client<C> {
pub fn new(configuration: Rc<configuration::Configuration<C>>) -> {{{classname}}}Client<C> {
{{{classname}}}Client {
configuration,
@@ -26,15 +26,15 @@ impl<C: hyper::client::Connect> {{{classname}}}Client<C> {
pub trait {{{classname}}} {
{{#operations}}
{{#operation}}
fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Box<dyn Future<Item = {{^returnType}}(){{/returnType}}{{#returnType}}{{{returnType}}}{{/returnType}}, Error = Error<serde_json::Value>>>;
fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Box<dyn Future<Output = Result<{{^returnType}}(){{/returnType}}{{#returnType}}{{{.}}}{{/returnType}}, Error<serde_json::Value>>>+Unpin>;
{{/operation}}
{{/operations}}
}
impl<C: hyper::client::Connect>{{{classname}}} for {{{classname}}}Client<C> {
impl<C: hyper::client::connect::Connect + Clone + Send + Sync + 'static>{{{classname}}} for {{{classname}}}Client<C> {
{{#operations}}
{{#operation}}
fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Box<dyn Future<Item = {{^returnType}}(){{/returnType}}{{#returnType}}{{{.}}}{{/returnType}}, Error = Error<serde_json::Value>>> {
fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Box<dyn Future<Output = Result<{{^returnType}}(){{/returnType}}{{#returnType}}{{{.}}}{{/returnType}}, Error<serde_json::Value>>> + Unpin> {
let mut req = __internal_request::Request::new(hyper::Method::{{{httpMethod}}}, "{{{path}}}".to_string())
{{#hasAuthMethods}}
{{#authMethods}}
@@ -119,13 +119,13 @@ impl<C: hyper::client::Connect>{{{classname}}} for {{{classname}}}Client<C> {
{{/isNullable}}
{{#isNullable}}
match {{{paramName}}} {
Some(param_value) => { req = req.with_form_param("{{{baseName}}}".to_string(), unimplemented!()); },
Some(_param_value) => { req = req.with_form_param("{{{baseName}}}".to_string(), unimplemented!()); },
None => { req = req.with_form_param("{{{baseName}}}".to_string(), unimplemented!()); },
}
{{/isNullable}}
{{/required}}
{{^required}}
if let Some(param_value) = {{{paramName}}} {
if let Some(_param_value) = {{{paramName}}} {
req = req.with_form_param("{{{baseName}}}".to_string(), unimplemented!());
}
{{/required}}
@@ -159,7 +159,8 @@ impl<C: hyper::client::Connect>{{{classname}}} for {{{classname}}}Client<C> {
req = req.returns_nothing();
{{/returnType}}
req.execute(self.configuration.borrow())
// TODO: do not box here
Box::new(req.execute(self.configuration.borrow()))
}
{{/operation}}
modules/openapi-generator/src/main/resources/rust/hyper/api_mod.mustache
+ 31
- 3
  • View file @ 873a4791


@@ -4,12 +4,34 @@ use serde_json;
#[derive(Debug)]
pub enum Error<T> {
UriError(hyper::error::UriError),
Http(http::Error),
Hyper(hyper::Error),
Serde(serde_json::Error),
ApiError(ApiError<T>),
}
impl<T: std::fmt::Debug> std::error::Error for Error<T> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Http(inner) => Some(inner),
Error::Hyper(inner) => Some(inner),
Error::Serde(inner) => Some(inner),
Error::ApiError(_) => None
}
}
}
impl<T: std::fmt::Debug> std::fmt::Display for Error<T> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::Http(inner) => write!(f, "query construction error: {}", inner),
Error::Hyper(inner) => write!(f, "transport error: {}", inner),
Error::Serde(inner) => write!(f, "serde error: {}", inner),
Error::ApiError(inner) => write!(f, "api error: {:?}", inner),
}
}
}
#[derive(Debug)]
pub struct ApiError<T> {
pub code: hyper::StatusCode,
@@ -39,13 +61,19 @@ impl<'de, T> From<(hyper::StatusCode, &'de [u8])> for Error<T>
impl<T> From<hyper::Error> for Error<T> {
fn from(e: hyper::Error) -> Self {
return Error::Hyper(e)
Error::Hyper(e)
}
}
impl<T> From<serde_json::Error> for Error<T> {
fn from(e: serde_json::Error) -> Self {
return Error::Serde(e)
Error::Serde(e)
}
}
impl<T> From<http::Error> for Error<T> {
fn from(e: http::Error) -> Self {
Error::Http(e)
}
}
modules/openapi-generator/src/main/resources/rust/hyper/client.mustache
+ 1
- 1
  • View file @ 873a4791


@@ -18,7 +18,7 @@ pub struct APIClient {
}
impl APIClient {
pub fn new<C: hyper::client::Connect>(configuration: Configuration<C>) -> APIClient {
pub fn new<C: hyper::client::connect::Connect + Clone + Send + Sync + 'static>(configuration: Configuration<C>) -> APIClient {
let rc = Rc::new(configuration);
APIClient {
modules/openapi-generator/src/main/resources/rust/hyper/configuration.mustache
+ 4
- 4
  • View file @ 873a4791


{{>partial_header}}
use hyper;
pub struct Configuration<C: hyper::client::Connect> {
pub struct Configuration<C: hyper::client::connect::Connect + 'static> {
pub base_path: String,
pub user_agent: Option<String>,
pub client: hyper::client::Client<C>,
pub client: hyper::client::Client<C, hyper::Body>,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub api_key: Option<ApiKey>,
@@ -18,8 +18,8 @@ pub struct ApiKey {
pub key: String,
}
impl<C: hyper::client::Connect> Configuration<C> {
pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
impl<C: hyper::client::connect::Connect + 'static> Configuration<C> {
pub fn new(client: hyper::client::Client<C, hyper::Body>) -> Configuration<C> {
Configuration {
base_path: "{{{basePath}}}".to_owned(),
user_agent: {{#httpUserAgent}}Some("{{{.}}}".to_owned()){{/httpUserAgent}}{{^httpUserAgent}}Some("OpenAPI-Generator/{{{version}}}/rust".to_owned()){{/httpUserAgent}},
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: PyAV-Org/PyAV!287
Source branch: github/fork/MikailBag/rust-update-5.0

Menu

Explore Projects Groups Snippets