diff --git a/bin/configs/rust-reqwest-object-query-param.yaml b/bin/configs/rust-reqwest-object-query-param.yaml new file mode 100644 index 00000000000..fb2f687219a --- /dev/null +++ b/bin/configs/rust-reqwest-object-query-param.yaml @@ -0,0 +1,9 @@ +generatorName: rust +outputDir: samples/client/others/rust/reqwest/object-query-param +library: reqwest +inputSpec: modules/openapi-generator/src/test/resources/3_0/objectQueryParam.yaml +templateDir: modules/openapi-generator/src/main/resources/rust +validateSpec: "false" +additionalProperties: + supportAsync: "true" + packageName: object-query-param-reqwest diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index e9cfabc5599..c7133f867b4 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -155,7 +155,13 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{/isArray}} {{^isArray}} {{^isNullable}} + {{#isModel}} + let params = crate::apis::parse_flat_object(&serde_json::to_value({{{vendorExtensions.x-rust-param-identifier}}})?); + req_builder = req_builder.query(¶ms); + {{/isModel}} + {{^isModel}} req_builder = req_builder.query(&[("{{{baseName}}}", &{{{vendorExtensions.x-rust-param-identifier}}}.to_string())]); + {{/isModel}} {{/isNullable}} {{#isNullable}} {{#isDeepObject}} @@ -165,9 +171,17 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: }; {{/isDeepObject}} {{^isDeepObject}} + {{#isModel}} + if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { + let params = crate::apis::parse_flat_object(&serde_json::to_value({{{vendorExtensions.x-rust-param-identifier}}})?); + req_builder = req_builder.query(¶ms); + }; + {{/isModel}} + {{^isModel}} if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]); }; + {{/isModel}} {{/isDeepObject}} {{/isNullable}} {{/isArray}} @@ -186,7 +200,13 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: req_builder = req_builder.query(¶ms); {{/isDeepObject}} {{^isDeepObject}} + {{#isModel}} + let params = crate::apis::parse_flat_object(&serde_json::to_value(param_value)?); + req_builder = req_builder.query(¶ms); + {{/isModel}} + {{^isModel}} req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]); + {{/isModel}} {{/isDeepObject}} {{/isArray}} } diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache index 4d5df28e9bb..dc0797cf3bd 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache @@ -105,6 +105,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/modules/openapi-generator/src/test/resources/3_0/objectQueryParam.yaml b/modules/openapi-generator/src/test/resources/3_0/objectQueryParam.yaml index c3e7469a199..003c9a49227 100644 --- a/modules/openapi-generator/src/test/resources/3_0/objectQueryParam.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/objectQueryParam.yaml @@ -14,6 +14,7 @@ paths: parameters: - in: query name: pageQuery + required: true schema: type: object properties: @@ -22,4 +23,13 @@ paths: format: int32 limit: type: integer - format: int32 \ No newline at end of file + format: int32 + - in: query + name: notRequired + required: false + schema: + type: object + properties: + foobar: + type: integer + format: int32 diff --git a/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs b/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs index fdcc89b3606..a046b8e201e 100644 --- a/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest-regression-16119/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs index fdcc89b3606..a046b8e201e 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs b/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs index fdcc89b3606..a046b8e201e 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/composed-oneof/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs b/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs index fdcc89b3606..a046b8e201e 100644 --- a/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/emptyObject/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/others/rust/reqwest/object-query-param/.gitignore b/samples/client/others/rust/reqwest/object-query-param/.gitignore new file mode 100644 index 00000000000..6aa106405a4 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/.gitignore @@ -0,0 +1,3 @@ +/target/ +**/*.rs.bk +Cargo.lock diff --git a/samples/client/others/rust/reqwest/object-query-param/.openapi-generator-ignore b/samples/client/others/rust/reqwest/object-query-param/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/others/rust/reqwest/object-query-param/.openapi-generator/FILES b/samples/client/others/rust/reqwest/object-query-param/.openapi-generator/FILES new file mode 100644 index 00000000000..9ec011cd3ab --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/.openapi-generator/FILES @@ -0,0 +1,15 @@ +.gitignore +.travis.yml +Cargo.toml +README.md +docs/DefaultApi.md +docs/ListNotRequiredParameter.md +docs/ListPageQueryParameter.md +git_push.sh +src/apis/configuration.rs +src/apis/default_api.rs +src/apis/mod.rs +src/lib.rs +src/models/list_not_required_parameter.rs +src/models/list_page_query_parameter.rs +src/models/mod.rs diff --git a/samples/client/others/rust/reqwest/object-query-param/.openapi-generator/VERSION b/samples/client/others/rust/reqwest/object-query-param/.openapi-generator/VERSION new file mode 100644 index 00000000000..4c631cf217a --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.14.0-SNAPSHOT diff --git a/samples/client/others/rust/reqwest/object-query-param/.travis.yml b/samples/client/others/rust/reqwest/object-query-param/.travis.yml new file mode 100644 index 00000000000..22761ba7ee1 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/samples/client/others/rust/reqwest/object-query-param/Cargo.toml b/samples/client/others/rust/reqwest/object-query-param/Cargo.toml new file mode 100644 index 00000000000..804300c3832 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "object-query-param-reqwest" +version = "1.0.0" +authors = ["OpenAPI Generator team and contributors"] +description = "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)" +license = "Apache-2.0" +edition = "2021" + +[dependencies] +serde = { version = "^1.0", features = ["derive"] } +serde_json = "^1.0" +serde_repr = "^0.1" +url = "^2.5" +reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] } diff --git a/samples/client/others/rust/reqwest/object-query-param/README.md b/samples/client/others/rust/reqwest/object-query-param/README.md new file mode 100644 index 00000000000..b77e5809be9 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/README.md @@ -0,0 +1,47 @@ +# Rust API client for object-query-param-reqwest + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + +## Overview + +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: 1.0.0 +- Generator version: 7.14.0-SNAPSHOT +- Build package: `org.openapitools.codegen.languages.RustClientCodegen` + +## Installation + +Put the package under your project folder in a directory named `object-query-param-reqwest` and add the following to `Cargo.toml` under `[dependencies]`: + +``` +object-query-param-reqwest = { path = "./object-query-param-reqwest" } +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost:8080* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**list**](docs/DefaultApi.md#list) | **GET** /pony | + + +## Documentation For Models + + - [ListNotRequiredParameter](docs/ListNotRequiredParameter.md) + - [ListPageQueryParameter](docs/ListPageQueryParameter.md) + + +To get access to the crate's generated documentation, use: + +``` +cargo doc --open +``` + +## Author + + + diff --git a/samples/client/others/rust/reqwest/object-query-param/docs/DefaultApi.md b/samples/client/others/rust/reqwest/object-query-param/docs/DefaultApi.md new file mode 100644 index 00000000000..333be0dc492 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/docs/DefaultApi.md @@ -0,0 +1,38 @@ +# \DefaultApi + +All URIs are relative to *http://localhost:8080* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**list**](DefaultApi.md#list) | **GET** /pony | + + + +## list + +> list(page_query, not_required) + + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**page_query** | [**ListPageQueryParameter**](.md) | | [required] | +**not_required** | Option<[**ListNotRequiredParameter**](.md)> | | | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/others/rust/reqwest/object-query-param/docs/ListNotRequiredParameter.md b/samples/client/others/rust/reqwest/object-query-param/docs/ListNotRequiredParameter.md new file mode 100644 index 00000000000..8386441e98d --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/docs/ListNotRequiredParameter.md @@ -0,0 +1,11 @@ +# ListNotRequiredParameter + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**foobar** | Option<**i32**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/object-query-param/docs/ListPageQueryParameter.md b/samples/client/others/rust/reqwest/object-query-param/docs/ListPageQueryParameter.md new file mode 100644 index 00000000000..82f0d548e5f --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/docs/ListPageQueryParameter.md @@ -0,0 +1,12 @@ +# ListPageQueryParameter + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**offset** | Option<**i32**> | | [optional] +**limit** | Option<**i32**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/object-query-param/git_push.sh b/samples/client/others/rust/reqwest/object-query-param/git_push.sh new file mode 100644 index 00000000000..f53a75d4fab --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/git_push.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=$(git remote) +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/samples/client/others/rust/reqwest/object-query-param/src/apis/configuration.rs b/samples/client/others/rust/reqwest/object-query-param/src/apis/configuration.rs new file mode 100644 index 00000000000..440e7714254 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/src/apis/configuration.rs @@ -0,0 +1,51 @@ +/* + * OpenAPI Petstore + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + + +#[derive(Debug, Clone)] +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, +} + +pub type BasicAuth = (String, Option); + +#[derive(Debug, Clone)] +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} + + +impl Configuration { + pub fn new() -> Configuration { + Configuration::default() + } +} + +impl Default for Configuration { + fn default() -> Self { + Configuration { + base_path: "http://localhost:8080".to_owned(), + user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()), + client: reqwest::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} diff --git a/samples/client/others/rust/reqwest/object-query-param/src/apis/default_api.rs b/samples/client/others/rust/reqwest/object-query-param/src/apis/default_api.rs new file mode 100644 index 00000000000..76c54236cd5 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/src/apis/default_api.rs @@ -0,0 +1,57 @@ +/* + * OpenAPI Petstore + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + +use reqwest; +use serde::{Deserialize, Serialize, de::Error as _}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration, ContentType}; + + +/// struct for typed errors of method [`list`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListError { + UnknownValue(serde_json::Value), +} + + +pub async fn list(configuration: &configuration::Configuration, page_query: models::ListPageQueryParameter, not_required: Option) -> Result<(), Error> { + // add a prefix to parameters to efficiently prevent name collisions + let p_page_query = page_query; + let p_not_required = not_required; + + let uri_str = format!("{}/pony", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); + + let params = crate::apis::parse_flat_object(&serde_json::to_value(p_page_query)?); + req_builder = req_builder.query(¶ms); + if let Some(ref param_value) = p_not_required { + let params = crate::apis::parse_flat_object(&serde_json::to_value(param_value)?); + req_builder = req_builder.query(¶ms); + } + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); + } + + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; + + let status = resp.status(); + + if !status.is_client_error() && !status.is_server_error() { + Ok(()) + } else { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + diff --git a/samples/client/others/rust/reqwest/object-query-param/src/apis/mod.rs b/samples/client/others/rust/reqwest/object-query-param/src/apis/mod.rs new file mode 100644 index 00000000000..a046b8e201e --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/src/apis/mod.rs @@ -0,0 +1,143 @@ +use std::error; +use std::fmt; + +#[derive(Debug, Clone)] +pub struct ResponseContent { + pub status: reqwest::StatusCode, + pub content: String, + pub entity: Option, +} + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), + ResponseError(ResponseContent), +} + +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()), + Error::Serde(e) => ("serde", e.to_string()), + Error::Io(e) => ("IO", e.to_string()), + Error::ResponseError(e) => ("response", format!("status code {}", e.status)), + }; + write!(f, "error in {}: {}", module, e) + } +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + Some(match self { + Error::Reqwest(e) => e, + Error::Serde(e) => e, + Error::Io(e) => e, + Error::ResponseError(_) => return None, + }) + } +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Serde(e) + } +} + +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) + } +} + +pub fn urlencode>(s: T) -> String { + ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +} + +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + +pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => params.append(&mut parse_deep_object( + &format!("{}[{}]", prefix, key), + value, + )), + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.append(&mut parse_deep_object( + &format!("{}[{}][{}]", prefix, key, i), + value, + )); + } + }, + serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), + _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported with style=deepObject") +} + +/// Internal use only +/// A content type supported by this client. +#[allow(dead_code)] +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type.starts_with("text/plain") { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + +pub mod default_api; + +pub mod configuration; diff --git a/samples/client/others/rust/reqwest/object-query-param/src/lib.rs b/samples/client/others/rust/reqwest/object-query-param/src/lib.rs new file mode 100644 index 00000000000..e1520628d76 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/src/lib.rs @@ -0,0 +1,11 @@ +#![allow(unused_imports)] +#![allow(clippy::too_many_arguments)] + +extern crate serde_repr; +extern crate serde; +extern crate serde_json; +extern crate url; +extern crate reqwest; + +pub mod apis; +pub mod models; diff --git a/samples/client/others/rust/reqwest/object-query-param/src/models/list_not_required_parameter.rs b/samples/client/others/rust/reqwest/object-query-param/src/models/list_not_required_parameter.rs new file mode 100644 index 00000000000..ccaf52a1b6b --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/src/models/list_not_required_parameter.rs @@ -0,0 +1,27 @@ +/* + * OpenAPI Petstore + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct ListNotRequiredParameter { + #[serde(rename = "foobar", skip_serializing_if = "Option::is_none")] + pub foobar: Option, +} + +impl ListNotRequiredParameter { + pub fn new() -> ListNotRequiredParameter { + ListNotRequiredParameter { + foobar: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/object-query-param/src/models/list_page_query_parameter.rs b/samples/client/others/rust/reqwest/object-query-param/src/models/list_page_query_parameter.rs new file mode 100644 index 00000000000..808b1b56a90 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/src/models/list_page_query_parameter.rs @@ -0,0 +1,30 @@ +/* + * OpenAPI Petstore + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct ListPageQueryParameter { + #[serde(rename = "offset", skip_serializing_if = "Option::is_none")] + pub offset: Option, + #[serde(rename = "limit", skip_serializing_if = "Option::is_none")] + pub limit: Option, +} + +impl ListPageQueryParameter { + pub fn new() -> ListPageQueryParameter { + ListPageQueryParameter { + offset: None, + limit: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/object-query-param/src/models/mod.rs b/samples/client/others/rust/reqwest/object-query-param/src/models/mod.rs new file mode 100644 index 00000000000..b50743f7435 --- /dev/null +++ b/samples/client/others/rust/reqwest/object-query-param/src/models/mod.rs @@ -0,0 +1,4 @@ +pub mod list_not_required_parameter; +pub use self::list_not_required_parameter::ListNotRequiredParameter; +pub mod list_page_query_parameter; +pub use self::list_page_query_parameter::ListPageQueryParameter; diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs index fdcc89b3606..a046b8e201e 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs index fdcc89b3606..a046b8e201e 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs index 36835a5e8fa..9596ea3c671 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs index df474de3782..c66c58a48e6 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs index b27445925dc..2c38595d5bb 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs @@ -70,6 +70,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs index c55f52db30b..2adec55a9f6 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/mod.rs @@ -64,6 +64,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs index a075c841443..37a5419c07b 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs index a075c841443..37a5419c07b 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs index c03ebdf001f..ad6845bce02 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/mod.rs @@ -65,6 +65,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs index a075c841443..37a5419c07b 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs index a075c841443..37a5419c07b 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/mod.rs @@ -61,6 +61,33 @@ pub fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } +pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => { + unimplemented!( + "Only flat objects are supported, use parse_deep_object() instead" + ) + } + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.push((format!("{key}[{i}]"), value.to_string())); + } + } + serde_json::Value::String(s) => params.push((key.to_string(), s.clone())), + _ => params.push((key.to_string(), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported") +} + pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![];