Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bin/configs/rust-reqwest-petstore-serde-path-to-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: rust
outputDir: samples/client/petstore/rust/reqwest/petstore-serde-path-to-error
library: reqwest
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/rust
additionalProperties:
packageName: petstore-reqwest-serde-path-to-error
useSerdePathToError: true
enumNameMappings:
delivered: shipped
1 change: 1 addition & 0 deletions docs/generators/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|supportTokenSource|If set, add support for google-cloud-token. This option is for 'reqwest' and 'reqwest-trait' library only and requires the 'supportAsync' option| |false|
|topLevelApiClient|Creates a top level `Api` trait and `ApiClient` struct that contain all Apis. This option is for 'reqwest-trait' library only| |false|
|useBonBuilder|Use the bon crate for building parameter types. This option is for the 'reqwest-trait' library only| |false|
|useSerdePathToError|If set, use the serde_path_to_error library to enhance serde error messages. This option is for 'reqwest' and 'reqwest-trait' library only| |false|
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false|
|withAWSV4Signature|whether to include AWS v4 signature support| |false|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
@Setter(AccessLevel.PRIVATE) private boolean useSingleRequestParameter = false;
@Setter(AccessLevel.PRIVATE) private boolean supportAsync = true;
@Setter(AccessLevel.PRIVATE) private boolean supportMiddleware = false;
@Setter(AccessLevel.PRIVATE) private boolean useSerdePathToError = false;
@Setter(AccessLevel.PRIVATE) private boolean supportTokenSource = false;
private boolean supportMultipleResponses = false;
private boolean withAWSV4Signature = false;
Expand All @@ -70,6 +71,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
public static final String REQWEST_TRAIT_LIBRARY_ATTR = "reqwestTrait";
public static final String SUPPORT_ASYNC = "supportAsync";
public static final String SUPPORT_MIDDLEWARE = "supportMiddleware";
public static final String USE_SERDE_PATH_TO_ERROR = "useSerdePathToError";
public static final String SUPPORT_TOKEN_SOURCE = "supportTokenSource";
public static final String SUPPORT_MULTIPLE_RESPONSES = "supportMultipleResponses";
public static final String PREFER_UNSIGNED_INT = "preferUnsignedInt";
Expand Down Expand Up @@ -210,6 +212,8 @@ public RustClientCodegen() {
.defaultValue(Boolean.TRUE.toString()));
cliOptions.add(new CliOption(SUPPORT_MIDDLEWARE, "If set, add support for reqwest-middleware. This option is for 'reqwest' and 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE)
.defaultValue(Boolean.FALSE.toString()));
cliOptions.add(new CliOption(USE_SERDE_PATH_TO_ERROR, "If set, use the serde_path_to_error library to enhance serde error messages. This option is for 'reqwest' and 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE)
.defaultValue(Boolean.FALSE.toString()));
cliOptions.add(new CliOption(SUPPORT_TOKEN_SOURCE, "If set, add support for google-cloud-token. This option is for 'reqwest' and 'reqwest-trait' library only and requires the 'supportAsync' option", SchemaTypeUtil.BOOLEAN_TYPE)
.defaultValue(Boolean.FALSE.toString()));
cliOptions.add(new CliOption(SUPPORT_MULTIPLE_RESPONSES, "If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' and 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE)
Expand Down Expand Up @@ -410,6 +414,11 @@ public void processOpts() {
}
writePropertyBack(SUPPORT_MIDDLEWARE, getSupportMiddleware());

if (additionalProperties.containsKey(USE_SERDE_PATH_TO_ERROR)) {
this.setUseSerdePathToError(convertPropertyToBoolean(USE_SERDE_PATH_TO_ERROR));
}
writePropertyBack(USE_SERDE_PATH_TO_ERROR, getUseSerdePathToError());

if (additionalProperties.containsKey(SUPPORT_TOKEN_SOURCE)) {
this.setSupportTokenSource(convertPropertyToBoolean(SUPPORT_TOKEN_SOURCE));
}
Expand Down Expand Up @@ -527,6 +536,10 @@ private boolean getSupportMiddleware() {
return supportMiddleware;
}

private boolean getUseSerdePathToError() {
return useSerdePathToError;
}

private boolean getSupportTokenSource() {
return supportTokenSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ serde_with = { version = "^3.8", default-features = false, features = ["base64",
{{/serdeWith}}
serde_json = "^1.0"
serde_repr = "^0.1"
{{#useSerdePathToError}}
serde_path_to_error = "^0.1"
{{/useSerdePathToError}}
url = "^2.5"
{{#hasUUIDs}}
uuid = { version = "^1.8", features = ["serde", "v4"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,12 @@ impl {{classname}} for {{classname}}Client {
{{/returnType}}
{{#returnType}}
match local_var_content_type {
{{^useSerdePathToError}}
ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
{{/useSerdePathToError}}
{{#useSerdePathToError}}
ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&local_var_content)).map_err(Error::from),
{{/useSerdePathToError}}
{{#vendorExtensions.x-supports-plain-text}}
ContentType::Text => return Ok(local_var_content),
{{/vendorExtensions.x-supports-plain-text}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,12 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
{{#returnType}}
let content = resp.text(){{#supportAsync}}.await{{/supportAsync}}?;
match content_type {
{{^useSerdePathToError}}
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
{{/useSerdePathToError}}
{{#useSerdePathToError}}
ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
{{/useSerdePathToError}}
{{#vendorExtensions.x-supports-plain-text}}
ContentType::Text => return Ok(content),
{{/vendorExtensions.x-supports-plain-text}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub enum Error<T> {
ReqwestMiddleware(reqwest_middleware::Error),
{{/supportMiddleware}}
Serde(serde_json::Error),
{{#useSerdePathToError}}
SerdePathToError(serde_path_to_error::Error<serde_json::Error>),
{{/useSerdePathToError}}
Io(std::io::Error),
ResponseError(ResponseContent<T>),
{{#withAWSV4Signature}}
Expand All @@ -38,6 +41,9 @@ impl <T> fmt::Display for Error<T> {
Error::ReqwestMiddleware(e) => ("reqwest-middleware", e.to_string()),
{{/supportMiddleware}}
Error::Serde(e) => ("serde", e.to_string()),
{{#useSerdePathToError}}
Error::SerdePathToError(e) => ("serde", format!("{}: {}", e.path().to_string(), e.inner().to_string())),
{{/useSerdePathToError}}
Error::Io(e) => ("IO", e.to_string()),
Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
{{#withAWSV4Signature}}
Expand All @@ -61,6 +67,9 @@ impl <T: fmt::Debug> error::Error for Error<T> {
Error::ReqwestMiddleware(e) => e,
{{/supportMiddleware}}
Error::Serde(e) => e,
{{#useSerdePathToError}}
Error::SerdePathToError(e) => e,
{{/useSerdePathToError}}
Error::Io(e) => e,
Error::ResponseError(_) => return None,
{{#withAWSV4Signature}}
Expand Down Expand Up @@ -95,6 +104,14 @@ impl <T> From<serde_json::Error> for Error<T> {
}
}

{{#useSerdePathToError}}
impl<T> From<serde_path_to_error::Error<serde_json::Error>> for Error<T> {
fn from(e: serde_path_to_error::Error<serde_json::Error>) -> Self {
Error::SerdePathToError(e)
}
}

{{/useSerdePathToError}}
impl <T> From<std::io::Error> for Error<T> {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target/
**/*.rs.bk
Cargo.lock
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.gitignore
.travis.yml
Cargo.toml
README.md
docs/ActionContainer.md
docs/AnyTypeTest.md
docs/ApiResponse.md
docs/ArrayItemRefTest.md
docs/Baz.md
docs/Category.md
docs/EnumArrayTesting.md
docs/FakeApi.md
docs/NullableArray.md
docs/NumericEnumTesting.md
docs/OptionalTesting.md
docs/Order.md
docs/Page.md
docs/Person.md
docs/Pet.md
docs/PetApi.md
docs/PropertyTest.md
docs/Ref.md
docs/Return.md
docs/StoreApi.md
docs/Tag.md
docs/TestAllOfWithMultiMetadataOnly.md
docs/TestingApi.md
docs/TypeTesting.md
docs/UniqueItemArrayTesting.md
docs/User.md
docs/UserApi.md
docs/Vehicle.md
docs/WithInnerOneOf.md
git_push.sh
src/apis/configuration.rs
src/apis/fake_api.rs
src/apis/mod.rs
src/apis/pet_api.rs
src/apis/store_api.rs
src/apis/testing_api.rs
src/apis/user_api.rs
src/lib.rs
src/models/action_container.rs
src/models/any_type_test.rs
src/models/api_response.rs
src/models/array_item_ref_test.rs
src/models/baz.rs
src/models/category.rs
src/models/enum_array_testing.rs
src/models/mod.rs
src/models/model_ref.rs
src/models/model_return.rs
src/models/nullable_array.rs
src/models/numeric_enum_testing.rs
src/models/optional_testing.rs
src/models/order.rs
src/models/page.rs
src/models/person.rs
src/models/pet.rs
src/models/property_test.rs
src/models/tag.rs
src/models/test_all_of_with_multi_metadata_only.rs
src/models/type_testing.rs
src/models/unique_item_array_testing.rs
src/models/user.rs
src/models/vehicle.rs
src/models/with_inner_one_of.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.18.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: rust
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "petstore-reqwest-serde-path-to-error"
version = "1.0.0"
authors = ["OpenAPI Generator team and contributors"]
description = "This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters."
license = "Apache-2.0"
edition = "2021"

[dependencies]
serde = { version = "^1.0", features = ["derive"] }
serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] }
serde_json = "^1.0"
serde_repr = "^0.1"
serde_path_to_error = "^0.1"
url = "^2.5"
uuid = { version = "^1.8", features = ["serde", "v4"] }
reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] }

[features]
default = ["native-tls"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Rust API client for petstore-reqwest-serde-path-to-error

This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.


## 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.18.0-SNAPSHOT
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`

## Installation

Put the package under your project folder in a directory named `petstore-reqwest-serde-path-to-error` and add the following to `Cargo.toml` under `[dependencies]`:

```
petstore-reqwest-serde-path-to-error = { path = "./petstore-reqwest-serde-path-to-error" }
```

## Documentation for API Endpoints

All URIs are relative to *http://localhost/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*FakeApi* | [**test_nullable_required_param**](docs/FakeApi.md#test_nullable_required_param) | **GET** /fake/user/{user_name} | To test nullable required parameters
*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status
*PetApi* | [**find_pets_by_tags**](docs/PetApi.md#find_pets_by_tags) | **GET** /pet/findByTags | Finds Pets by tags
*PetApi* | [**get_pet_by_id**](docs/PetApi.md#get_pet_by_id) | **GET** /pet/{petId} | Find pet by ID
*PetApi* | [**pets_explode_post**](docs/PetApi.md#pets_explode_post) | **POST** /pets/explode | List all pets
*PetApi* | [**pets_post**](docs/PetApi.md#pets_post) | **POST** /pets | List all pets
*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **PUT** /pet | Update an existing pet
*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image
*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **GET** /store/inventory | Returns pet inventories by status
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **GET** /store/order/{orderId} | Find purchase order by ID
*StoreApi* | [**place_order**](docs/StoreApi.md#place_order) | **POST** /store/order | Place an order for a pet
*TestingApi* | [**tests_all_of_with_one_model_get**](docs/TestingApi.md#tests_all_of_with_one_model_get) | **GET** /tests/allOfWithOneModel | Test for allOf with a single option. (One of the issues in #20500)
*TestingApi* | [**tests_file_response_get**](docs/TestingApi.md#tests_file_response_get) | **GET** /tests/fileResponse | Returns an image file
*TestingApi* | [**tests_type_testing_get**](docs/TestingApi.md#tests_type_testing_get) | **GET** /tests/typeTesting | Route to test the TypeTesting schema
*UserApi* | [**create_user**](docs/UserApi.md#create_user) | **POST** /user | Create user
*UserApi* | [**create_users_with_array_input**](docs/UserApi.md#create_users_with_array_input) | **POST** /user/createWithArray | Creates list of users with given input array
*UserApi* | [**create_users_with_list_input**](docs/UserApi.md#create_users_with_list_input) | **POST** /user/createWithList | Creates list of users with given input array
*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **DELETE** /user/{username} | Delete user
*UserApi* | [**get_user_by_name**](docs/UserApi.md#get_user_by_name) | **GET** /user/{username} | Get user by user name
*UserApi* | [**login_user**](docs/UserApi.md#login_user) | **GET** /user/login | Logs user into the system
*UserApi* | [**logout_user**](docs/UserApi.md#logout_user) | **GET** /user/logout | Logs out current logged in user session
*UserApi* | [**update_user**](docs/UserApi.md#update_user) | **PUT** /user/{username} | Updated user


## Documentation For Models

- [ActionContainer](docs/ActionContainer.md)
- [AnyTypeTest](docs/AnyTypeTest.md)
- [ApiResponse](docs/ApiResponse.md)
- [ArrayItemRefTest](docs/ArrayItemRefTest.md)
- [Baz](docs/Baz.md)
- [Category](docs/Category.md)
- [EnumArrayTesting](docs/EnumArrayTesting.md)
- [NullableArray](docs/NullableArray.md)
- [NumericEnumTesting](docs/NumericEnumTesting.md)
- [OptionalTesting](docs/OptionalTesting.md)
- [Order](docs/Order.md)
- [Page](docs/Page.md)
- [Person](docs/Person.md)
- [Pet](docs/Pet.md)
- [PropertyTest](docs/PropertyTest.md)
- [Ref](docs/Ref.md)
- [Return](docs/Return.md)
- [Tag](docs/Tag.md)
- [TestAllOfWithMultiMetadataOnly](docs/TestAllOfWithMultiMetadataOnly.md)
- [TypeTesting](docs/TypeTesting.md)
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
- [User](docs/User.md)
- [Vehicle](docs/Vehicle.md)
- [WithInnerOneOf](docs/WithInnerOneOf.md)


To get access to the crate's generated documentation, use:

```
cargo doc --open
```

## Author



Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ActionContainer

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**action** | [**models::Baz**](Baz.md) | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AnyTypeTest

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**foo** | Option<[**serde_json::Value**](.md)> | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Loading
Loading