diff options
author | Bryan Newbold <bnewbold@archive.org> | 2021-02-02 11:42:43 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2021-02-02 11:42:43 -0800 |
commit | b8991aed0f4c9f58daad1865a3873fc31bdc96bd (patch) | |
tree | 9b1a669f192fdddc419ac06a6632a46e690a5cc8 /rust | |
parent | 119835ea0cf68f0003299cb3e285ae7d8d744af4 (diff) | |
download | fatcat-cli-b8991aed0f4c9f58daad1865a3873fc31bdc96bd.tar.gz fatcat-cli-b8991aed0f4c9f58daad1865a3873fc31bdc96bd.zip |
re-codegen openapi stuff
Diffstat (limited to 'rust')
-rw-r--r-- | rust/fatcat-openapi/Cargo.toml | 32 | ||||
-rw-r--r-- | rust/fatcat-openapi/Cargo.toml.codegen | 75 | ||||
-rw-r--r-- | rust/fatcat-openapi/README.md | 4 | ||||
-rw-r--r-- | rust/fatcat-openapi/docs/ReleaseExtIds.md | 3 | ||||
-rw-r--r-- | rust/fatcat-openapi/docs/default_api.md | 191 | ||||
-rw-r--r-- | rust/fatcat-openapi/examples/client/main.rs | 103 | ||||
-rw-r--r-- | rust/fatcat-openapi/examples/server/main.rs | 5 | ||||
-rw-r--r-- | rust/fatcat-openapi/examples/server/server.rs | 720 | ||||
-rw-r--r-- | rust/fatcat-openapi/src/client/mod.rs | 24991 | ||||
-rw-r--r-- | rust/fatcat-openapi/src/context.rs | 97 | ||||
-rw-r--r-- | rust/fatcat-openapi/src/lib.rs | 1700 | ||||
-rw-r--r-- | rust/fatcat-openapi/src/models.rs | 48 | ||||
-rw-r--r-- | rust/fatcat-openapi/src/server/mod.rs | 16182 |
13 files changed, 20415 insertions, 23736 deletions
diff --git a/rust/fatcat-openapi/Cargo.toml b/rust/fatcat-openapi/Cargo.toml index 7e5a5c6..b35a016 100644 --- a/rust/fatcat-openapi/Cargo.toml +++ b/rust/fatcat-openapi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fatcat-openapi" -version = "0.3.1" +version = "0.3.3" edition = "2018" authors = ["Bryan Newbold <bnewbold@archive.org>"] description = "Fatcat is an editable bibliographic database. This OpenAPI code-generated crate container HTTP API models, endpoints, and other auto-generated types useful for both client and server implementations of the catalog API." @@ -11,7 +11,7 @@ license = "CC0-1.0" [features] default = ["client", "server"] client = [ - "hyper", "hyper-openssl", "native-tls", "openssl", "url" + "hyper", "hyper-openssl", "hyper-tls", "native-tls", "openssl", "url" ] server = [ "serde_ignored", "hyper", "regex", "percent-encoding", "url", "lazy_static" @@ -20,34 +20,36 @@ conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk- [target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies] native-tls = { version = "0.2", optional = true } +hyper-tls = { version = "0.4", optional = true } [target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies] -hyper-openssl = { version = "0.7.1", optional = true } +hyper-openssl = { version = "0.8", optional = true } openssl = {version = "0.10", optional = true } [dependencies] # Common +async-trait = "0.1.24" chrono = { version = "0.4", features = ["serde"] } -futures = "0.1" -swagger = "4.0" +futures = "0.3" +swagger = "5.0.0-alpha-1" log = "0.4.0" mime = "0.3" -serde = { version = "1.0", features = ["derive"]} +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" # Crates included if required by the API definition # Common between server and client features -hyper = {version = "0.12", optional = true} -serde_ignored = {version = "0.0.4", optional = true} -url = {version = "1.5", optional = true} +hyper = {version = "0.13", optional = true} +serde_ignored = {version = "0.1.1", optional = true} +url = {version = "2.1", optional = true} # Client-specific # Server, and client callback-specific lazy_static = { version = "1.4", optional = true } -percent-encoding = {version = "1.0.0", optional = true} +percent-encoding = {version = "2.1.0", optional = true} regex = {version = "1.3", optional = true} # Conversion @@ -59,13 +61,13 @@ frunk-enum-core = { version = "0.2.0", optional = true } [dev-dependencies] clap = "2.25" -error-chain = "0.12" -env_logger = "0.6" -tokio = "0.1.17" -uuid = {version = "0.7", features = ["serde", "v4"]} +env_logger = "0.7" +tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] } +native-tls = "0.2" +tokio-tls = "0.3" [target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies] -tokio-openssl = "0.3" +tokio-openssl = "0.4" openssl = "0.10" [[example]] diff --git a/rust/fatcat-openapi/Cargo.toml.codegen b/rust/fatcat-openapi/Cargo.toml.codegen deleted file mode 100644 index 2370479..0000000 --- a/rust/fatcat-openapi/Cargo.toml.codegen +++ /dev/null @@ -1,75 +0,0 @@ -[package] -name = "fatcat-openapi" -version = "0.3.1" -authors = ["webservices@archive.org"] -description = "Fatcat is a scalable, versioned, API-oriented catalog of bibliographic entities and file metadata. " -license = "Unlicense" -edition = "2018" - -[features] -default = ["client", "server"] -client = [ - "hyper", "hyper-openssl", "native-tls", "openssl", "url" -] -server = [ - "serde_ignored", "hyper", "regex", "percent-encoding", "url", "lazy_static" -] -conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-enum-derive"] - -[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies] -native-tls = { version = "0.2", optional = true } - -[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies] -hyper-openssl = { version = "0.7.1", optional = true } -openssl = {version = "0.10", optional = true } - -[dependencies] -# Common -chrono = { version = "0.4", features = ["serde"] } -futures = "0.1" -swagger = "4.0" -log = "0.4.0" -mime = "0.3" - -serde = { version = "1.0", features = ["derive"]} -serde_json = "1.0" - -# Crates included if required by the API definition - -# Common between server and client features -hyper = {version = "0.12", optional = true} -serde_ignored = {version = "0.0.4", optional = true} -url = {version = "1.5", optional = true} - -# Client-specific - -# Server, and client callback-specific -lazy_static = { version = "1.4", optional = true } -percent-encoding = {version = "1.0.0", optional = true} -regex = {version = "0.2", optional = true} - -# Conversion -frunk = { version = "0.3.0", optional = true } -frunk_derives = { version = "0.3.0", optional = true } -frunk_core = { version = "0.3.0", optional = true } -frunk-enum-derive = { version = "0.2.0", optional = true } -frunk-enum-core = { version = "0.2.0", optional = true } - -[dev-dependencies] -clap = "2.25" -error-chain = "0.12" -env_logger = "0.6" -tokio = "0.1.17" -uuid = {version = "0.7", features = ["serde", "v4"]} - -[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies] -tokio-openssl = "0.3" -openssl = "0.10" - -[[example]] -name = "client" -required-features = ["client"] - -[[example]] -name = "server" -required-features = ["server"] diff --git a/rust/fatcat-openapi/README.md b/rust/fatcat-openapi/README.md index 4740d49..acb0fbc 100644 --- a/rust/fatcat-openapi/README.md +++ b/rust/fatcat-openapi/README.md @@ -15,8 +15,8 @@ To see how to make this your own, look here: [README]((https://openapi-generator.tech)) -- API version: 0.3.1 -- Build date: 2020-05-18T19:57:20.713017-07:00[America/Los_Angeles] +- API version: 0.3.3 +- Build date: 2021-02-02T11:39:37.681488-08:00[America/Los_Angeles] For more information, please visit [https://fatcat.wiki](https://fatcat.wiki) diff --git a/rust/fatcat-openapi/docs/ReleaseExtIds.md b/rust/fatcat-openapi/docs/ReleaseExtIds.md index e790c9a..416d595 100644 --- a/rust/fatcat-openapi/docs/ReleaseExtIds.md +++ b/rust/fatcat-openapi/docs/ReleaseExtIds.md @@ -13,6 +13,9 @@ Name | Type | Description | Notes **jstor** | **String** | JSTOR work identifier | [optional] [default to None] **ark** | **String** | ARK identifier | [optional] [default to None] **mag** | **String** | Microsoft Academic Graph identifier | [optional] [default to None] +**doaj** | **String** | DOAJ article-level identifier | [optional] [default to None] +**dblp** | **String** | dblp (https://dblp.uni-trier.de/) paper identifier; eg for conference proceedings | [optional] [default to None] +**oai** | **String** | OAI-PMH identifier; only used when an OAI-PMH record is the only authoritative metadata (eg, journal OAI-PMH feeds w/o DOIs) | [optional] [default to None] [[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/rust/fatcat-openapi/docs/default_api.md b/rust/fatcat-openapi/docs/default_api.md index b97a861..5308e84 100644 --- a/rust/fatcat-openapi/docs/default_api.md +++ b/rust/fatcat-openapi/docs/default_api.md @@ -125,7 +125,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -160,7 +160,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -188,7 +188,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -225,7 +225,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -254,7 +254,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -282,7 +282,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -309,7 +309,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -335,7 +335,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -363,7 +363,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -392,7 +392,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -419,7 +419,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -445,7 +445,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -472,7 +472,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -498,7 +498,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -527,7 +527,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -555,7 +555,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -582,7 +582,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -608,7 +608,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -635,7 +635,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -661,7 +661,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -690,7 +690,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -719,7 +719,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -746,7 +746,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -773,7 +773,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -800,7 +800,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -827,7 +827,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -854,7 +854,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -881,7 +881,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -910,7 +910,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -939,7 +939,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -966,7 +966,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -993,7 +993,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1020,7 +1020,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1047,7 +1047,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1081,7 +1081,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1108,7 +1108,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1145,7 +1145,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1172,7 +1172,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1208,7 +1208,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1235,7 +1235,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1272,7 +1272,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1307,7 +1307,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1332,7 +1332,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1366,7 +1366,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1391,7 +1391,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1427,7 +1427,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1462,7 +1462,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1489,7 +1489,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1525,7 +1525,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1562,7 +1562,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1589,7 +1589,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1627,7 +1627,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1665,7 +1665,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1700,7 +1700,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1725,7 +1725,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1759,7 +1759,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1784,7 +1784,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1819,7 +1819,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1854,7 +1854,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1879,7 +1879,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1913,7 +1913,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1938,7 +1938,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -1973,7 +1973,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2010,7 +2010,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2037,7 +2037,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2073,7 +2073,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2109,7 +2109,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2145,7 +2145,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2172,7 +2172,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2209,7 +2209,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2245,7 +2245,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2280,7 +2280,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2305,7 +2305,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2339,7 +2339,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2364,7 +2364,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2399,7 +2399,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2434,7 +2434,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2459,7 +2459,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2493,7 +2493,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2518,7 +2518,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2554,7 +2554,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2589,7 +2589,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2626,7 +2626,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2661,7 +2661,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2697,7 +2697,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2728,6 +2728,9 @@ Name | Type | Description | Notes **jstor** | **String**| | **ark** | **String**| | **mag** | **String**| | + **doaj** | **String**| | + **dblp** | **String**| | + **oai** | **String**| | **expand** | **String**| List of sub-entities to expand in response. See `get_release`. | **hide** | **String**| List of sub-entities to elide in response. See `get_release`. | @@ -2742,7 +2745,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2772,7 +2775,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2800,7 +2803,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2839,7 +2842,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2868,7 +2871,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2896,7 +2899,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2924,7 +2927,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2954,7 +2957,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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) @@ -2982,7 +2985,7 @@ Name | Type | Description | Notes ### HTTP request headers - **Content-Type**: application/json - - **Accept**: application/json, + - **Accept**: application/json [[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/rust/fatcat-openapi/examples/client/main.rs b/rust/fatcat-openapi/examples/client/main.rs index 0bc6662..14a1bdf 100644 --- a/rust/fatcat-openapi/examples/client/main.rs +++ b/rust/fatcat-openapi/examples/client/main.rs @@ -3,39 +3,39 @@ use clap::{App, Arg}; #[allow(unused_imports)] use fatcat_openapi::{ - models, AcceptEditgroupResponse, Api, ApiError, ApiNoContext, AuthCheckResponse, - AuthOidcResponse, Client, ContextWrapperExt, CreateAuthTokenResponse, - CreateContainerAutoBatchResponse, CreateContainerResponse, CreateCreatorAutoBatchResponse, - CreateCreatorResponse, CreateEditgroupAnnotationResponse, CreateEditgroupResponse, - CreateFileAutoBatchResponse, CreateFileResponse, CreateFilesetAutoBatchResponse, - CreateFilesetResponse, CreateReleaseAutoBatchResponse, CreateReleaseResponse, - CreateWebcaptureAutoBatchResponse, CreateWebcaptureResponse, CreateWorkAutoBatchResponse, - CreateWorkResponse, DeleteContainerEditResponse, DeleteContainerResponse, - DeleteCreatorEditResponse, DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, - DeleteFilesetEditResponse, DeleteFilesetResponse, DeleteReleaseEditResponse, - DeleteReleaseResponse, DeleteWebcaptureEditResponse, DeleteWebcaptureResponse, - DeleteWorkEditResponse, DeleteWorkResponse, GetChangelogEntryResponse, GetChangelogResponse, - GetContainerEditResponse, GetContainerHistoryResponse, GetContainerRedirectsResponse, - GetContainerResponse, GetContainerRevisionResponse, GetCreatorEditResponse, - GetCreatorHistoryResponse, GetCreatorRedirectsResponse, GetCreatorReleasesResponse, - GetCreatorResponse, GetCreatorRevisionResponse, GetEditgroupAnnotationsResponse, - GetEditgroupResponse, GetEditgroupsReviewableResponse, GetEditorAnnotationsResponse, - GetEditorEditgroupsResponse, GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, - GetFileRedirectsResponse, GetFileResponse, GetFileRevisionResponse, GetFilesetEditResponse, - GetFilesetHistoryResponse, GetFilesetRedirectsResponse, GetFilesetResponse, - GetFilesetRevisionResponse, GetReleaseEditResponse, GetReleaseFilesResponse, - GetReleaseFilesetsResponse, GetReleaseHistoryResponse, GetReleaseRedirectsResponse, - GetReleaseResponse, GetReleaseRevisionResponse, GetReleaseWebcapturesResponse, - GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, - GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, - GetWorkHistoryResponse, GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, - GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, - LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, UpdateEditgroupResponse, - UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, - UpdateWebcaptureResponse, UpdateWorkResponse, + models, AcceptEditgroupResponse, Api, ApiNoContext, AuthCheckResponse, AuthOidcResponse, + Client, ContextWrapperExt, CreateAuthTokenResponse, CreateContainerAutoBatchResponse, + CreateContainerResponse, CreateCreatorAutoBatchResponse, CreateCreatorResponse, + CreateEditgroupAnnotationResponse, CreateEditgroupResponse, CreateFileAutoBatchResponse, + CreateFileResponse, CreateFilesetAutoBatchResponse, CreateFilesetResponse, + CreateReleaseAutoBatchResponse, CreateReleaseResponse, CreateWebcaptureAutoBatchResponse, + CreateWebcaptureResponse, CreateWorkAutoBatchResponse, CreateWorkResponse, + DeleteContainerEditResponse, DeleteContainerResponse, DeleteCreatorEditResponse, + DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, DeleteFilesetEditResponse, + DeleteFilesetResponse, DeleteReleaseEditResponse, DeleteReleaseResponse, + DeleteWebcaptureEditResponse, DeleteWebcaptureResponse, DeleteWorkEditResponse, + DeleteWorkResponse, GetChangelogEntryResponse, GetChangelogResponse, GetContainerEditResponse, + GetContainerHistoryResponse, GetContainerRedirectsResponse, GetContainerResponse, + GetContainerRevisionResponse, GetCreatorEditResponse, GetCreatorHistoryResponse, + GetCreatorRedirectsResponse, GetCreatorReleasesResponse, GetCreatorResponse, + GetCreatorRevisionResponse, GetEditgroupAnnotationsResponse, GetEditgroupResponse, + GetEditgroupsReviewableResponse, GetEditorAnnotationsResponse, GetEditorEditgroupsResponse, + GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, GetFileRedirectsResponse, + GetFileResponse, GetFileRevisionResponse, GetFilesetEditResponse, GetFilesetHistoryResponse, + GetFilesetRedirectsResponse, GetFilesetResponse, GetFilesetRevisionResponse, + GetReleaseEditResponse, GetReleaseFilesResponse, GetReleaseFilesetsResponse, + GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, + GetReleaseRevisionResponse, GetReleaseWebcapturesResponse, GetWebcaptureEditResponse, + GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, GetWebcaptureResponse, + GetWebcaptureRevisionResponse, GetWorkEditResponse, GetWorkHistoryResponse, + GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, GetWorkRevisionResponse, + LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse, + UpdateContainerResponse, UpdateCreatorResponse, UpdateEditgroupResponse, UpdateEditorResponse, + UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, UpdateWebcaptureResponse, + UpdateWorkResponse, }; #[allow(unused_imports)] -use futures::{future, stream, Future, Stream}; +use futures::{future, stream, Stream}; #[allow(unused_imports)] use log::info; @@ -44,6 +44,13 @@ use log::info; #[allow(unused_imports)] use swagger::{AuthData, ContextBuilder, EmptyContext, Has, Push, XSpanIdString}; +type ClientContext = swagger::make_context_ty!( + ContextBuilder, + EmptyContext, + Option<AuthData>, + XSpanIdString +); + // rt may be unused if there are no examples #[allow(unused_mut)] fn main() { @@ -156,27 +163,24 @@ fn main() { matches.value_of("port").unwrap() ); - let client = if matches.is_present("https") { - // Using Simple HTTPS - Client::try_new_https(&base_url).expect("Failed to create HTTPS client") - } else { - // Using HTTP - Client::try_new_http(&base_url).expect("Failed to create HTTP client") - }; - - let context: swagger::make_context_ty!( - ContextBuilder, - EmptyContext, - Option<AuthData>, - XSpanIdString - ) = swagger::make_context!( + let context: ClientContext = swagger::make_context!( ContextBuilder, EmptyContext, None as Option<AuthData>, XSpanIdString::default() ); - let client = client.with_context(context); + let mut client: Box<dyn ApiNoContext<ClientContext>> = if matches.is_present("https") { + // Using Simple HTTPS + let client = + Box::new(Client::try_new_https(&base_url).expect("Failed to create HTTPS client")); + Box::new(client.with_context(context)) + } else { + // Using HTTP + let client = + Box::new(Client::try_new_http(&base_url).expect("Failed to create HTTP client")); + Box::new(client.with_context(context)) + }; let mut rt = tokio::runtime::Runtime::new().unwrap(); @@ -1036,6 +1040,9 @@ fn main() { Some("jstor_example".to_string()), Some("ark_example".to_string()), Some("mag_example".to_string()), + Some("doaj_example".to_string()), + Some("dblp_example".to_string()), + Some("oai_example".to_string()), Some("expand_example".to_string()), Some("hide_example".to_string()), )); @@ -1134,6 +1141,8 @@ fn main() { info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has<XSpanIdString>).get().clone()); }, */ - _ => panic!("Invalid operation provided"), + _ => { + panic!("Invalid operation provided") + } } } diff --git a/rust/fatcat-openapi/examples/server/main.rs b/rust/fatcat-openapi/examples/server/main.rs index af089c2..5488dc6 100644 --- a/rust/fatcat-openapi/examples/server/main.rs +++ b/rust/fatcat-openapi/examples/server/main.rs @@ -8,7 +8,8 @@ mod server; /// Create custom server, wire it to the autogenerated router, /// and pass it to the web server. -fn main() { +#[tokio::main] +async fn main() { env_logger::init(); let matches = App::new("server") @@ -21,5 +22,5 @@ fn main() { let addr = "127.0.0.1:8080"; - hyper::rt::run(server::create(addr, matches.is_present("https"))); + server::create(addr, matches.is_present("https")).await; } diff --git a/rust/fatcat-openapi/examples/server/server.rs b/rust/fatcat-openapi/examples/server/server.rs index 85c8f73..981487e 100644 --- a/rust/fatcat-openapi/examples/server/server.rs +++ b/rust/fatcat-openapi/examples/server/server.rs @@ -2,22 +2,18 @@ #![allow(unused_imports)] -mod errors { - error_chain::error_chain! {} -} - -pub use self::errors::*; - -use chrono; -use futures::{future, Future, Stream}; +use async_trait::async_trait; +use futures::{future, Stream, StreamExt, TryFutureExt, TryStreamExt}; use hyper::server::conn::Http; -use hyper::service::MakeService as _; +use hyper::service::Service; use log::info; +#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] use openssl::ssl::SslAcceptorBuilder; +use std::future::Future; use std::marker::PhantomData; use std::net::SocketAddr; use std::sync::{Arc, Mutex}; -use swagger; +use std::task::{Context, Poll}; use swagger::auth::MakeAllowAllAuthenticator; use swagger::EmptyContext; use swagger::{Has, XSpanIdString}; @@ -25,24 +21,21 @@ use tokio::net::TcpListener; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; -#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] -use tokio_openssl::SslAcceptorExt; use fatcat_openapi::models; -#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] /// Builds an SSL implementation for Simple HTTPS from some hard-coded file names -pub fn create(addr: &str, https: bool) -> Box<dyn Future<Item = (), Error = ()> + Send> { +pub async fn create(addr: &str, https: bool) { let addr = addr.parse().expect("Failed to parse bind address"); let server = Server::new(); - let service_fn = MakeService::new(server); + let service = MakeService::new(server); - let service_fn = MakeAllowAllAuthenticator::new(service_fn, "cosmo"); + let service = MakeAllowAllAuthenticator::new(service, "cosmo"); - let service_fn = - fatcat_openapi::server::context::MakeAddContext::<_, EmptyContext>::new(service_fn); + let mut service = + fatcat_openapi::server::context::MakeAddContext::<_, EmptyContext>::new(service); if https { #[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))] @@ -63,41 +56,39 @@ pub fn create(addr: &str, https: bool) -> Box<dyn Future<Item = (), Error = ()> ssl.check_private_key() .expect("Failed to check private key"); - let tls_acceptor = ssl.build(); - let service_fn = Arc::new(Mutex::new(service_fn)); - let tls_listener = TcpListener::bind(&addr) - .unwrap() - .incoming() - .for_each(move |tcp| { - let addr = tcp.peer_addr().expect("Unable to get remote address"); + let tls_acceptor = Arc::new(ssl.build()); + let mut tcp_listener = TcpListener::bind(&addr).await.unwrap(); + let mut incoming = tcp_listener.incoming(); - let service_fn = service_fn.clone(); + while let (Some(tcp), rest) = incoming.into_future().await { + if let Ok(tcp) = tcp { + let addr = tcp.peer_addr().expect("Unable to get remote address"); + let service = service.call(addr); + let tls_acceptor = Arc::clone(&tls_acceptor); - hyper::rt::spawn(tls_acceptor.accept_async(tcp).map_err(|_| ()).and_then( - move |tls| { - let ms = { - let mut service_fn = service_fn.lock().unwrap(); - service_fn.make_service(&addr) - }; + tokio::spawn(async move { + let tls = tokio_openssl::accept(&*tls_acceptor, tcp) + .await + .map_err(|_| ())?; - ms.and_then(move |service| Http::new().serve_connection(tls, service)) - .map_err(|_| ()) - }, - )); + let service = service.await.map_err(|_| ())?; - Ok(()) - }) - .map_err(|_| ()); + Http::new() + .serve_connection(tls, service) + .await + .map_err(|_| ()) + }); + } - Box::new(tls_listener) + incoming = rest; + } } } else { // Using HTTP - Box::new( - hyper::server::Server::bind(&addr) - .serve(service_fn) - .map_err(|e| panic!("{:?}", e)), - ) + hyper::server::Server::bind(&addr) + .serve(service) + .await + .unwrap() } } @@ -116,90 +107,92 @@ impl<C> Server<C> { use fatcat_openapi::server::MakeService; use fatcat_openapi::{ - AcceptEditgroupResponse, Api, ApiError, AuthCheckResponse, AuthOidcResponse, - CreateAuthTokenResponse, CreateContainerAutoBatchResponse, CreateContainerResponse, - CreateCreatorAutoBatchResponse, CreateCreatorResponse, CreateEditgroupAnnotationResponse, - CreateEditgroupResponse, CreateFileAutoBatchResponse, CreateFileResponse, - CreateFilesetAutoBatchResponse, CreateFilesetResponse, CreateReleaseAutoBatchResponse, - CreateReleaseResponse, CreateWebcaptureAutoBatchResponse, CreateWebcaptureResponse, - CreateWorkAutoBatchResponse, CreateWorkResponse, DeleteContainerEditResponse, - DeleteContainerResponse, DeleteCreatorEditResponse, DeleteCreatorResponse, - DeleteFileEditResponse, DeleteFileResponse, DeleteFilesetEditResponse, DeleteFilesetResponse, - DeleteReleaseEditResponse, DeleteReleaseResponse, DeleteWebcaptureEditResponse, - DeleteWebcaptureResponse, DeleteWorkEditResponse, DeleteWorkResponse, - GetChangelogEntryResponse, GetChangelogResponse, GetContainerEditResponse, - GetContainerHistoryResponse, GetContainerRedirectsResponse, GetContainerResponse, - GetContainerRevisionResponse, GetCreatorEditResponse, GetCreatorHistoryResponse, - GetCreatorRedirectsResponse, GetCreatorReleasesResponse, GetCreatorResponse, - GetCreatorRevisionResponse, GetEditgroupAnnotationsResponse, GetEditgroupResponse, - GetEditgroupsReviewableResponse, GetEditorAnnotationsResponse, GetEditorEditgroupsResponse, - GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, GetFileRedirectsResponse, - GetFileResponse, GetFileRevisionResponse, GetFilesetEditResponse, GetFilesetHistoryResponse, - GetFilesetRedirectsResponse, GetFilesetResponse, GetFilesetRevisionResponse, - GetReleaseEditResponse, GetReleaseFilesResponse, GetReleaseFilesetsResponse, - GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, - GetReleaseRevisionResponse, GetReleaseWebcapturesResponse, GetWebcaptureEditResponse, - GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, GetWebcaptureResponse, - GetWebcaptureRevisionResponse, GetWorkEditResponse, GetWorkHistoryResponse, - GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, GetWorkRevisionResponse, - LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse, - UpdateContainerResponse, UpdateCreatorResponse, UpdateEditgroupResponse, UpdateEditorResponse, - UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, UpdateWebcaptureResponse, - UpdateWorkResponse, + AcceptEditgroupResponse, Api, AuthCheckResponse, AuthOidcResponse, CreateAuthTokenResponse, + CreateContainerAutoBatchResponse, CreateContainerResponse, CreateCreatorAutoBatchResponse, + CreateCreatorResponse, CreateEditgroupAnnotationResponse, CreateEditgroupResponse, + CreateFileAutoBatchResponse, CreateFileResponse, CreateFilesetAutoBatchResponse, + CreateFilesetResponse, CreateReleaseAutoBatchResponse, CreateReleaseResponse, + CreateWebcaptureAutoBatchResponse, CreateWebcaptureResponse, CreateWorkAutoBatchResponse, + CreateWorkResponse, DeleteContainerEditResponse, DeleteContainerResponse, + DeleteCreatorEditResponse, DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, + DeleteFilesetEditResponse, DeleteFilesetResponse, DeleteReleaseEditResponse, + DeleteReleaseResponse, DeleteWebcaptureEditResponse, DeleteWebcaptureResponse, + DeleteWorkEditResponse, DeleteWorkResponse, GetChangelogEntryResponse, GetChangelogResponse, + GetContainerEditResponse, GetContainerHistoryResponse, GetContainerRedirectsResponse, + GetContainerResponse, GetContainerRevisionResponse, GetCreatorEditResponse, + GetCreatorHistoryResponse, GetCreatorRedirectsResponse, GetCreatorReleasesResponse, + GetCreatorResponse, GetCreatorRevisionResponse, GetEditgroupAnnotationsResponse, + GetEditgroupResponse, GetEditgroupsReviewableResponse, GetEditorAnnotationsResponse, + GetEditorEditgroupsResponse, GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, + GetFileRedirectsResponse, GetFileResponse, GetFileRevisionResponse, GetFilesetEditResponse, + GetFilesetHistoryResponse, GetFilesetRedirectsResponse, GetFilesetResponse, + GetFilesetRevisionResponse, GetReleaseEditResponse, GetReleaseFilesResponse, + GetReleaseFilesetsResponse, GetReleaseHistoryResponse, GetReleaseRedirectsResponse, + GetReleaseResponse, GetReleaseRevisionResponse, GetReleaseWebcapturesResponse, + GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, + GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, + GetWorkHistoryResponse, GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, + GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, + LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, UpdateEditgroupResponse, + UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, + UpdateWebcaptureResponse, UpdateWorkResponse, }; +use std::error::Error; +use swagger::ApiError; +#[async_trait] impl<C> Api<C> for Server<C> where - C: Has<XSpanIdString>, + C: Has<XSpanIdString> + Send + Sync, { - fn accept_editgroup( + async fn accept_editgroup( &self, editgroup_id: String, context: &C, - ) -> Box<dyn Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> { + ) -> Result<AcceptEditgroupResponse, ApiError> { let context = context.clone(); info!( "accept_editgroup(\"{}\") - X-Span-ID: {:?}", editgroup_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn auth_check( + async fn auth_check( &self, role: Option<String>, context: &C, - ) -> Box<dyn Future<Item = AuthCheckResponse, Error = ApiError> + Send> { + ) -> Result<AuthCheckResponse, ApiError> { let context = context.clone(); info!( "auth_check({:?}) - X-Span-ID: {:?}", role, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn auth_oidc( + async fn auth_oidc( &self, auth_oidc: models::AuthOidc, context: &C, - ) -> Box<dyn Future<Item = AuthOidcResponse, Error = ApiError> + Send> { + ) -> Result<AuthOidcResponse, ApiError> { let context = context.clone(); info!( "auth_oidc({:?}) - X-Span-ID: {:?}", auth_oidc, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_auth_token( + async fn create_auth_token( &self, editor_id: String, duration_seconds: Option<i32>, context: &C, - ) -> Box<dyn Future<Item = CreateAuthTokenResponse, Error = ApiError> + Send> { + ) -> Result<CreateAuthTokenResponse, ApiError> { let context = context.clone(); info!( "create_auth_token(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -207,15 +200,15 @@ where duration_seconds, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_container( + async fn create_container( &self, editgroup_id: String, container_entity: models::ContainerEntity, context: &C, - ) -> Box<dyn Future<Item = CreateContainerResponse, Error = ApiError> + Send> { + ) -> Result<CreateContainerResponse, ApiError> { let context = context.clone(); info!( "create_container(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -223,29 +216,29 @@ where container_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_container_auto_batch( + async fn create_container_auto_batch( &self, container_auto_batch: models::ContainerAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateContainerAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateContainerAutoBatchResponse, ApiError> { let context = context.clone(); info!( "create_container_auto_batch({:?}) - X-Span-ID: {:?}", container_auto_batch, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_creator( + async fn create_creator( &self, editgroup_id: String, creator_entity: models::CreatorEntity, context: &C, - ) -> Box<dyn Future<Item = CreateCreatorResponse, Error = ApiError> + Send> { + ) -> Result<CreateCreatorResponse, ApiError> { let context = context.clone(); info!( "create_creator(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -253,43 +246,43 @@ where creator_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_creator_auto_batch( + async fn create_creator_auto_batch( &self, creator_auto_batch: models::CreatorAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateCreatorAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateCreatorAutoBatchResponse, ApiError> { let context = context.clone(); info!( "create_creator_auto_batch({:?}) - X-Span-ID: {:?}", creator_auto_batch, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_editgroup( + async fn create_editgroup( &self, editgroup: models::Editgroup, context: &C, - ) -> Box<dyn Future<Item = CreateEditgroupResponse, Error = ApiError> + Send> { + ) -> Result<CreateEditgroupResponse, ApiError> { let context = context.clone(); info!( "create_editgroup({:?}) - X-Span-ID: {:?}", editgroup, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_editgroup_annotation( + async fn create_editgroup_annotation( &self, editgroup_id: String, editgroup_annotation: models::EditgroupAnnotation, context: &C, - ) -> Box<dyn Future<Item = CreateEditgroupAnnotationResponse, Error = ApiError> + Send> { + ) -> Result<CreateEditgroupAnnotationResponse, ApiError> { let context = context.clone(); info!( "create_editgroup_annotation(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -297,15 +290,15 @@ where editgroup_annotation, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_file( + async fn create_file( &self, editgroup_id: String, file_entity: models::FileEntity, context: &C, - ) -> Box<dyn Future<Item = CreateFileResponse, Error = ApiError> + Send> { + ) -> Result<CreateFileResponse, ApiError> { let context = context.clone(); info!( "create_file(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -313,29 +306,29 @@ where file_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_file_auto_batch( + async fn create_file_auto_batch( &self, file_auto_batch: models::FileAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateFileAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateFileAutoBatchResponse, ApiError> { let context = context.clone(); info!( "create_file_auto_batch({:?}) - X-Span-ID: {:?}", file_auto_batch, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_fileset( + async fn create_fileset( &self, editgroup_id: String, fileset_entity: models::FilesetEntity, context: &C, - ) -> Box<dyn Future<Item = CreateFilesetResponse, Error = ApiError> + Send> { + ) -> Result<CreateFilesetResponse, ApiError> { let context = context.clone(); info!( "create_fileset(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -343,29 +336,29 @@ where fileset_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_fileset_auto_batch( + async fn create_fileset_auto_batch( &self, fileset_auto_batch: models::FilesetAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateFilesetAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateFilesetAutoBatchResponse, ApiError> { let context = context.clone(); info!( "create_fileset_auto_batch({:?}) - X-Span-ID: {:?}", fileset_auto_batch, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_release( + async fn create_release( &self, editgroup_id: String, release_entity: models::ReleaseEntity, context: &C, - ) -> Box<dyn Future<Item = CreateReleaseResponse, Error = ApiError> + Send> { + ) -> Result<CreateReleaseResponse, ApiError> { let context = context.clone(); info!( "create_release(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -373,29 +366,29 @@ where release_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_release_auto_batch( + async fn create_release_auto_batch( &self, release_auto_batch: models::ReleaseAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateReleaseAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateReleaseAutoBatchResponse, ApiError> { let context = context.clone(); info!( "create_release_auto_batch({:?}) - X-Span-ID: {:?}", release_auto_batch, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_webcapture( + async fn create_webcapture( &self, editgroup_id: String, webcapture_entity: models::WebcaptureEntity, context: &C, - ) -> Box<dyn Future<Item = CreateWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<CreateWebcaptureResponse, ApiError> { let context = context.clone(); info!( "create_webcapture(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -403,29 +396,29 @@ where webcapture_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_webcapture_auto_batch( + async fn create_webcapture_auto_batch( &self, webcapture_auto_batch: models::WebcaptureAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateWebcaptureAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateWebcaptureAutoBatchResponse, ApiError> { let context = context.clone(); info!( "create_webcapture_auto_batch({:?}) - X-Span-ID: {:?}", webcapture_auto_batch, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_work( + async fn create_work( &self, editgroup_id: String, work_entity: models::WorkEntity, context: &C, - ) -> Box<dyn Future<Item = CreateWorkResponse, Error = ApiError> + Send> { + ) -> Result<CreateWorkResponse, ApiError> { let context = context.clone(); info!( "create_work(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -433,29 +426,29 @@ where work_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn create_work_auto_batch( + async fn create_work_auto_batch( &self, work_auto_batch: models::WorkAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateWorkAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateWorkAutoBatchResponse, ApiError> { let context = context.clone(); info!( "create_work_auto_batch({:?}) - X-Span-ID: {:?}", work_auto_batch, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_container( + async fn delete_container( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteContainerResponse, Error = ApiError> + Send> { + ) -> Result<DeleteContainerResponse, ApiError> { let context = context.clone(); info!( "delete_container(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -463,15 +456,15 @@ where ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_container_edit( + async fn delete_container_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteContainerEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteContainerEditResponse, ApiError> { let context = context.clone(); info!( "delete_container_edit(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -479,15 +472,15 @@ where edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_creator( + async fn delete_creator( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteCreatorResponse, Error = ApiError> + Send> { + ) -> Result<DeleteCreatorResponse, ApiError> { let context = context.clone(); info!( "delete_creator(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -495,15 +488,15 @@ where ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_creator_edit( + async fn delete_creator_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteCreatorEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteCreatorEditResponse, ApiError> { let context = context.clone(); info!( "delete_creator_edit(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -511,15 +504,15 @@ where edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_file( + async fn delete_file( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFileResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFileResponse, ApiError> { let context = context.clone(); info!( "delete_file(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -527,15 +520,15 @@ where ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_file_edit( + async fn delete_file_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFileEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFileEditResponse, ApiError> { let context = context.clone(); info!( "delete_file_edit(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -543,15 +536,15 @@ where edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_fileset( + async fn delete_fileset( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFilesetResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFilesetResponse, ApiError> { let context = context.clone(); info!( "delete_fileset(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -559,15 +552,15 @@ where ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_fileset_edit( + async fn delete_fileset_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFilesetEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFilesetEditResponse, ApiError> { let context = context.clone(); info!( "delete_fileset_edit(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -575,15 +568,15 @@ where edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_release( + async fn delete_release( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteReleaseResponse, Error = ApiError> + Send> { + ) -> Result<DeleteReleaseResponse, ApiError> { let context = context.clone(); info!( "delete_release(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -591,15 +584,15 @@ where ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_release_edit( + async fn delete_release_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteReleaseEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteReleaseEditResponse, ApiError> { let context = context.clone(); info!( "delete_release_edit(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -607,15 +600,15 @@ where edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_webcapture( + async fn delete_webcapture( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWebcaptureResponse, ApiError> { let context = context.clone(); info!( "delete_webcapture(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -623,15 +616,15 @@ where ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_webcapture_edit( + async fn delete_webcapture_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWebcaptureEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWebcaptureEditResponse, ApiError> { let context = context.clone(); info!( "delete_webcapture_edit(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -639,15 +632,15 @@ where edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_work( + async fn delete_work( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWorkResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWorkResponse, ApiError> { let context = context.clone(); info!( "delete_work(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -655,15 +648,15 @@ where ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn delete_work_edit( + async fn delete_work_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWorkEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWorkEditResponse, ApiError> { let context = context.clone(); info!( "delete_work_edit(\"{}\", \"{}\") - X-Span-ID: {:?}", @@ -671,44 +664,44 @@ where edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_changelog( + async fn get_changelog( &self, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetChangelogResponse, Error = ApiError> + Send> { + ) -> Result<GetChangelogResponse, ApiError> { let context = context.clone(); info!( "get_changelog({:?}) - X-Span-ID: {:?}", limit, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_changelog_entry( + async fn get_changelog_entry( &self, index: i64, context: &C, - ) -> Box<dyn Future<Item = GetChangelogEntryResponse, Error = ApiError> + Send> { + ) -> Result<GetChangelogEntryResponse, ApiError> { let context = context.clone(); info!( "get_changelog_entry({}) - X-Span-ID: {:?}", index, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_container( + async fn get_container( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetContainerResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerResponse, ApiError> { let context = context.clone(); info!( "get_container(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -717,29 +710,29 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_container_edit( + async fn get_container_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetContainerEditResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerEditResponse, ApiError> { let context = context.clone(); info!( "get_container_edit(\"{}\") - X-Span-ID: {:?}", edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_container_history( + async fn get_container_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetContainerHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerHistoryResponse, ApiError> { let context = context.clone(); info!( "get_container_history(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -747,30 +740,30 @@ where limit, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_container_redirects( + async fn get_container_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetContainerRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerRedirectsResponse, ApiError> { let context = context.clone(); info!( "get_container_redirects(\"{}\") - X-Span-ID: {:?}", ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_container_revision( + async fn get_container_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetContainerRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerRevisionResponse, ApiError> { let context = context.clone(); info!( "get_container_revision(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -779,16 +772,16 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_creator( + async fn get_creator( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorResponse, ApiError> { let context = context.clone(); info!( "get_creator(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -797,29 +790,29 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_creator_edit( + async fn get_creator_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetCreatorEditResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorEditResponse, ApiError> { let context = context.clone(); info!( "get_creator_edit(\"{}\") - X-Span-ID: {:?}", edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_creator_history( + async fn get_creator_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorHistoryResponse, ApiError> { let context = context.clone(); info!( "get_creator_history(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -827,29 +820,29 @@ where limit, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_creator_redirects( + async fn get_creator_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetCreatorRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorRedirectsResponse, ApiError> { let context = context.clone(); info!( "get_creator_redirects(\"{}\") - X-Span-ID: {:?}", ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_creator_releases( + async fn get_creator_releases( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorReleasesResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorReleasesResponse, ApiError> { let context = context.clone(); info!( "get_creator_releases(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -857,16 +850,16 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_creator_revision( + async fn get_creator_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorRevisionResponse, ApiError> { let context = context.clone(); info!( "get_creator_revision(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -875,29 +868,29 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_editgroup( + async fn get_editgroup( &self, editgroup_id: String, context: &C, - ) -> Box<dyn Future<Item = GetEditgroupResponse, Error = ApiError> + Send> { + ) -> Result<GetEditgroupResponse, ApiError> { let context = context.clone(); info!( "get_editgroup(\"{}\") - X-Span-ID: {:?}", editgroup_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_editgroup_annotations( + async fn get_editgroup_annotations( &self, editgroup_id: String, expand: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetEditgroupAnnotationsResponse, Error = ApiError> + Send> { + ) -> Result<GetEditgroupAnnotationsResponse, ApiError> { let context = context.clone(); info!( "get_editgroup_annotations(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -905,17 +898,17 @@ where expand, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_editgroups_reviewable( + async fn get_editgroups_reviewable( &self, expand: Option<String>, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, context: &C, - ) -> Box<dyn Future<Item = GetEditgroupsReviewableResponse, Error = ApiError> + Send> { + ) -> Result<GetEditgroupsReviewableResponse, ApiError> { let context = context.clone(); info!( "get_editgroups_reviewable({:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", @@ -925,31 +918,31 @@ where since, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_editor( + async fn get_editor( &self, editor_id: String, context: &C, - ) -> Box<dyn Future<Item = GetEditorResponse, Error = ApiError> + Send> { + ) -> Result<GetEditorResponse, ApiError> { let context = context.clone(); info!( "get_editor(\"{}\") - X-Span-ID: {:?}", editor_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_editor_annotations( + async fn get_editor_annotations( &self, editor_id: String, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, context: &C, - ) -> Box<dyn Future<Item = GetEditorAnnotationsResponse, Error = ApiError> + Send> { + ) -> Result<GetEditorAnnotationsResponse, ApiError> { let context = context.clone(); info!( "get_editor_annotations(\"{}\", {:?}, {:?}, {:?}) - X-Span-ID: {:?}", @@ -959,17 +952,17 @@ where since, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_editor_editgroups( + async fn get_editor_editgroups( &self, editor_id: String, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, context: &C, - ) -> Box<dyn Future<Item = GetEditorEditgroupsResponse, Error = ApiError> + Send> { + ) -> Result<GetEditorEditgroupsResponse, ApiError> { let context = context.clone(); info!( "get_editor_editgroups(\"{}\", {:?}, {:?}, {:?}) - X-Span-ID: {:?}", @@ -979,16 +972,16 @@ where since, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_file( + async fn get_file( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFileResponse, Error = ApiError> + Send> { + ) -> Result<GetFileResponse, ApiError> { let context = context.clone(); info!( "get_file(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -997,29 +990,29 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_file_edit( + async fn get_file_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetFileEditResponse, Error = ApiError> + Send> { + ) -> Result<GetFileEditResponse, ApiError> { let context = context.clone(); info!( "get_file_edit(\"{}\") - X-Span-ID: {:?}", edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_file_history( + async fn get_file_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetFileHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetFileHistoryResponse, ApiError> { let context = context.clone(); info!( "get_file_history(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1027,30 +1020,30 @@ where limit, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_file_redirects( + async fn get_file_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetFileRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetFileRedirectsResponse, ApiError> { let context = context.clone(); info!( "get_file_redirects(\"{}\") - X-Span-ID: {:?}", ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_file_revision( + async fn get_file_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFileRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetFileRevisionResponse, ApiError> { let context = context.clone(); info!( "get_file_revision(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1059,16 +1052,16 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_fileset( + async fn get_fileset( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFilesetResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetResponse, ApiError> { let context = context.clone(); info!( "get_fileset(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1077,29 +1070,29 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_fileset_edit( + async fn get_fileset_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetFilesetEditResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetEditResponse, ApiError> { let context = context.clone(); info!( "get_fileset_edit(\"{}\") - X-Span-ID: {:?}", edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_fileset_history( + async fn get_fileset_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetFilesetHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetHistoryResponse, ApiError> { let context = context.clone(); info!( "get_fileset_history(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1107,30 +1100,30 @@ where limit, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_fileset_redirects( + async fn get_fileset_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetFilesetRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetRedirectsResponse, ApiError> { let context = context.clone(); info!( "get_fileset_redirects(\"{}\") - X-Span-ID: {:?}", ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_fileset_revision( + async fn get_fileset_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFilesetRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetRevisionResponse, ApiError> { let context = context.clone(); info!( "get_fileset_revision(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1139,16 +1132,16 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_release( + async fn get_release( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseResponse, ApiError> { let context = context.clone(); info!( "get_release(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1157,29 +1150,29 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_release_edit( + async fn get_release_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetReleaseEditResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseEditResponse, ApiError> { let context = context.clone(); info!( "get_release_edit(\"{}\") - X-Span-ID: {:?}", edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_release_files( + async fn get_release_files( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseFilesResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseFilesResponse, ApiError> { let context = context.clone(); info!( "get_release_files(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1187,15 +1180,15 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_release_filesets( + async fn get_release_filesets( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseFilesetsResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseFilesetsResponse, ApiError> { let context = context.clone(); info!( "get_release_filesets(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1203,15 +1196,15 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_release_history( + async fn get_release_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseHistoryResponse, ApiError> { let context = context.clone(); info!( "get_release_history(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1219,30 +1212,30 @@ where limit, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_release_redirects( + async fn get_release_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetReleaseRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseRedirectsResponse, ApiError> { let context = context.clone(); info!( "get_release_redirects(\"{}\") - X-Span-ID: {:?}", ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_release_revision( + async fn get_release_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseRevisionResponse, ApiError> { let context = context.clone(); info!( "get_release_revision(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1251,15 +1244,15 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_release_webcaptures( + async fn get_release_webcaptures( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseWebcapturesResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseWebcapturesResponse, ApiError> { let context = context.clone(); info!( "get_release_webcaptures(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1267,16 +1260,16 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_webcapture( + async fn get_webcapture( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureResponse, ApiError> { let context = context.clone(); info!( "get_webcapture(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1285,29 +1278,29 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_webcapture_edit( + async fn get_webcapture_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureEditResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureEditResponse, ApiError> { let context = context.clone(); info!( "get_webcapture_edit(\"{}\") - X-Span-ID: {:?}", edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_webcapture_history( + async fn get_webcapture_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureHistoryResponse, ApiError> { let context = context.clone(); info!( "get_webcapture_history(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1315,30 +1308,30 @@ where limit, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_webcapture_redirects( + async fn get_webcapture_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureRedirectsResponse, ApiError> { let context = context.clone(); info!( "get_webcapture_redirects(\"{}\") - X-Span-ID: {:?}", ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_webcapture_revision( + async fn get_webcapture_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureRevisionResponse, ApiError> { let context = context.clone(); info!( "get_webcapture_revision(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1347,16 +1340,16 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_work( + async fn get_work( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWorkResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkResponse, ApiError> { let context = context.clone(); info!( "get_work(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1365,29 +1358,29 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_work_edit( + async fn get_work_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetWorkEditResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkEditResponse, ApiError> { let context = context.clone(); info!( "get_work_edit(\"{}\") - X-Span-ID: {:?}", edit_id, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_work_history( + async fn get_work_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetWorkHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkHistoryResponse, ApiError> { let context = context.clone(); info!( "get_work_history(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1395,29 +1388,29 @@ where limit, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_work_redirects( + async fn get_work_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetWorkRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkRedirectsResponse, ApiError> { let context = context.clone(); info!( "get_work_redirects(\"{}\") - X-Span-ID: {:?}", ident, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_work_releases( + async fn get_work_releases( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWorkReleasesResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkReleasesResponse, ApiError> { let context = context.clone(); info!( "get_work_releases(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1425,16 +1418,16 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn get_work_revision( + async fn get_work_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWorkRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkRevisionResponse, ApiError> { let context = context.clone(); info!( "get_work_revision(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1443,17 +1436,17 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn lookup_container( + async fn lookup_container( &self, issnl: Option<String>, wikidata_qid: Option<String>, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupContainerResponse, Error = ApiError> + Send> { + ) -> Result<LookupContainerResponse, ApiError> { let context = context.clone(); info!( "lookup_container({:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", @@ -1463,17 +1456,17 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn lookup_creator( + async fn lookup_creator( &self, orcid: Option<String>, wikidata_qid: Option<String>, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupCreatorResponse, Error = ApiError> + Send> { + ) -> Result<LookupCreatorResponse, ApiError> { let context = context.clone(); info!( "lookup_creator({:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", @@ -1483,10 +1476,10 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn lookup_file( + async fn lookup_file( &self, md5: Option<String>, sha1: Option<String>, @@ -1494,7 +1487,7 @@ where expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupFileResponse, Error = ApiError> + Send> { + ) -> Result<LookupFileResponse, ApiError> { let context = context.clone(); info!( "lookup_file({:?}, {:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", @@ -1505,10 +1498,10 @@ where hide, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn lookup_release( + async fn lookup_release( &self, doi: Option<String>, wikidata_qid: Option<String>, @@ -1520,22 +1513,25 @@ where jstor: Option<String>, ark: Option<String>, mag: Option<String>, + doaj: Option<String>, + dblp: Option<String>, + oai: Option<String>, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupReleaseResponse, Error = ApiError> + Send> { + ) -> Result<LookupReleaseResponse, ApiError> { let context = context.clone(); - info!("lookup_release({:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", doi, wikidata_qid, isbn13, pmid, pmcid, core, arxiv, jstor, ark, mag, expand, hide, context.get().0.clone()); - Box::new(future::err("Generic failure".into())) + info!("lookup_release({:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", doi, wikidata_qid, isbn13, pmid, pmcid, core, arxiv, jstor, ark, mag, doaj, dblp, oai, expand, hide, context.get().0.clone()); + Err("Generic failuare".into()) } - fn update_container( + async fn update_container( &self, editgroup_id: String, ident: String, container_entity: models::ContainerEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateContainerResponse, Error = ApiError> + Send> { + ) -> Result<UpdateContainerResponse, ApiError> { let context = context.clone(); info!( "update_container(\"{}\", \"{}\", {:?}) - X-Span-ID: {:?}", @@ -1544,16 +1540,16 @@ where container_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn update_creator( + async fn update_creator( &self, editgroup_id: String, ident: String, creator_entity: models::CreatorEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateCreatorResponse, Error = ApiError> + Send> { + ) -> Result<UpdateCreatorResponse, ApiError> { let context = context.clone(); info!( "update_creator(\"{}\", \"{}\", {:?}) - X-Span-ID: {:?}", @@ -1562,16 +1558,16 @@ where creator_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn update_editgroup( + async fn update_editgroup( &self, editgroup_id: String, editgroup: models::Editgroup, submit: Option<bool>, context: &C, - ) -> Box<dyn Future<Item = UpdateEditgroupResponse, Error = ApiError> + Send> { + ) -> Result<UpdateEditgroupResponse, ApiError> { let context = context.clone(); info!( "update_editgroup(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}", @@ -1580,15 +1576,15 @@ where submit, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn update_editor( + async fn update_editor( &self, editor_id: String, editor: models::Editor, context: &C, - ) -> Box<dyn Future<Item = UpdateEditorResponse, Error = ApiError> + Send> { + ) -> Result<UpdateEditorResponse, ApiError> { let context = context.clone(); info!( "update_editor(\"{}\", {:?}) - X-Span-ID: {:?}", @@ -1596,16 +1592,16 @@ where editor, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn update_file( + async fn update_file( &self, editgroup_id: String, ident: String, file_entity: models::FileEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateFileResponse, Error = ApiError> + Send> { + ) -> Result<UpdateFileResponse, ApiError> { let context = context.clone(); info!( "update_file(\"{}\", \"{}\", {:?}) - X-Span-ID: {:?}", @@ -1614,16 +1610,16 @@ where file_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn update_fileset( + async fn update_fileset( &self, editgroup_id: String, ident: String, fileset_entity: models::FilesetEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateFilesetResponse, Error = ApiError> + Send> { + ) -> Result<UpdateFilesetResponse, ApiError> { let context = context.clone(); info!( "update_fileset(\"{}\", \"{}\", {:?}) - X-Span-ID: {:?}", @@ -1632,16 +1628,16 @@ where fileset_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn update_release( + async fn update_release( &self, editgroup_id: String, ident: String, release_entity: models::ReleaseEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateReleaseResponse, Error = ApiError> + Send> { + ) -> Result<UpdateReleaseResponse, ApiError> { let context = context.clone(); info!( "update_release(\"{}\", \"{}\", {:?}) - X-Span-ID: {:?}", @@ -1650,16 +1646,16 @@ where release_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn update_webcapture( + async fn update_webcapture( &self, editgroup_id: String, ident: String, webcapture_entity: models::WebcaptureEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<UpdateWebcaptureResponse, ApiError> { let context = context.clone(); info!( "update_webcapture(\"{}\", \"{}\", {:?}) - X-Span-ID: {:?}", @@ -1668,16 +1664,16 @@ where webcapture_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } - fn update_work( + async fn update_work( &self, editgroup_id: String, ident: String, work_entity: models::WorkEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateWorkResponse, Error = ApiError> + Send> { + ) -> Result<UpdateWorkResponse, ApiError> { let context = context.clone(); info!( "update_work(\"{}\", \"{}\", {:?}) - X-Span-ID: {:?}", @@ -1686,6 +1682,6 @@ where work_entity, context.get().0.clone() ); - Box::new(future::err("Generic failure".into())) + Err("Generic failuare".into()) } } diff --git a/rust/fatcat-openapi/src/client/mod.rs b/rust/fatcat-openapi/src/client/mod.rs index 06ecf4c..bb1cee8 100644 --- a/rust/fatcat-openapi/src/client/mod.rs +++ b/rust/fatcat-openapi/src/client/mod.rs @@ -1,37 +1,45 @@ -use futures; -use futures::{future, stream, Future, Stream}; -use hyper; -use hyper::client::HttpConnector; +use async_trait::async_trait; +use futures::{ + future, future::BoxFuture, future::FutureExt, future::TryFutureExt, stream, stream::StreamExt, + Stream, +}; use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE}; -use hyper::{Body, Response, Uri}; -#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] -use hyper_openssl::HttpsConnector; -use serde_json; +use hyper::{service::Service, Body, Request, Response, Uri}; +use percent_encoding::{utf8_percent_encode, AsciiSet}; use std::borrow::Cow; use std::convert::TryInto; -use std::error; +use std::error::Error; use std::fmt; -use std::io::{Error, ErrorKind, Read}; +use std::future::Future; +use std::io::{ErrorKind, Read}; +use std::marker::PhantomData; use std::path::Path; use std::str; use std::str::FromStr; use std::string::ToString; -use std::sync::Arc; -use swagger; -use swagger::{client::Service, ApiError, AuthData, Connector, Has, XSpanIdString}; +use std::sync::{Arc, Mutex}; +use std::task::{Context, Poll}; +use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; -use url::percent_encoding::{utf8_percent_encode, PATH_SEGMENT_ENCODE_SET, QUERY_ENCODE_SET}; use crate::header; use crate::models; -url::define_encode_set! { - /// This encode set is used for object IDs - /// - /// Aside from the special characters defined in the `PATH_SEGMENT_ENCODE_SET`, - /// the vertical bar (|) is encoded. - pub ID_ENCODE_SET = [PATH_SEGMENT_ENCODE_SET] | {'|'} -} +/// https://url.spec.whatwg.org/#fragment-percent-encode-set +#[allow(dead_code)] +const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS + .add(b' ') + .add(b'"') + .add(b'<') + .add(b'>') + .add(b'`'); + +/// This encode set is used for object IDs +/// +/// Aside from the special characters defined in the `PATH_SEGMENT_ENCODE_SET`, +/// the vertical bar (|) is encoded. +#[allow(dead_code)] +const ID_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET.add(b'|'); use crate::{ AcceptEditgroupResponse, Api, AuthCheckResponse, AuthOidcResponse, CreateAuthTokenResponse, @@ -67,13 +75,13 @@ use crate::{ /// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes. fn into_base_path( - input: &str, + input: impl TryInto<Uri, Error = hyper::http::uri::InvalidUri>, correct_scheme: Option<&'static str>, ) -> Result<String, ClientInitError> { // First convert to Uri, since a base path is a subset of Uri. - let uri = Uri::from_str(input)?; + let uri = input.try_into()?; - let scheme = uri.scheme_part().ok_or(ClientInitError::InvalidScheme)?; + let scheme = uri.scheme_str().ok_or(ClientInitError::InvalidScheme)?; // Check the scheme if necessary if let Some(correct_scheme) = correct_scheme { @@ -84,7 +92,7 @@ fn into_base_path( let host = uri.host().ok_or_else(|| ClientInitError::MissingHost)?; let port = uri - .port_part() + .port_u16() .map(|x| format!(":{}", x)) .unwrap_or_default(); Ok(format!( @@ -97,30 +105,56 @@ fn into_base_path( } /// A client that implements the API by making HTTP calls out to a server. -pub struct Client<F> { +pub struct Client<S, C> +where + S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static, + S::Future: Send + 'static, + S::Error: Into<crate::ServiceError> + fmt::Display, + C: Clone + Send + Sync + 'static, +{ /// Inner service - client_service: Arc<Box<dyn Service<ReqBody = Body, Future = F> + Send + Sync>>, + client_service: S, /// Base path of the API base_path: String, + + /// Marker + marker: PhantomData<fn(C)>, } -impl<F> fmt::Debug for Client<F> { +impl<S, C> fmt::Debug for Client<S, C> +where + S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static, + S::Future: Send + 'static, + S::Error: Into<crate::ServiceError> + fmt::Display, + C: Clone + Send + Sync + 'static, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } -impl<F> Clone for Client<F> { +impl<S, C> Clone for Client<S, C> +where + S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static, + S::Future: Send + 'static, + S::Error: Into<crate::ServiceError> + fmt::Display, + C: Clone + Send + Sync + 'static, +{ fn clone(&self) -> Self { - Client { + Self { client_service: self.client_service.clone(), base_path: self.base_path.clone(), + marker: PhantomData, } } } -impl Client<hyper::client::ResponseFuture> { +impl<Connector, C> Client<DropContextService<hyper::client::Client<Connector, Body>, C>, C> +where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static, +{ /// Create a client with a custom implementation of hyper::client::Connect. /// /// Intended for use with custom implementations of connect for e.g. protocol logging @@ -132,41 +166,120 @@ impl Client<hyper::client::ResponseFuture> { /// /// # Arguments /// - /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com" + /// * `base_path` - base path of the client API, i.e. "http://www.my-api-implementation.com" /// * `protocol` - Which protocol to use when constructing the request url, e.g. `Some("http")` /// * `connector` - Implementation of `hyper::client::Connect` to use for the client - pub fn try_new_with_connector<C>( + pub fn try_new_with_connector( base_path: &str, protocol: Option<&'static str>, - connector: C, - ) -> Result<Self, ClientInitError> - where - C: hyper::client::connect::Connect + 'static, - C::Transport: 'static, - C::Future: 'static, - { - let client_service = Box::new(hyper::client::Client::builder().build(connector)); + connector: Connector, + ) -> Result<Self, ClientInitError> { + let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); - Ok(Client { - client_service: Arc::new(client_service), + Ok(Self { + client_service, base_path: into_base_path(base_path, protocol)?, + marker: PhantomData, + }) + } +} + +#[derive(Debug, Clone)] +pub enum HyperClient { + Http(hyper::client::Client<hyper::client::HttpConnector, Body>), + Https(hyper::client::Client<HttpsConnector, Body>), +} + +impl Service<Request<Body>> for HyperClient { + type Response = Response<Body>; + type Error = hyper::Error; + type Future = hyper::client::ResponseFuture; + + fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> { + match self { + HyperClient::Http(client) => client.poll_ready(cx), + HyperClient::Https(client) => client.poll_ready(cx), + } + } + + fn call(&mut self, req: Request<Body>) -> Self::Future { + match self { + HyperClient::Http(client) => client.call(req), + HyperClient::Https(client) => client.call(req), + } + } +} + +impl<C> Client<DropContextService<HyperClient, C>, C> +where + C: Clone + Send + Sync + 'static, +{ + /// Create an HTTP client. + /// + /// # Arguments + /// * `base_path` - base path of the client API, i.e. "http://www.my-api-implementation.com" + pub fn try_new(base_path: &str) -> Result<Self, ClientInitError> { + let uri = Uri::from_str(base_path)?; + + let scheme = uri.scheme_str().ok_or(ClientInitError::InvalidScheme)?; + let scheme = scheme.to_ascii_lowercase(); + + let connector = Connector::builder(); + + let client_service = match scheme.as_str() { + "http" => HyperClient::Http(hyper::client::Client::builder().build(connector.build())), + "https" => { + let connector = connector + .https() + .build() + .map_err(|e| ClientInitError::SslError(e))?; + HyperClient::Https(hyper::client::Client::builder().build(connector)) + } + _ => { + return Err(ClientInitError::InvalidScheme); + } + }; + + let client_service = DropContextService::new(client_service); + + Ok(Self { + client_service, + base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } +} +impl<C> Client<DropContextService<hyper::client::Client<hyper::client::HttpConnector, Body>, C>, C> +where + C: Clone + Send + Sync + 'static, +{ /// Create an HTTP client. /// /// # Arguments - /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com" + /// * `base_path` - base path of the client API, i.e. "http://www.my-api-implementation.com" pub fn try_new_http(base_path: &str) -> Result<Self, ClientInitError> { let http_connector = Connector::builder().build(); Self::try_new_with_connector(base_path, Some("http"), http_connector) } +} + +#[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))] +type HttpsConnector = hyper_tls::HttpsConnector<hyper::client::HttpConnector>; + +#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] +type HttpsConnector = hyper_openssl::HttpsConnector<hyper::client::HttpConnector>; +impl<C> Client<DropContextService<hyper::client::Client<HttpsConnector, Body>, C>, C> +where + C: Clone + Send + Sync + 'static, +{ /// Create a client with a TLS connection to the server /// /// # Arguments - /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com" + /// * `base_path` - base path of the client API, i.e. "https://www.my-api-implementation.com" pub fn try_new_https(base_path: &str) -> Result<Self, ClientInitError> { let https_connector = Connector::builder() .https() @@ -178,7 +291,7 @@ impl Client<hyper::client::ResponseFuture> { /// Create a client with a TLS connection to the server using a pinned certificate /// /// # Arguments - /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com" + /// * `base_path` - base path of the client API, i.e. "https://www.my-api-implementation.com" /// * `ca_certificate` - Path to CA certificate used to authenticate the server #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] pub fn try_new_https_pinned<CA>( @@ -199,7 +312,7 @@ impl Client<hyper::client::ResponseFuture> { /// Create a client with a mutually authenticated TLS connection to the server. /// /// # Arguments - /// * `base_path` - base path of the client API, i.e. "www.my-api-implementation.com" + /// * `base_path` - base path of the client API, i.e. "https://www.my-api-implementation.com" /// * `ca_certificate` - Path to CA certificate used to authenticate the server /// * `client_key` - Path to the client private key /// * `client_certificate` - Path to the client's public certificate associated with the private key @@ -225,17 +338,25 @@ impl Client<hyper::client::ResponseFuture> { } } -impl<F> Client<F> { - /// Constructor for creating a `Client` by passing in a pre-made `swagger::Service` +impl<S, C> Client<S, C> +where + S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static, + S::Future: Send + 'static, + S::Error: Into<crate::ServiceError> + fmt::Display, + C: Clone + Send + Sync + 'static, +{ + /// Constructor for creating a `Client` by passing in a pre-made `hyper::service::Service` / + /// `tower::Service` /// /// This allows adding custom wrappers around the underlying transport, for example for logging. pub fn try_new_with_client_service( - client_service: Arc<Box<dyn Service<ReqBody = Body, Future = F> + Send + Sync>>, + client_service: S, base_path: &str, ) -> Result<Self, ClientInitError> { - Ok(Client { - client_service: client_service, + Ok(Self { + client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } @@ -274,22 +395,34 @@ impl fmt::Display for ClientInitError { } } -impl error::Error for ClientInitError { +impl Error for ClientInitError { fn description(&self) -> &str { "Failed to produce a hyper client." } } -impl<C, F> Api<C> for Client<F> +#[async_trait] +impl<S, C> Api<C> for Client<S, C> where - C: Has<XSpanIdString> + Has<Option<AuthData>>, - F: Future<Item = Response<Body>, Error = hyper::Error> + Send + 'static, + S: Service<(Request<Body>, C), Response = Response<Body>> + Clone + Sync + Send + 'static, + S::Future: Send + 'static, + S::Error: Into<crate::ServiceError> + fmt::Display, + C: Has<XSpanIdString> + Has<Option<AuthData>> + Clone + Send + Sync + 'static, { - fn accept_editgroup( + fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), crate::ServiceError>> { + match self.client_service.clone().poll_ready(cx) { + Poll::Ready(Err(e)) => Poll::Ready(Err(e.into())), + Poll::Ready(Ok(o)) => Poll::Ready(Ok(o)), + Poll::Pending => Poll::Pending, + } + } + + async fn accept_editgroup( &self, param_editgroup_id: String, context: &C, - ) -> Box<dyn Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> { + ) -> Result<AcceptEditgroupResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/accept", self.base_path, @@ -297,40 +430,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -341,15 +465,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -357,10 +481,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -371,233 +495,170 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Success>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AcceptEditgroupResponse::MergedSuccessfully - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AcceptEditgroupResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AcceptEditgroupResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Success>(body)?; + Ok(AcceptEditgroupResponse::MergedSuccessfully(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AcceptEditgroupResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AcceptEditgroupResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AcceptEditgroupResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 409 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AcceptEditgroupResponse::EditConflict - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AcceptEditgroupResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AcceptEditgroupResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AcceptEditgroupResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AcceptEditgroupResponse::NotFound(body)) + } + 409 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AcceptEditgroupResponse::EditConflict(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AcceptEditgroupResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn auth_check( + async fn auth_check( &self, param_role: Option<String>, context: &C, - ) -> Box<dyn Future<Item = AuthCheckResponse, Error = ApiError> + Send> { + ) -> Result<AuthCheckResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/auth/check", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_role) = param_role { - query_string.append_pair("role", ¶m_role.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_role) = param_role { + query_string.append_pair("role", ¶m_role.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -608,15 +669,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -624,10 +685,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -638,185 +699,141 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Success>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthCheckResponse::Success - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthCheckResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthCheckResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Success>(body)?; + Ok(AuthCheckResponse::Success(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AuthCheckResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthCheckResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthCheckResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AuthCheckResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AuthCheckResponse::Forbidden(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AuthCheckResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn auth_oidc( + async fn auth_oidc( &self, param_auth_oidc: models::AuthOidc, context: &C, - ) -> Box<dyn Future<Item = AuthOidcResponse, Error = ApiError> + Send> { + ) -> Result<AuthOidcResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/auth/oidc", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -829,16 +846,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -849,15 +865,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -865,10 +881,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -879,194 +895,140 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::AuthOidcResult>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthOidcResponse::Found - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::AuthOidcResult>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthOidcResponse::Created - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthOidcResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthOidcResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::AuthOidcResult>(body)?; + Ok(AuthOidcResponse::Found(body)) + } + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::AuthOidcResult>(body)?; + Ok(AuthOidcResponse::Created(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AuthOidcResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthOidcResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 409 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthOidcResponse::Conflict - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - AuthOidcResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AuthOidcResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AuthOidcResponse::Forbidden(body)) + } + 409 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AuthOidcResponse::Conflict(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(AuthOidcResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_auth_token( + async fn create_auth_token( &self, param_editor_id: String, param_duration_seconds: Option<i32>, context: &C, - ) -> Box<dyn Future<Item = CreateAuthTokenResponse, Error = ApiError> + Send> { + ) -> Result<CreateAuthTokenResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/auth/token/{editor_id}", self.base_path, @@ -1074,43 +1036,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_duration_seconds) = param_duration_seconds { - query_string.append_pair("duration_seconds", ¶m_duration_seconds.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_duration_seconds) = param_duration_seconds { + query_string.append_pair("duration_seconds", ¶m_duration_seconds.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -1121,15 +1074,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -1137,10 +1090,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -1151,154 +1104,118 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::AuthTokenResult>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateAuthTokenResponse::Success - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateAuthTokenResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateAuthTokenResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::AuthTokenResult>(body)?; + Ok(CreateAuthTokenResponse::Success(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateAuthTokenResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateAuthTokenResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateAuthTokenResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateAuthTokenResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateAuthTokenResponse::Forbidden(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateAuthTokenResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_container( + async fn create_container( &self, param_editgroup_id: String, param_container_entity: models::ContainerEntity, context: &C, - ) -> Box<dyn Future<Item = CreateContainerResponse, Error = ApiError> + Send> { + ) -> Result<CreateContainerResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/container", self.base_path, @@ -1306,35 +1223,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_container_entity) @@ -1347,16 +1256,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -1367,15 +1275,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -1383,10 +1291,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -1397,205 +1305,152 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerResponse::CreatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(CreateContainerResponse::CreatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_container_auto_batch( + async fn create_container_auto_batch( &self, param_container_auto_batch: models::ContainerAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateContainerAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateContainerAutoBatchResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/container/batch", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_container_auto_batch) @@ -1608,16 +1463,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -1628,15 +1482,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -1644,10 +1498,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -1658,174 +1512,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerAutoBatchResponse::CreatedEditgroup - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerAutoBatchResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerAutoBatchResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(CreateContainerAutoBatchResponse::CreatedEditgroup(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerAutoBatchResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerAutoBatchResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerAutoBatchResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateContainerAutoBatchResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerAutoBatchResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerAutoBatchResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerAutoBatchResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateContainerAutoBatchResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_creator( + async fn create_creator( &self, param_editgroup_id: String, param_creator_entity: models::CreatorEntity, context: &C, - ) -> Box<dyn Future<Item = CreateCreatorResponse, Error = ApiError> + Send> { + ) -> Result<CreateCreatorResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/creator", self.base_path, @@ -1833,35 +1642,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -1874,16 +1675,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -1894,15 +1694,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -1910,10 +1710,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -1924,205 +1724,152 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorResponse::CreatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(CreateCreatorResponse::CreatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_creator_auto_batch( + async fn create_creator_auto_batch( &self, param_creator_auto_batch: models::CreatorAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateCreatorAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateCreatorAutoBatchResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/creator/batch", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_creator_auto_batch) @@ -2135,16 +1882,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -2155,15 +1901,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -2171,10 +1917,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -2185,205 +1931,152 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorAutoBatchResponse::CreatedEditgroup - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorAutoBatchResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorAutoBatchResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(CreateCreatorAutoBatchResponse::CreatedEditgroup(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorAutoBatchResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorAutoBatchResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorAutoBatchResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateCreatorAutoBatchResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorAutoBatchResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorAutoBatchResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorAutoBatchResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateCreatorAutoBatchResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_editgroup( + async fn create_editgroup( &self, param_editgroup: models::Editgroup, context: &C, - ) -> Box<dyn Future<Item = CreateEditgroupResponse, Error = ApiError> + Send> { + ) -> Result<CreateEditgroupResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -2396,16 +2089,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -2416,15 +2108,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -2432,10 +2124,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -2446,174 +2138,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupResponse::SuccessfullyCreated - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(CreateEditgroupResponse::SuccessfullyCreated(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_editgroup_annotation( + async fn create_editgroup_annotation( &self, param_editgroup_id: String, param_editgroup_annotation: models::EditgroupAnnotation, context: &C, - ) -> Box<dyn Future<Item = CreateEditgroupAnnotationResponse, Error = ApiError> + Send> { + ) -> Result<CreateEditgroupAnnotationResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/annotation", self.base_path, @@ -2621,35 +2268,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_editgroup_annotation) @@ -2662,16 +2301,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -2682,15 +2320,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -2698,10 +2336,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -2712,174 +2350,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EditgroupAnnotation>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupAnnotationResponse::Created - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupAnnotationResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupAnnotationResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EditgroupAnnotation>(body)?; + Ok(CreateEditgroupAnnotationResponse::Created(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupAnnotationResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupAnnotationResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupAnnotationResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateEditgroupAnnotationResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupAnnotationResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupAnnotationResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupAnnotationResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateEditgroupAnnotationResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_file( + async fn create_file( &self, param_editgroup_id: String, param_file_entity: models::FileEntity, context: &C, - ) -> Box<dyn Future<Item = CreateFileResponse, Error = ApiError> + Send> { + ) -> Result<CreateFileResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/file", self.base_path, @@ -2887,35 +2480,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -2928,16 +2513,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -2948,15 +2532,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -2964,10 +2548,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -2978,205 +2562,152 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileResponse::CreatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(CreateFileResponse::CreatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_file_auto_batch( + async fn create_file_auto_batch( &self, param_file_auto_batch: models::FileAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateFileAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateFileAutoBatchResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/file/batch", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -3189,16 +2720,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -3209,15 +2739,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -3225,10 +2755,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -3239,174 +2769,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileAutoBatchResponse::CreatedEditgroup - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileAutoBatchResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileAutoBatchResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(CreateFileAutoBatchResponse::CreatedEditgroup(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileAutoBatchResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileAutoBatchResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileAutoBatchResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFileAutoBatchResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileAutoBatchResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileAutoBatchResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileAutoBatchResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFileAutoBatchResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_fileset( + async fn create_fileset( &self, param_editgroup_id: String, param_fileset_entity: models::FilesetEntity, context: &C, - ) -> Box<dyn Future<Item = CreateFilesetResponse, Error = ApiError> + Send> { + ) -> Result<CreateFilesetResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/fileset", self.base_path, @@ -3414,35 +2899,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -3455,16 +2932,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -3475,15 +2951,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -3491,10 +2967,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -3505,205 +2981,152 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetResponse::CreatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(CreateFilesetResponse::CreatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_fileset_auto_batch( + async fn create_fileset_auto_batch( &self, param_fileset_auto_batch: models::FilesetAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateFilesetAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateFilesetAutoBatchResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/fileset/batch", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_fileset_auto_batch) @@ -3716,16 +3139,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -3736,15 +3158,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -3752,10 +3174,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -3766,174 +3188,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetAutoBatchResponse::CreatedEditgroup - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetAutoBatchResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetAutoBatchResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(CreateFilesetAutoBatchResponse::CreatedEditgroup(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetAutoBatchResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetAutoBatchResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetAutoBatchResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateFilesetAutoBatchResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetAutoBatchResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetAutoBatchResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetAutoBatchResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateFilesetAutoBatchResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_release( + async fn create_release( &self, param_editgroup_id: String, param_release_entity: models::ReleaseEntity, context: &C, - ) -> Box<dyn Future<Item = CreateReleaseResponse, Error = ApiError> + Send> { + ) -> Result<CreateReleaseResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/release", self.base_path, @@ -3941,35 +3318,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -3982,16 +3351,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -4002,15 +3370,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -4018,10 +3386,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -4032,205 +3400,152 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseResponse::CreatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(CreateReleaseResponse::CreatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_release_auto_batch( + async fn create_release_auto_batch( &self, param_release_auto_batch: models::ReleaseAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateReleaseAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateReleaseAutoBatchResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/release/batch", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_release_auto_batch) @@ -4243,16 +3558,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -4263,15 +3577,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -4279,10 +3593,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -4293,174 +3607,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseAutoBatchResponse::CreatedEditgroup - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseAutoBatchResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseAutoBatchResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(CreateReleaseAutoBatchResponse::CreatedEditgroup(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseAutoBatchResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseAutoBatchResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseAutoBatchResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateReleaseAutoBatchResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseAutoBatchResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseAutoBatchResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseAutoBatchResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateReleaseAutoBatchResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_webcapture( + async fn create_webcapture( &self, param_editgroup_id: String, param_webcapture_entity: models::WebcaptureEntity, context: &C, - ) -> Box<dyn Future<Item = CreateWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<CreateWebcaptureResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/webcapture", self.base_path, @@ -4468,35 +3737,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_webcapture_entity) @@ -4509,16 +3770,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -4529,15 +3789,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -4545,10 +3805,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -4559,205 +3819,152 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureResponse::CreatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(CreateWebcaptureResponse::CreatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_webcapture_auto_batch( + async fn create_webcapture_auto_batch( &self, param_webcapture_auto_batch: models::WebcaptureAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateWebcaptureAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateWebcaptureAutoBatchResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/webcapture/batch", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_webcapture_auto_batch) @@ -4770,16 +3977,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -4790,15 +3996,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -4806,10 +4012,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -4820,174 +4026,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureAutoBatchResponse::CreatedEditgroup - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureAutoBatchResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureAutoBatchResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(CreateWebcaptureAutoBatchResponse::CreatedEditgroup(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureAutoBatchResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureAutoBatchResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureAutoBatchResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWebcaptureAutoBatchResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureAutoBatchResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureAutoBatchResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureAutoBatchResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWebcaptureAutoBatchResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_work( + async fn create_work( &self, param_editgroup_id: String, param_work_entity: models::WorkEntity, context: &C, - ) -> Box<dyn Future<Item = CreateWorkResponse, Error = ApiError> + Send> { + ) -> Result<CreateWorkResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/work", self.base_path, @@ -4995,35 +4156,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -5036,16 +4189,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -5056,15 +4208,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -5072,10 +4224,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -5086,205 +4238,152 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkResponse::CreatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(CreateWorkResponse::CreatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn create_work_auto_batch( + async fn create_work_auto_batch( &self, param_work_auto_batch: models::WorkAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateWorkAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateWorkAutoBatchResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/auto/work/batch", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("POST") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -5297,16 +4396,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -5317,15 +4415,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -5333,10 +4431,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -5347,174 +4445,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 201 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkAutoBatchResponse::CreatedEditgroup - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkAutoBatchResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkAutoBatchResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 201 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(CreateWorkAutoBatchResponse::CreatedEditgroup(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkAutoBatchResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkAutoBatchResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkAutoBatchResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - CreateWorkAutoBatchResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkAutoBatchResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkAutoBatchResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkAutoBatchResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(CreateWorkAutoBatchResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_container( + async fn delete_container( &self, param_editgroup_id: String, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteContainerResponse, Error = ApiError> + Send> { + ) -> Result<DeleteContainerResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/container/{ident}", self.base_path, @@ -5523,40 +4576,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -5567,15 +4611,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -5583,10 +4627,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -5597,174 +4641,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerResponse::DeletedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(DeleteContainerResponse::DeletedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_container_edit( + async fn delete_container_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteContainerEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteContainerEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/container/edit/{edit_id}", self.base_path, @@ -5773,40 +4772,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -5817,15 +4807,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -5833,10 +4823,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -5847,174 +4837,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Success>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerEditResponse::DeletedEdit - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerEditResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerEditResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Success>(body)?; + Ok(DeleteContainerEditResponse::DeletedEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerEditResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerEditResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerEditResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteContainerEditResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerEditResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerEditResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteContainerEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_creator( + async fn delete_creator( &self, param_editgroup_id: String, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteCreatorResponse, Error = ApiError> + Send> { + ) -> Result<DeleteCreatorResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/creator/{ident}", self.base_path, @@ -6023,40 +4968,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -6067,15 +5003,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -6083,10 +5019,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -6097,174 +5033,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorResponse::DeletedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(DeleteCreatorResponse::DeletedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_creator_edit( + async fn delete_creator_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteCreatorEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteCreatorEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/creator/edit/{edit_id}", self.base_path, @@ -6273,40 +5164,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -6317,15 +5199,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -6333,10 +5215,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -6347,174 +5229,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Success>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorEditResponse::DeletedEdit - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorEditResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorEditResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Success>(body)?; + Ok(DeleteCreatorEditResponse::DeletedEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorEditResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorEditResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorEditResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteCreatorEditResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorEditResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorEditResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteCreatorEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_file( + async fn delete_file( &self, param_editgroup_id: String, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFileResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFileResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/file/{ident}", self.base_path, @@ -6523,40 +5360,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -6567,15 +5395,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -6583,10 +5411,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -6597,174 +5425,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileResponse::DeletedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(DeleteFileResponse::DeletedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_file_edit( + async fn delete_file_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFileEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFileEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/file/edit/{edit_id}", self.base_path, @@ -6773,40 +5556,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -6817,15 +5591,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -6833,10 +5607,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -6847,174 +5621,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Success>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileEditResponse::DeletedEdit - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileEditResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileEditResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Success>(body)?; + Ok(DeleteFileEditResponse::DeletedEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileEditResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileEditResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileEditResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFileEditResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileEditResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileEditResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFileEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_fileset( + async fn delete_fileset( &self, param_editgroup_id: String, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFilesetResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFilesetResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/fileset/{ident}", self.base_path, @@ -7023,40 +5752,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -7067,15 +5787,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -7083,10 +5803,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -7097,174 +5817,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetResponse::DeletedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(DeleteFilesetResponse::DeletedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_fileset_edit( + async fn delete_fileset_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFilesetEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFilesetEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/fileset/edit/{edit_id}", self.base_path, @@ -7273,40 +5948,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -7317,15 +5983,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -7333,10 +5999,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -7347,174 +6013,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Success>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetEditResponse::DeletedEdit - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetEditResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetEditResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Success>(body)?; + Ok(DeleteFilesetEditResponse::DeletedEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetEditResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetEditResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetEditResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteFilesetEditResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetEditResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetEditResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteFilesetEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_release( + async fn delete_release( &self, param_editgroup_id: String, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteReleaseResponse, Error = ApiError> + Send> { + ) -> Result<DeleteReleaseResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/release/{ident}", self.base_path, @@ -7523,40 +6144,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -7567,15 +6179,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -7583,10 +6195,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -7597,174 +6209,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseResponse::DeletedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(DeleteReleaseResponse::DeletedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_release_edit( + async fn delete_release_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteReleaseEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteReleaseEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/release/edit/{edit_id}", self.base_path, @@ -7773,40 +6340,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -7817,15 +6375,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -7833,10 +6391,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -7847,174 +6405,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Success>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseEditResponse::DeletedEdit - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseEditResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseEditResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Success>(body)?; + Ok(DeleteReleaseEditResponse::DeletedEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseEditResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseEditResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseEditResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteReleaseEditResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseEditResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseEditResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteReleaseEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_webcapture( + async fn delete_webcapture( &self, param_editgroup_id: String, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWebcaptureResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/webcapture/{ident}", self.base_path, @@ -8023,40 +6536,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -8067,15 +6571,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -8083,10 +6587,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -8097,174 +6601,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureResponse::DeletedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(DeleteWebcaptureResponse::DeletedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_webcapture_edit( + async fn delete_webcapture_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWebcaptureEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWebcaptureEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/webcapture/edit/{edit_id}", self.base_path, @@ -8273,40 +6732,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -8317,15 +6767,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -8333,10 +6783,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -8347,174 +6797,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Success>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureEditResponse::DeletedEdit - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureEditResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureEditResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Success>(body)?; + Ok(DeleteWebcaptureEditResponse::DeletedEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureEditResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureEditResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureEditResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWebcaptureEditResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureEditResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureEditResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWebcaptureEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_work( + async fn delete_work( &self, param_editgroup_id: String, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWorkResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWorkResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/work/{ident}", self.base_path, @@ -8523,40 +6928,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -8567,15 +6963,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -8583,10 +6979,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -8597,174 +6993,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkResponse::DeletedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(DeleteWorkResponse::DeletedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn delete_work_edit( + async fn delete_work_edit( &self, param_editgroup_id: String, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWorkEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWorkEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/work/edit/{edit_id}", self.base_path, @@ -8773,40 +7124,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("DELETE") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -8817,15 +7159,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -8833,10 +7175,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -8847,213 +7189,159 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Success>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkEditResponse::DeletedEdit - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkEditResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkEditResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Success>(body)?; + Ok(DeleteWorkEditResponse::DeletedEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkEditResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkEditResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkEditResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - DeleteWorkEditResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkEditResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkEditResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(DeleteWorkEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn get_changelog( + async fn get_changelog( &self, param_limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetChangelogResponse, Error = ApiError> + Send> { + ) -> Result<GetChangelogResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/changelog", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -9064,102 +7352,78 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::ChangelogEntry>>( - body, - ) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetChangelogResponse::Success(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetChangelogResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetChangelogResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::ChangelogEntry>>(body)?; + Ok(GetChangelogResponse::Success(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetChangelogResponse::BadRequest(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetChangelogResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_changelog_entry( + async fn get_changelog_entry( &self, param_index: i64, context: &C, - ) -> Box<dyn Future<Item = GetChangelogEntryResponse, Error = ApiError> + Send> { + ) -> Result<GetChangelogEntryResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/changelog/{index}", self.base_path, @@ -9167,40 +7431,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -9211,122 +7466,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ChangelogEntry>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetChangelogEntryResponse::FoundChangelogEntry(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetChangelogEntryResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetChangelogEntryResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetChangelogEntryResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ChangelogEntry>(body)?; + Ok(GetChangelogEntryResponse::FoundChangelogEntry(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetChangelogEntryResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetChangelogEntryResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetChangelogEntryResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_container( + async fn get_container( &self, param_ident: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetContainerResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/{ident}", self.base_path, @@ -9334,46 +7558,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -9384,118 +7599,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ContainerEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ContainerEntity>(body)?; + Ok(GetContainerResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_container_edit( + async fn get_container_edit( &self, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetContainerEditResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/edit/{edit_id}", self.base_path, @@ -9503,40 +7689,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -9547,119 +7724,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerEditResponse::FoundEdit(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerEditResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerEditResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerEditResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(GetContainerEditResponse::FoundEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerEditResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_container_history( + async fn get_container_history( &self, param_ident: String, param_limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetContainerHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerHistoryResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/{ident}/history", self.base_path, @@ -9667,43 +7815,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -9714,122 +7853,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::EntityHistoryEntry>>( - body, - ) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetContainerHistoryResponse::FoundEntityHistory(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerHistoryResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerHistoryResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerHistoryResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::EntityHistoryEntry>>(body)?; + Ok(GetContainerHistoryResponse::FoundEntityHistory(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerHistoryResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerHistoryResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerHistoryResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_container_redirects( + async fn get_container_redirects( &self, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = GetContainerRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerRedirectsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/{ident}/redirects", self.base_path, @@ -9837,40 +7943,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -9881,122 +7978,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<String>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetContainerRedirectsResponse::FoundEntityRedirects(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerRedirectsResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerRedirectsResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerRedirectsResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<String>>(body)?; + Ok(GetContainerRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerRedirectsResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerRedirectsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerRedirectsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_container_revision( + async fn get_container_revision( &self, param_rev_id: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetContainerRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerRevisionResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/container/rev/{rev_id}", self.base_path, @@ -10004,46 +8070,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -10054,122 +8111,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ContainerEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetContainerRevisionResponse::FoundEntityRevision(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerRevisionResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerRevisionResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetContainerRevisionResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ContainerEntity>(body)?; + Ok(GetContainerRevisionResponse::FoundEntityRevision(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerRevisionResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerRevisionResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetContainerRevisionResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_creator( + async fn get_creator( &self, param_ident: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/{ident}", self.base_path, @@ -10177,46 +8203,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -10227,118 +8244,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::CreatorEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::CreatorEntity>(body)?; + Ok(GetCreatorResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_creator_edit( + async fn get_creator_edit( &self, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetCreatorEditResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/edit/{edit_id}", self.base_path, @@ -10346,40 +8334,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -10390,119 +8369,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorEditResponse::FoundEdit(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorEditResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorEditResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorEditResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(GetCreatorEditResponse::FoundEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorEditResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_creator_history( + async fn get_creator_history( &self, param_ident: String, param_limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorHistoryResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/{ident}/history", self.base_path, @@ -10510,43 +8460,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -10557,122 +8498,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::EntityHistoryEntry>>( - body, - ) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetCreatorHistoryResponse::FoundEntityHistory(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorHistoryResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorHistoryResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorHistoryResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::EntityHistoryEntry>>(body)?; + Ok(GetCreatorHistoryResponse::FoundEntityHistory(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorHistoryResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorHistoryResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorHistoryResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_creator_redirects( + async fn get_creator_redirects( &self, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = GetCreatorRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorRedirectsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/{ident}/redirects", self.base_path, @@ -10680,40 +8588,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -10724,121 +8623,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<String>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetCreatorRedirectsResponse::FoundEntityRedirects(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorRedirectsResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorRedirectsResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorRedirectsResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<String>>(body)?; + Ok(GetCreatorRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorRedirectsResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorRedirectsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorRedirectsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_creator_releases( + async fn get_creator_releases( &self, param_ident: String, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorReleasesResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorReleasesResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/{ident}/releases", self.base_path, @@ -10846,43 +8714,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -10893,120 +8752,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::ReleaseEntity>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorReleasesResponse::Found(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorReleasesResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorReleasesResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorReleasesResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::ReleaseEntity>>(body)?; + Ok(GetCreatorReleasesResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorReleasesResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorReleasesResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorReleasesResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_creator_revision( + async fn get_creator_revision( &self, param_rev_id: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorRevisionResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/creator/rev/{rev_id}", self.base_path, @@ -11014,46 +8844,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -11064,120 +8885,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::CreatorEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetCreatorRevisionResponse::FoundEntityRevision(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorRevisionResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorRevisionResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetCreatorRevisionResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::CreatorEntity>(body)?; + Ok(GetCreatorRevisionResponse::FoundEntityRevision(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorRevisionResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorRevisionResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetCreatorRevisionResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_editgroup( + async fn get_editgroup( &self, param_editgroup_id: String, context: &C, - ) -> Box<dyn Future<Item = GetEditgroupResponse, Error = ApiError> + Send> { + ) -> Result<GetEditgroupResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}", self.base_path, @@ -11185,40 +8975,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -11229,119 +9010,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditgroupResponse::Found(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditgroupResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditgroupResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditgroupResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(GetEditgroupResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_editgroup_annotations( + async fn get_editgroup_annotations( &self, param_editgroup_id: String, param_expand: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetEditgroupAnnotationsResponse, Error = ApiError> + Send> { + ) -> Result<GetEditgroupAnnotationsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/annotations", self.base_path, @@ -11349,43 +9101,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -11396,233 +9139,179 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<Vec<models::EditgroupAnnotation>>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditgroupAnnotationsResponse::Success - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditgroupAnnotationsResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditgroupAnnotationsResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::EditgroupAnnotation>>(body)?; + Ok(GetEditgroupAnnotationsResponse::Success(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupAnnotationsResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditgroupAnnotationsResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditgroupAnnotationsResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditgroupAnnotationsResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupAnnotationsResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupAnnotationsResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupAnnotationsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupAnnotationsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn get_editgroups_reviewable( + async fn get_editgroups_reviewable( &self, param_expand: Option<String>, param_limit: Option<i64>, param_before: Option<chrono::DateTime<chrono::Utc>>, param_since: Option<chrono::DateTime<chrono::Utc>>, context: &C, - ) -> Box<dyn Future<Item = GetEditgroupsReviewableResponse, Error = ApiError> + Send> { + ) -> Result<GetEditgroupsReviewableResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/editgroup/reviewable", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - if let Some(param_before) = param_before { - query_string.append_pair("before", ¶m_before.to_string()); - } - if let Some(param_since) = param_since { - query_string.append_pair("since", ¶m_since.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + if let Some(param_before) = param_before { + query_string.append_pair("before", ¶m_before.to_string()); + } + if let Some(param_since) = param_since { + query_string.append_pair("since", ¶m_since.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -11633,120 +9322,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::Editgroup>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditgroupsReviewableResponse::Found(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditgroupsReviewableResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditgroupsReviewableResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetEditgroupsReviewableResponse::GenericError(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::Editgroup>>(body)?; + Ok(GetEditgroupsReviewableResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupsReviewableResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupsReviewableResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditgroupsReviewableResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_editor( + async fn get_editor( &self, param_editor_id: String, context: &C, - ) -> Box<dyn Future<Item = GetEditorResponse, Error = ApiError> + Send> { + ) -> Result<GetEditorResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editor/{editor_id}", self.base_path, @@ -11754,40 +9412,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -11798,121 +9447,92 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::Editor>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditorResponse::Found(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditorResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditorResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditorResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editor>(body)?; + Ok(GetEditorResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_editor_annotations( + async fn get_editor_annotations( &self, param_editor_id: String, param_limit: Option<i64>, param_before: Option<chrono::DateTime<chrono::Utc>>, param_since: Option<chrono::DateTime<chrono::Utc>>, context: &C, - ) -> Box<dyn Future<Item = GetEditorAnnotationsResponse, Error = ApiError> + Send> { + ) -> Result<GetEditorAnnotationsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editor/{editor_id}/annotations", self.base_path, @@ -11920,49 +9540,40 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - if let Some(param_before) = param_before { - query_string.append_pair("before", ¶m_before.to_string()); - } - if let Some(param_since) = param_since { - query_string.append_pair("since", ¶m_since.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + if let Some(param_before) = param_before { + query_string.append_pair("before", ¶m_before.to_string()); + } + if let Some(param_since) = param_since { + query_string.append_pair("since", ¶m_since.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -11973,184 +9584,139 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<Vec<models::EditgroupAnnotation>>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditorAnnotationsResponse::Success - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditorAnnotationsResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditorAnnotationsResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::EditgroupAnnotation>>(body)?; + Ok(GetEditorAnnotationsResponse::Success(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorAnnotationsResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditorAnnotationsResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditorAnnotationsResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - GetEditorAnnotationsResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorAnnotationsResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorAnnotationsResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorAnnotationsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorAnnotationsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn get_editor_editgroups( + async fn get_editor_editgroups( &self, param_editor_id: String, param_limit: Option<i64>, param_before: Option<chrono::DateTime<chrono::Utc>>, param_since: Option<chrono::DateTime<chrono::Utc>>, context: &C, - ) -> Box<dyn Future<Item = GetEditorEditgroupsResponse, Error = ApiError> + Send> { + ) -> Result<GetEditorEditgroupsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editor/{editor_id}/editgroups", self.base_path, @@ -12158,49 +9724,40 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - if let Some(param_before) = param_before { - query_string.append_pair("before", ¶m_before.to_string()); - } - if let Some(param_since) = param_since { - query_string.append_pair("since", ¶m_since.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + if let Some(param_before) = param_before { + query_string.append_pair("before", ¶m_before.to_string()); + } + if let Some(param_since) = param_since { + query_string.append_pair("since", ¶m_since.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -12211,120 +9768,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::Editgroup>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditorEditgroupsResponse::Found(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditorEditgroupsResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditorEditgroupsResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetEditorEditgroupsResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::Editgroup>>(body)?; + Ok(GetEditorEditgroupsResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorEditgroupsResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorEditgroupsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetEditorEditgroupsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_file( + async fn get_file( &self, param_ident: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFileResponse, Error = ApiError> + Send> { + ) -> Result<GetFileResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/{ident}", self.base_path, @@ -12332,46 +9860,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -12382,118 +9901,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::FileEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::FileEntity>(body)?; + Ok(GetFileResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_file_edit( + async fn get_file_edit( &self, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetFileEditResponse, Error = ApiError> + Send> { + ) -> Result<GetFileEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/edit/{edit_id}", self.base_path, @@ -12501,40 +9991,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -12545,119 +10026,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileEditResponse::FoundEdit(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileEditResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileEditResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileEditResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(GetFileEditResponse::FoundEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileEditResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_file_history( + async fn get_file_history( &self, param_ident: String, param_limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetFileHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetFileHistoryResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/{ident}/history", self.base_path, @@ -12665,43 +10117,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -12712,120 +10155,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::EntityHistoryEntry>>( - body, - ) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileHistoryResponse::FoundEntityHistory(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileHistoryResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileHistoryResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileHistoryResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::EntityHistoryEntry>>(body)?; + Ok(GetFileHistoryResponse::FoundEntityHistory(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileHistoryResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileHistoryResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileHistoryResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_file_redirects( + async fn get_file_redirects( &self, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = GetFileRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetFileRedirectsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/{ident}/redirects", self.base_path, @@ -12833,40 +10245,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -12877,122 +10280,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<String>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetFileRedirectsResponse::FoundEntityRedirects(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileRedirectsResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileRedirectsResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileRedirectsResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<String>>(body)?; + Ok(GetFileRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileRedirectsResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileRedirectsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileRedirectsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_file_revision( + async fn get_file_revision( &self, param_rev_id: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFileRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetFileRevisionResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/file/rev/{rev_id}", self.base_path, @@ -13000,46 +10372,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -13050,122 +10413,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::FileEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetFileRevisionResponse::FoundEntityRevision(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileRevisionResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileRevisionResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFileRevisionResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::FileEntity>(body)?; + Ok(GetFileRevisionResponse::FoundEntityRevision(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileRevisionResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileRevisionResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFileRevisionResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_fileset( + async fn get_fileset( &self, param_ident: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFilesetResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/{ident}", self.base_path, @@ -13173,46 +10505,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -13223,118 +10546,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::FilesetEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::FilesetEntity>(body)?; + Ok(GetFilesetResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_fileset_edit( + async fn get_fileset_edit( &self, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetFilesetEditResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/edit/{edit_id}", self.base_path, @@ -13342,40 +10636,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -13386,119 +10671,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetEditResponse::FoundEdit(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetEditResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetEditResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetEditResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(GetFilesetEditResponse::FoundEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetEditResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_fileset_history( + async fn get_fileset_history( &self, param_ident: String, param_limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetFilesetHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetHistoryResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/{ident}/history", self.base_path, @@ -13506,43 +10762,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -13553,122 +10800,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::EntityHistoryEntry>>( - body, - ) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetFilesetHistoryResponse::FoundEntityHistory(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetHistoryResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetHistoryResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetHistoryResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::EntityHistoryEntry>>(body)?; + Ok(GetFilesetHistoryResponse::FoundEntityHistory(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetHistoryResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetHistoryResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetHistoryResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_fileset_redirects( + async fn get_fileset_redirects( &self, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = GetFilesetRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetRedirectsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/{ident}/redirects", self.base_path, @@ -13676,40 +10890,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -13720,122 +10925,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<String>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetFilesetRedirectsResponse::FoundEntityRedirects(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetRedirectsResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetRedirectsResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetRedirectsResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<String>>(body)?; + Ok(GetFilesetRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetRedirectsResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetRedirectsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetRedirectsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_fileset_revision( + async fn get_fileset_revision( &self, param_rev_id: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFilesetRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetRevisionResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/fileset/rev/{rev_id}", self.base_path, @@ -13843,46 +11017,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -13893,122 +11058,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::FilesetEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetFilesetRevisionResponse::FoundEntityRevision(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetRevisionResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetRevisionResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetFilesetRevisionResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::FilesetEntity>(body)?; + Ok(GetFilesetRevisionResponse::FoundEntityRevision(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetRevisionResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetRevisionResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetFilesetRevisionResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_release( + async fn get_release( &self, param_ident: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}", self.base_path, @@ -14016,46 +11150,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -14066,118 +11191,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ReleaseEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ReleaseEntity>(body)?; + Ok(GetReleaseResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_release_edit( + async fn get_release_edit( &self, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetReleaseEditResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/edit/{edit_id}", self.base_path, @@ -14185,40 +11281,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -14229,119 +11316,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseEditResponse::FoundEdit(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseEditResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseEditResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseEditResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(GetReleaseEditResponse::FoundEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseEditResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_release_files( + async fn get_release_files( &self, param_ident: String, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseFilesResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseFilesResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/files", self.base_path, @@ -14349,43 +11407,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -14396,119 +11445,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::FileEntity>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseFilesResponse::Found(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseFilesResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseFilesResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseFilesResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::FileEntity>>(body)?; + Ok(GetReleaseFilesResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseFilesResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseFilesResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseFilesResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_release_filesets( + async fn get_release_filesets( &self, param_ident: String, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseFilesetsResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseFilesetsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/filesets", self.base_path, @@ -14516,43 +11536,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -14563,119 +11574,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::FilesetEntity>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseFilesetsResponse::Found(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseFilesetsResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseFilesetsResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseFilesetsResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::FilesetEntity>>(body)?; + Ok(GetReleaseFilesetsResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseFilesetsResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseFilesetsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseFilesetsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_release_history( + async fn get_release_history( &self, param_ident: String, param_limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseHistoryResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/history", self.base_path, @@ -14683,43 +11665,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -14730,122 +11703,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::EntityHistoryEntry>>( - body, - ) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetReleaseHistoryResponse::FoundEntityHistory(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseHistoryResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseHistoryResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseHistoryResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::EntityHistoryEntry>>(body)?; + Ok(GetReleaseHistoryResponse::FoundEntityHistory(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseHistoryResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseHistoryResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseHistoryResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_release_redirects( + async fn get_release_redirects( &self, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = GetReleaseRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseRedirectsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/redirects", self.base_path, @@ -14853,40 +11793,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -14897,122 +11828,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<String>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetReleaseRedirectsResponse::FoundEntityRedirects(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseRedirectsResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseRedirectsResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseRedirectsResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<String>>(body)?; + Ok(GetReleaseRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseRedirectsResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseRedirectsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseRedirectsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_release_revision( + async fn get_release_revision( &self, param_rev_id: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseRevisionResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/rev/{rev_id}", self.base_path, @@ -15020,46 +11920,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -15070,121 +11961,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ReleaseEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetReleaseRevisionResponse::FoundEntityRevision(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseRevisionResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseRevisionResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseRevisionResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ReleaseEntity>(body)?; + Ok(GetReleaseRevisionResponse::FoundEntityRevision(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseRevisionResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseRevisionResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseRevisionResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_release_webcaptures( + async fn get_release_webcaptures( &self, param_ident: String, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseWebcapturesResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseWebcapturesResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/release/{ident}/webcaptures", self.base_path, @@ -15192,43 +12052,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -15239,122 +12090,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::WebcaptureEntity>>( - body, - ) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseWebcapturesResponse::Found(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseWebcapturesResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseWebcapturesResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetReleaseWebcapturesResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::WebcaptureEntity>>(body)?; + Ok(GetReleaseWebcapturesResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseWebcapturesResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseWebcapturesResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetReleaseWebcapturesResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_webcapture( + async fn get_webcapture( &self, param_ident: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/{ident}", self.base_path, @@ -15362,46 +12182,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -15412,118 +12223,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::WebcaptureEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::WebcaptureEntity>(body)?; + Ok(GetWebcaptureResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_webcapture_edit( + async fn get_webcapture_edit( &self, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureEditResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/edit/{edit_id}", self.base_path, @@ -15531,40 +12313,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -15575,119 +12348,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureEditResponse::FoundEdit(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureEditResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureEditResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureEditResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(GetWebcaptureEditResponse::FoundEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureEditResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_webcapture_history( + async fn get_webcapture_history( &self, param_ident: String, param_limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureHistoryResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/{ident}/history", self.base_path, @@ -15695,43 +12439,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -15742,122 +12477,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::EntityHistoryEntry>>( - body, - ) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetWebcaptureHistoryResponse::FoundEntityHistory(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureHistoryResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureHistoryResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureHistoryResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::EntityHistoryEntry>>(body)?; + Ok(GetWebcaptureHistoryResponse::FoundEntityHistory(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureHistoryResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureHistoryResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureHistoryResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_webcapture_redirects( + async fn get_webcapture_redirects( &self, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureRedirectsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/{ident}/redirects", self.base_path, @@ -15865,40 +12567,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -15909,124 +12602,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<String>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetWebcaptureRedirectsResponse::FoundEntityRedirects(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureRedirectsResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureRedirectsResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetWebcaptureRedirectsResponse::GenericError(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<String>>(body)?; + Ok(GetWebcaptureRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureRedirectsResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureRedirectsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureRedirectsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_webcapture_revision( + async fn get_webcapture_revision( &self, param_rev_id: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureRevisionResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/webcapture/rev/{rev_id}", self.base_path, @@ -16034,46 +12694,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -16084,122 +12735,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::WebcaptureEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetWebcaptureRevisionResponse::FoundEntityRevision(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureRevisionResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureRevisionResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWebcaptureRevisionResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::WebcaptureEntity>(body)?; + Ok(GetWebcaptureRevisionResponse::FoundEntityRevision(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureRevisionResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureRevisionResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWebcaptureRevisionResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_work( + async fn get_work( &self, param_ident: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWorkResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/{ident}", self.base_path, @@ -16207,46 +12827,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -16257,118 +12868,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::WorkEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::WorkEntity>(body)?; + Ok(GetWorkResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_work_edit( + async fn get_work_edit( &self, param_edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetWorkEditResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkEditResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/edit/{edit_id}", self.base_path, @@ -16376,40 +12958,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -16420,119 +12993,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkEditResponse::FoundEdit(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkEditResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkEditResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkEditResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(GetWorkEditResponse::FoundEdit(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkEditResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkEditResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkEditResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_work_history( + async fn get_work_history( &self, param_ident: String, param_limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetWorkHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkHistoryResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/{ident}/history", self.base_path, @@ -16540,43 +13084,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_limit) = param_limit { - query_string.append_pair("limit", ¶m_limit.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_limit) = param_limit { + query_string.append_pair("limit", ¶m_limit.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -16587,120 +13122,89 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::EntityHistoryEntry>>( - body, - ) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkHistoryResponse::FoundEntityHistory(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkHistoryResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkHistoryResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkHistoryResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::EntityHistoryEntry>>(body)?; + Ok(GetWorkHistoryResponse::FoundEntityHistory(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkHistoryResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkHistoryResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkHistoryResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_work_redirects( + async fn get_work_redirects( &self, param_ident: String, context: &C, - ) -> Box<dyn Future<Item = GetWorkRedirectsResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkRedirectsResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/{ident}/redirects", self.base_path, @@ -16708,40 +13212,31 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -16752,121 +13247,90 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<String>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetWorkRedirectsResponse::FoundEntityRedirects(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkRedirectsResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkRedirectsResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkRedirectsResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<String>>(body)?; + Ok(GetWorkRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkRedirectsResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkRedirectsResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkRedirectsResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_work_releases( + async fn get_work_releases( &self, param_ident: String, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWorkReleasesResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkReleasesResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/{ident}/releases", self.base_path, @@ -16874,43 +13338,34 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -16921,120 +13376,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<Vec<models::ReleaseEntity>>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkReleasesResponse::Found(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkReleasesResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkReleasesResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkReleasesResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<Vec<models::ReleaseEntity>>(body)?; + Ok(GetWorkReleasesResponse::Found(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkReleasesResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkReleasesResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkReleasesResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn get_work_revision( + async fn get_work_revision( &self, param_rev_id: String, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWorkRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkRevisionResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/work/rev/{rev_id}", self.base_path, @@ -17042,46 +13468,37 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -17092,172 +13509,132 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::WorkEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| { - GetWorkRevisionResponse::FoundEntityRevision(body) - }), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkRevisionResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkRevisionResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| GetWorkRevisionResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::WorkEntity>(body)?; + Ok(GetWorkRevisionResponse::FoundEntityRevision(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkRevisionResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkRevisionResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(GetWorkRevisionResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn lookup_container( + async fn lookup_container( &self, param_issnl: Option<String>, param_wikidata_qid: Option<String>, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupContainerResponse, Error = ApiError> + Send> { + ) -> Result<LookupContainerResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/container/lookup", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_issnl) = param_issnl { - query_string.append_pair("issnl", ¶m_issnl.to_string()); - } - if let Some(param_wikidata_qid) = param_wikidata_qid { - query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); - } - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_issnl) = param_issnl { + query_string.append_pair("issnl", ¶m_issnl.to_string()); + } + if let Some(param_wikidata_qid) = param_wikidata_qid { + query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); + } + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -17268,170 +13645,132 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ContainerEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupContainerResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupContainerResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupContainerResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupContainerResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ContainerEntity>(body)?; + Ok(LookupContainerResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupContainerResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupContainerResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupContainerResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn lookup_creator( + async fn lookup_creator( &self, param_orcid: Option<String>, param_wikidata_qid: Option<String>, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupCreatorResponse, Error = ApiError> + Send> { + ) -> Result<LookupCreatorResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/creator/lookup", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_orcid) = param_orcid { - query_string.append_pair("orcid", ¶m_orcid.to_string()); - } - if let Some(param_wikidata_qid) = param_wikidata_qid { - query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); - } - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_orcid) = param_orcid { + query_string.append_pair("orcid", ¶m_orcid.to_string()); + } + if let Some(param_wikidata_qid) = param_wikidata_qid { + query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); + } + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -17442,114 +13781,84 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::CreatorEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupCreatorResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupCreatorResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupCreatorResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupCreatorResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::CreatorEntity>(body)?; + Ok(LookupCreatorResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupCreatorResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupCreatorResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupCreatorResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn lookup_file( + async fn lookup_file( &self, param_md5: Option<String>, param_sha1: Option<String>, @@ -17557,59 +13866,51 @@ where param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupFileResponse, Error = ApiError> + Send> { + ) -> Result<LookupFileResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/file/lookup", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_md5) = param_md5 { - query_string.append_pair("md5", ¶m_md5.to_string()); - } - if let Some(param_sha1) = param_sha1 { - query_string.append_pair("sha1", ¶m_sha1.to_string()); - } - if let Some(param_sha256) = param_sha256 { - query_string.append_pair("sha256", ¶m_sha256.to_string()); - } - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_md5) = param_md5 { + query_string.append_pair("md5", ¶m_md5.to_string()); + } + if let Some(param_sha1) = param_sha1 { + query_string.append_pair("sha1", ¶m_sha1.to_string()); + } + if let Some(param_sha256) = param_sha256 { + query_string.append_pair("sha256", ¶m_sha256.to_string()); + } + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -17620,114 +13921,84 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::FileEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupFileResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupFileResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupFileResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupFileResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::FileEntity>(body)?; + Ok(LookupFileResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupFileResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupFileResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupFileResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn lookup_release( + async fn lookup_release( &self, param_doi: Option<String>, param_wikidata_qid: Option<String>, @@ -17739,83 +14010,87 @@ where param_jstor: Option<String>, param_ark: Option<String>, param_mag: Option<String>, + param_doaj: Option<String>, + param_dblp: Option<String>, + param_oai: Option<String>, param_expand: Option<String>, param_hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupReleaseResponse, Error = ApiError> + Send> { + ) -> Result<LookupReleaseResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!("{}/v0/release/lookup", self.base_path); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_doi) = param_doi { - query_string.append_pair("doi", ¶m_doi.to_string()); - } - if let Some(param_wikidata_qid) = param_wikidata_qid { - query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); - } - if let Some(param_isbn13) = param_isbn13 { - query_string.append_pair("isbn13", ¶m_isbn13.to_string()); - } - if let Some(param_pmid) = param_pmid { - query_string.append_pair("pmid", ¶m_pmid.to_string()); - } - if let Some(param_pmcid) = param_pmcid { - query_string.append_pair("pmcid", ¶m_pmcid.to_string()); - } - if let Some(param_core) = param_core { - query_string.append_pair("core", ¶m_core.to_string()); - } - if let Some(param_arxiv) = param_arxiv { - query_string.append_pair("arxiv", ¶m_arxiv.to_string()); - } - if let Some(param_jstor) = param_jstor { - query_string.append_pair("jstor", ¶m_jstor.to_string()); - } - if let Some(param_ark) = param_ark { - query_string.append_pair("ark", ¶m_ark.to_string()); - } - if let Some(param_mag) = param_mag { - query_string.append_pair("mag", ¶m_mag.to_string()); - } - if let Some(param_expand) = param_expand { - query_string.append_pair("expand", ¶m_expand.to_string()); - } - if let Some(param_hide) = param_hide { - query_string.append_pair("hide", ¶m_hide.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_doi) = param_doi { + query_string.append_pair("doi", ¶m_doi.to_string()); + } + if let Some(param_wikidata_qid) = param_wikidata_qid { + query_string.append_pair("wikidata_qid", ¶m_wikidata_qid.to_string()); + } + if let Some(param_isbn13) = param_isbn13 { + query_string.append_pair("isbn13", ¶m_isbn13.to_string()); + } + if let Some(param_pmid) = param_pmid { + query_string.append_pair("pmid", ¶m_pmid.to_string()); + } + if let Some(param_pmcid) = param_pmcid { + query_string.append_pair("pmcid", ¶m_pmcid.to_string()); + } + if let Some(param_core) = param_core { + query_string.append_pair("core", ¶m_core.to_string()); + } + if let Some(param_arxiv) = param_arxiv { + query_string.append_pair("arxiv", ¶m_arxiv.to_string()); + } + if let Some(param_jstor) = param_jstor { + query_string.append_pair("jstor", ¶m_jstor.to_string()); + } + if let Some(param_ark) = param_ark { + query_string.append_pair("ark", ¶m_ark.to_string()); + } + if let Some(param_mag) = param_mag { + query_string.append_pair("mag", ¶m_mag.to_string()); + } + if let Some(param_doaj) = param_doaj { + query_string.append_pair("doaj", ¶m_doaj.to_string()); + } + if let Some(param_dblp) = param_dblp { + query_string.append_pair("dblp", ¶m_dblp.to_string()); + } + if let Some(param_oai) = param_oai { + query_string.append_pair("oai", ¶m_oai.to_string()); + } + if let Some(param_expand) = param_expand { + query_string.append_pair("expand", ¶m_expand.to_string()); + } + if let Some(param_hide) = param_hide { + query_string.append_pair("hide", ¶m_hide.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("GET") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -17826,120 +14101,91 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - Box::new( - self.client_service - .request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ReleaseEntity>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupReleaseResponse::FoundEntity(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 400 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupReleaseResponse::BadRequest(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 404 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupReleaseResponse::NotFound(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - 500 => { - let body = response.into_body(); - Box::new( - body.concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| { - str::from_utf8(&body) - .map_err(|e| { - ApiError(format!("Response was not valid UTF8: {}", e)) - }) - .and_then(|body| { - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - }) - }) - .map(move |body| LookupReleaseResponse::GenericError(body)), - ) as Box<dyn Future<Item = _, Error = _> + Send> - } - code => { - let headers = response.headers().clone(); - Box::new(response.into_body().take(100).concat2().then(move |body| { - future::err(ApiError(format!( - "Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => - Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - } - ))) - })) as Box<dyn Future<Item = _, Error = _> + Send> + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ReleaseEntity>(body)?; + Ok(LookupReleaseResponse::FoundEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupReleaseResponse::BadRequest(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupReleaseResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(LookupReleaseResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), } - }), - ) + ))) + } + } } - fn update_container( + async fn update_container( &self, param_editgroup_id: String, param_ident: String, param_container_entity: models::ContainerEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateContainerResponse, Error = ApiError> + Send> { + ) -> Result<UpdateContainerResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/container/{ident}", self.base_path, @@ -17948,35 +14194,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_container_entity) @@ -17989,16 +14227,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -18009,15 +14246,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -18025,10 +14262,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -18039,175 +14276,130 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateContainerResponse::UpdatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateContainerResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateContainerResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(UpdateContainerResponse::UpdatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateContainerResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateContainerResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateContainerResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateContainerResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateContainerResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateContainerResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateContainerResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateContainerResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn update_creator( + async fn update_creator( &self, param_editgroup_id: String, param_ident: String, param_creator_entity: models::CreatorEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateCreatorResponse, Error = ApiError> + Send> { + ) -> Result<UpdateCreatorResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/creator/{ident}", self.base_path, @@ -18216,35 +14408,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -18257,16 +14441,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -18277,15 +14460,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -18293,10 +14476,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -18307,175 +14490,130 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateCreatorResponse::UpdatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateCreatorResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateCreatorResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(UpdateCreatorResponse::UpdatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateCreatorResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateCreatorResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateCreatorResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateCreatorResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateCreatorResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateCreatorResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateCreatorResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateCreatorResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn update_editgroup( + async fn update_editgroup( &self, param_editgroup_id: String, param_editgroup: models::Editgroup, param_submit: Option<bool>, context: &C, - ) -> Box<dyn Future<Item = UpdateEditgroupResponse, Error = ApiError> + Send> { + ) -> Result<UpdateEditgroupResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}", self.base_path, @@ -18483,38 +14621,30 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - if let Some(param_submit) = param_submit { - query_string.append_pair("submit", ¶m_submit.to_string()); - } - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + if let Some(param_submit) = param_submit { + query_string.append_pair("submit", ¶m_submit.to_string()); + } + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -18527,16 +14657,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -18547,15 +14676,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -18563,10 +14692,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -18577,174 +14706,129 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editgroup>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditgroupResponse::UpdatedEditgroup - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditgroupResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditgroupResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editgroup>(body)?; + Ok(UpdateEditgroupResponse::UpdatedEditgroup(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditgroupResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditgroupResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditgroupResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditgroupResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditgroupResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditgroupResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditgroupResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditgroupResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn update_editor( + async fn update_editor( &self, param_editor_id: String, param_editor: models::Editor, context: &C, - ) -> Box<dyn Future<Item = UpdateEditorResponse, Error = ApiError> + Send> { + ) -> Result<UpdateEditorResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editor/{editor_id}", self.base_path, @@ -18752,35 +14836,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_editor).expect("impossible to fail to serialize"); @@ -18792,16 +14868,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -18812,15 +14887,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -18828,10 +14903,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -18842,175 +14917,130 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::Editor>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditorResponse::UpdatedEditor - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditorResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditorResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::Editor>(body)?; + Ok(UpdateEditorResponse::UpdatedEditor(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditorResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditorResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditorResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateEditorResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditorResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditorResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditorResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateEditorResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn update_file( + async fn update_file( &self, param_editgroup_id: String, param_ident: String, param_file_entity: models::FileEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateFileResponse, Error = ApiError> + Send> { + ) -> Result<UpdateFileResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/file/{ident}", self.base_path, @@ -19019,35 +15049,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -19060,16 +15082,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -19080,15 +15101,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -19096,10 +15117,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -19110,175 +15131,130 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFileResponse::UpdatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFileResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFileResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(UpdateFileResponse::UpdatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFileResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFileResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFileResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFileResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFileResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFileResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFileResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFileResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn update_fileset( + async fn update_fileset( &self, param_editgroup_id: String, param_ident: String, param_fileset_entity: models::FilesetEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateFilesetResponse, Error = ApiError> + Send> { + ) -> Result<UpdateFilesetResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/fileset/{ident}", self.base_path, @@ -19287,35 +15263,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -19328,16 +15296,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -19348,15 +15315,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -19364,10 +15331,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -19378,175 +15345,130 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFilesetResponse::UpdatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFilesetResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFilesetResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(UpdateFilesetResponse::UpdatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFilesetResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFilesetResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFilesetResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateFilesetResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFilesetResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFilesetResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFilesetResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateFilesetResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn update_release( + async fn update_release( &self, param_editgroup_id: String, param_ident: String, param_release_entity: models::ReleaseEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateReleaseResponse, Error = ApiError> + Send> { + ) -> Result<UpdateReleaseResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/release/{ident}", self.base_path, @@ -19555,35 +15477,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -19596,16 +15510,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -19616,15 +15529,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -19632,10 +15545,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -19646,175 +15559,130 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateReleaseResponse::UpdatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateReleaseResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateReleaseResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(UpdateReleaseResponse::UpdatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateReleaseResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateReleaseResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateReleaseResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateReleaseResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateReleaseResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateReleaseResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateReleaseResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateReleaseResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn update_webcapture( + async fn update_webcapture( &self, param_editgroup_id: String, param_ident: String, param_webcapture_entity: models::WebcaptureEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<UpdateWebcaptureResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/webcapture/{ident}", self.base_path, @@ -19823,35 +15691,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = serde_json::to_string(¶m_webcapture_entity) @@ -19864,16 +15724,15 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -19884,15 +15743,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -19900,10 +15759,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -19914,175 +15773,130 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWebcaptureResponse::UpdatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWebcaptureResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWebcaptureResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(UpdateWebcaptureResponse::UpdatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWebcaptureResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWebcaptureResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWebcaptureResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWebcaptureResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWebcaptureResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWebcaptureResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWebcaptureResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWebcaptureResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } - fn update_work( + async fn update_work( &self, param_editgroup_id: String, param_ident: String, param_work_entity: models::WorkEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateWorkResponse, Error = ApiError> + Send> { + ) -> Result<UpdateWorkResponse, ApiError> { + let mut client_service = self.client_service.clone(); let mut uri = format!( "{}/v0/editgroup/{editgroup_id}/work/{ident}", self.base_path, @@ -20091,35 +15905,27 @@ where ); // Query parameters - let mut query_string = url::form_urlencoded::Serializer::new("".to_owned()); - let query_string_str = query_string.finish(); - if !query_string_str.is_empty() { + let query_string = { + let mut query_string = form_urlencoded::Serializer::new("".to_owned()); + query_string.finish() + }; + if !query_string.is_empty() { uri += "?"; - uri += &query_string_str; + uri += &query_string; } let uri = match Uri::from_str(&uri) { Ok(uri) => uri, - Err(err) => { - return Box::new(future::err(ApiError(format!( - "Unable to build URI: {}", - err - )))) - } + Err(err) => return Err(ApiError(format!("Unable to build URI: {}", err))), }; - let mut request = match hyper::Request::builder() + let mut request = match Request::builder() .method("PUT") .uri(uri) .body(Body::empty()) { Ok(req) => req, - Err(e) => { - return Box::new(future::err(ApiError(format!( - "Unable to create request: {}", - e - )))) - } + Err(e) => return Err(ApiError(format!("Unable to create request: {}", e))), }; let body = @@ -20133,17 +15939,16 @@ where match HeaderValue::from_str(header) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create header: {} - {}", header, e - )))) + ))) } }, ); let header = HeaderValue::from_str( - (context as &dyn Has<XSpanIdString>) - .get() + Has::<XSpanIdString>::get(context) .0 .clone() .to_string() @@ -20154,15 +15959,15 @@ where match header { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create X-Span ID header value: {}", e - )))) + ))) } }, ); - if let Some(auth_data) = (context as &dyn Has<Option<AuthData>>).get().as_ref() { + if let Some(auth_data) = Has::<Option<AuthData>>::get(context).as_ref() { // Currently only authentication with Basic and Bearer are supported match auth_data { &AuthData::Bearer(ref bearer_header) => { @@ -20170,10 +15975,10 @@ where let header = match HeaderValue::from_str(&format!("{}", auth)) { Ok(h) => h, Err(e) => { - return Box::new(future::err(ApiError(format!( + return Err(ApiError(format!( "Unable to create Authorization header: {}", e - )))) + ))) } }; request @@ -20184,165 +15989,119 @@ where } } - Box::new(self.client_service.request(request) - .map_err(|e| ApiError(format!("No response received: {}", e))) - .and_then(|mut response| { - match response.status().as_u16() { - 200 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::EntityEdit>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWorkResponse::UpdatedEntity - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 400 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWorkResponse::BadRequest - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 401 => { - let response_www_authenticate = match response.headers().get(HeaderName::from_static("www_authenticate")) { - Some(response_www_authenticate) => response_www_authenticate.clone(), - None => return Box::new(future::err(ApiError(String::from("Required response header WWW_Authenticate for response 401 was not found.")))) as Box<dyn Future<Item=_, Error=_> + Send>, - }; - let response_www_authenticate = match TryInto::<header::IntoHeaderValue<String>>::try_into(response_www_authenticate) { - Ok(value) => value, - Err(e) => { - return Box::new(future::err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e)))) as Box<dyn Future<Item=_, Error=_> + Send>; - }, - }; - let response_www_authenticate = response_www_authenticate.0; - - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWorkResponse::NotAuthorized - { - body: body, - www_authenticate: response_www_authenticate, + let mut response = client_service + .call((request, context.clone())) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .await?; + + match response.status().as_u16() { + 200 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::EntityEdit>(body)?; + Ok(UpdateWorkResponse::UpdatedEntity(body)) + } + 400 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWorkResponse::BadRequest(body)) + } + 401 => { + let response_www_authenticate = match response + .headers() + .get(HeaderName::from_static("www_authenticate")) + { + Some(response_www_authenticate) => { + let response_www_authenticate = response_www_authenticate.clone(); + let response_www_authenticate = match TryInto::< + header::IntoHeaderValue<String>, + >::try_into( + response_www_authenticate + ) { + Ok(value) => value, + Err(e) => { + return Err(ApiError(format!("Invalid response header WWW_Authenticate for response 401 - {}", e))); } - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 403 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWorkResponse::Forbidden - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 404 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWorkResponse::NotFound - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - 500 => { - let body = response.into_body(); - Box::new( - body - .concat2() - .map_err(|e| ApiError(format!("Failed to read response: {}", e))) - .and_then(|body| - str::from_utf8(&body) - .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e))) - .and_then(|body| - serde_json::from_str::<models::ErrorResponse>(body) - .map_err(|e| e.into()) - ) - ) - .map(move |body| { - UpdateWorkResponse::GenericError - (body) - }) - ) as Box<dyn Future<Item=_, Error=_> + Send> - }, - code => { - let headers = response.headers().clone(); - Box::new(response.into_body() - .take(100) - .concat2() - .then(move |body| - future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - headers, - match body { - Ok(ref body) => match str::from_utf8(body) { - Ok(body) => Cow::from(body), - Err(e) => Cow::from(format!("<Body was not UTF8: {:?}>", e)), - }, - Err(e) => Cow::from(format!("<Failed to read body: {}>", e)), - }))) - ) - ) as Box<dyn Future<Item=_, Error=_> + Send> - } + }; + let response_www_authenticate = response_www_authenticate.0; + Some(response_www_authenticate) + } + None => None, + }; + + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWorkResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate, + }) + } + 403 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWorkResponse::Forbidden(body)) + } + 404 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWorkResponse::NotFound(body)) + } + 500 => { + let body = response.into_body(); + let body = body + .to_raw() + .map_err(|e| ApiError(format!("Failed to read response: {}", e))) + .await?; + let body = str::from_utf8(&body) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::<models::ErrorResponse>(body)?; + Ok(UpdateWorkResponse::GenericError(body)) + } + code => { + let headers = response.headers().clone(); + let body = response.into_body().take(100).to_raw().await; + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(body) => match String::from_utf8(body) { + Ok(body) => body, + Err(e) => format!("<Body was not UTF8: {:?}>", e), + }, + Err(e) => format!("<Failed to read body: {}>", e), + } + ))) } - })) + } } } diff --git a/rust/fatcat-openapi/src/context.rs b/rust/fatcat-openapi/src/context.rs index 57d11be..d782855 100644 --- a/rust/fatcat-openapi/src/context.rs +++ b/rust/fatcat-openapi/src/context.rs @@ -1,13 +1,12 @@ use crate::Api; -use futures::Future; -use hyper; +use futures::future::BoxFuture; use hyper::header::HeaderName; -use hyper::{body::Payload, service::Service, Error, Request, Response, StatusCode}; +use hyper::{service::Service, Error, Request, Response, StatusCode}; use std::default::Default; use std::io; use std::marker::PhantomData; +use std::task::{Context, Poll}; use swagger::auth::{AuthData, Authorization, Bearer, Scopes}; -use swagger::context::ContextualPayload; use swagger::{EmptyContext, Has, Pop, Push, XSpanIdString}; use url::form_urlencoded; @@ -31,55 +30,49 @@ where } // Make a service that adds context. -impl<'a, T, SC, A, B, C, D, E, ME, S, OB, F> hyper::service::MakeService<&'a SC> - for MakeAddContext<T, A> +impl<Target, T, A, B, C, D> Service<Target> for MakeAddContext<T, A> where - A: Default + Push<XSpanIdString, Result = B>, + Target: Send, + A: Default + Push<XSpanIdString, Result = B> + Send, B: Push<Option<AuthData>, Result = C>, C: Push<Option<Authorization>, Result = D>, D: Send + 'static, - T: hyper::service::MakeService< - &'a SC, - Error = E, - MakeError = ME, - Service = S, - ReqBody = ContextualPayload<hyper::Body, D>, - ResBody = OB, - Future = F, - >, - S: Service<Error = E, ReqBody = ContextualPayload<hyper::Body, D>, ResBody = OB> + 'static, - ME: swagger::ErrorBound, - E: swagger::ErrorBound, - F: Future<Item = S, Error = ME> + Send + 'static, - S::Future: Send, - OB: Payload, + T: Service<Target> + Send, + T::Future: Send + 'static, { - type ReqBody = hyper::Body; - type ResBody = OB; - type Error = E; - type MakeError = ME; - type Service = AddContext<S, A>; - type Future = Box<dyn Future<Item = Self::Service, Error = ME> + Send + 'static>; + type Error = T::Error; + type Response = AddContext<T::Response, A, B, C, D>; + type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>; - fn make_service(&mut self, ctx: &'a SC) -> Self::Future { - Box::new(self.inner.make_service(ctx).map(|s| AddContext::new(s))) + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { + self.inner.poll_ready(cx) + } + + fn call(&mut self, target: Target) -> Self::Future { + let service = self.inner.call(target); + + Box::pin(async move { Ok(AddContext::new(service.await?)) }) } } -/// Middleware to extract authentication data from request -pub struct AddContext<T, A> { +/// Middleware to add context data from the request +pub struct AddContext<T, A, B, C, D> +where + A: Default + Push<XSpanIdString, Result = B>, + B: Push<Option<AuthData>, Result = C>, + C: Push<Option<Authorization>, Result = D>, +{ inner: T, marker: PhantomData<A>, } -impl<T, A, B, C, D> AddContext<T, A> +impl<T, A, B, C, D> AddContext<T, A, B, C, D> where A: Default + Push<XSpanIdString, Result = B>, B: Push<Option<AuthData>, Result = C>, C: Push<Option<Authorization>, Result = D>, - T: Service, { - pub fn new(inner: T) -> AddContext<T, A> { + pub fn new(inner: T) -> Self { AddContext { inner, marker: PhantomData, @@ -87,24 +80,25 @@ where } } -impl<T, A, B, C, D> Service for AddContext<T, A> +impl<T, A, B, C, D, ReqBody> Service<Request<ReqBody>> for AddContext<T, A, B, C, D> where A: Default + Push<XSpanIdString, Result = B>, B: Push<Option<AuthData>, Result = C>, C: Push<Option<Authorization>, Result = D>, D: Send + 'static, - T: Service<ReqBody = ContextualPayload<hyper::Body, D>>, - T::Future: Future<Item = Response<T::ResBody>, Error = T::Error> + Send + 'static, + T: Service<(Request<ReqBody>, D)>, { - type ReqBody = hyper::Body; - type ResBody = T::ResBody; type Error = T::Error; - type Future = Box<dyn Future<Item = Response<T::ResBody>, Error = T::Error> + Send + 'static>; + type Future = T::Future; + type Response = T::Response; - fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future { - let context = A::default().push(XSpanIdString::get_or_generate(&req)); - let (head, body) = req.into_parts(); - let headers = head.headers.clone(); + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { + self.inner.poll_ready(cx) + } + + fn call(&mut self, request: Request<ReqBody>) -> Self::Future { + let context = A::default().push(XSpanIdString::get_or_generate(&request)); + let headers = request.headers(); { use std::ops::Deref; @@ -114,22 +108,13 @@ where let context = context.push(Some(auth_data)); let context = context.push(None::<Authorization>); - let body = ContextualPayload { - inner: body, - context: context, - }; - - return Box::new(self.inner.call(hyper::Request::from_parts(head, body))); + return self.inner.call((request, context)); } } let context = context.push(None::<AuthData>); let context = context.push(None::<Authorization>); - let body = ContextualPayload { - inner: body, - context: context, - }; - Box::new(self.inner.call(hyper::Request::from_parts(head, body))) + self.inner.call((request, context)) } } diff --git a/rust/fatcat-openapi/src/lib.rs b/rust/fatcat-openapi/src/lib.rs index 1438bdf..ba49f27 100644 --- a/rust/fatcat-openapi/src/lib.rs +++ b/rust/fatcat-openapi/src/lib.rs @@ -8,16 +8,16 @@ non_camel_case_types )] +use async_trait::async_trait; use futures::Stream; -use std::io::Error; +use std::error::Error; +use std::task::{Context, Poll}; +use swagger::{ApiError, ContextWrapper}; -#[deprecated(note = "Import futures directly")] -pub use futures::Future; -#[deprecated(note = "Import swagger-rs directly")] -pub use swagger::{ApiError, ContextWrapper}; +type ServiceError = Box<dyn Error + Send + Sync + 'static>; pub const BASE_PATH: &'static str = "/v0"; -pub const API_VERSION: &'static str = "0.3.1"; +pub const API_VERSION: &'static str = "0.3.3"; #[derive(Debug, PartialEq)] #[must_use] @@ -29,7 +29,7 @@ pub enum AcceptEditgroupResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -51,7 +51,7 @@ pub enum AuthCheckResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -71,7 +71,7 @@ pub enum AuthOidcResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -91,7 +91,7 @@ pub enum CreateAuthTokenResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -109,7 +109,7 @@ pub enum CreateContainerResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -129,7 +129,7 @@ pub enum CreateContainerAutoBatchResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -149,7 +149,7 @@ pub enum CreateCreatorResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -169,7 +169,7 @@ pub enum CreateCreatorAutoBatchResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -189,7 +189,7 @@ pub enum CreateEditgroupResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -209,7 +209,7 @@ pub enum CreateEditgroupAnnotationResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -229,7 +229,7 @@ pub enum CreateFileResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -249,7 +249,7 @@ pub enum CreateFileAutoBatchResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -269,7 +269,7 @@ pub enum CreateFilesetResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -289,7 +289,7 @@ pub enum CreateFilesetAutoBatchResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -309,7 +309,7 @@ pub enum CreateReleaseResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -329,7 +329,7 @@ pub enum CreateReleaseAutoBatchResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -349,7 +349,7 @@ pub enum CreateWebcaptureResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -369,7 +369,7 @@ pub enum CreateWebcaptureAutoBatchResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -389,7 +389,7 @@ pub enum CreateWorkResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -409,7 +409,7 @@ pub enum CreateWorkAutoBatchResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -429,7 +429,7 @@ pub enum DeleteContainerResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -449,7 +449,7 @@ pub enum DeleteContainerEditResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -469,7 +469,7 @@ pub enum DeleteCreatorResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -489,7 +489,7 @@ pub enum DeleteCreatorEditResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -509,7 +509,7 @@ pub enum DeleteFileResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -529,7 +529,7 @@ pub enum DeleteFileEditResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -549,7 +549,7 @@ pub enum DeleteFilesetResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -569,7 +569,7 @@ pub enum DeleteFilesetEditResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -589,7 +589,7 @@ pub enum DeleteReleaseResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -609,7 +609,7 @@ pub enum DeleteReleaseEditResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -629,7 +629,7 @@ pub enum DeleteWebcaptureResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -649,7 +649,7 @@ pub enum DeleteWebcaptureEditResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -669,7 +669,7 @@ pub enum DeleteWorkResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -689,7 +689,7 @@ pub enum DeleteWorkEditResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -889,7 +889,7 @@ pub enum GetEditgroupAnnotationsResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -935,7 +935,7 @@ pub enum GetEditorAnnotationsResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1397,7 +1397,7 @@ pub enum UpdateContainerResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1417,7 +1417,7 @@ pub enum UpdateCreatorResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1437,7 +1437,7 @@ pub enum UpdateEditgroupResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1457,7 +1457,7 @@ pub enum UpdateEditorResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1477,7 +1477,7 @@ pub enum UpdateFileResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1497,7 +1497,7 @@ pub enum UpdateFilesetResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1517,7 +1517,7 @@ pub enum UpdateReleaseResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1537,7 +1537,7 @@ pub enum UpdateWebcaptureResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1557,7 +1557,7 @@ pub enum UpdateWorkResponse { /// Not Authorized NotAuthorized { body: models::ErrorResponse, - www_authenticate: String, + www_authenticate: Option<String>, }, /// Forbidden Forbidden(models::ErrorResponse), @@ -1568,591 +1568,599 @@ pub enum UpdateWorkResponse { } /// API -pub trait Api<C> { - fn accept_editgroup( +#[async_trait] +pub trait Api<C: Send + Sync> { + fn poll_ready( + &self, + _cx: &mut Context, + ) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>> { + Poll::Ready(Ok(())) + } + + async fn accept_editgroup( &self, editgroup_id: String, context: &C, - ) -> Box<dyn Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send>; + ) -> Result<AcceptEditgroupResponse, ApiError>; - fn auth_check( + async fn auth_check( &self, role: Option<String>, context: &C, - ) -> Box<dyn Future<Item = AuthCheckResponse, Error = ApiError> + Send>; + ) -> Result<AuthCheckResponse, ApiError>; - fn auth_oidc( + async fn auth_oidc( &self, auth_oidc: models::AuthOidc, context: &C, - ) -> Box<dyn Future<Item = AuthOidcResponse, Error = ApiError> + Send>; + ) -> Result<AuthOidcResponse, ApiError>; - fn create_auth_token( + async fn create_auth_token( &self, editor_id: String, duration_seconds: Option<i32>, context: &C, - ) -> Box<dyn Future<Item = CreateAuthTokenResponse, Error = ApiError> + Send>; + ) -> Result<CreateAuthTokenResponse, ApiError>; - fn create_container( + async fn create_container( &self, editgroup_id: String, container_entity: models::ContainerEntity, context: &C, - ) -> Box<dyn Future<Item = CreateContainerResponse, Error = ApiError> + Send>; + ) -> Result<CreateContainerResponse, ApiError>; - fn create_container_auto_batch( + async fn create_container_auto_batch( &self, container_auto_batch: models::ContainerAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateContainerAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateContainerAutoBatchResponse, ApiError>; - fn create_creator( + async fn create_creator( &self, editgroup_id: String, creator_entity: models::CreatorEntity, context: &C, - ) -> Box<dyn Future<Item = CreateCreatorResponse, Error = ApiError> + Send>; + ) -> Result<CreateCreatorResponse, ApiError>; - fn create_creator_auto_batch( + async fn create_creator_auto_batch( &self, creator_auto_batch: models::CreatorAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateCreatorAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateCreatorAutoBatchResponse, ApiError>; - fn create_editgroup( + async fn create_editgroup( &self, editgroup: models::Editgroup, context: &C, - ) -> Box<dyn Future<Item = CreateEditgroupResponse, Error = ApiError> + Send>; + ) -> Result<CreateEditgroupResponse, ApiError>; - fn create_editgroup_annotation( + async fn create_editgroup_annotation( &self, editgroup_id: String, editgroup_annotation: models::EditgroupAnnotation, context: &C, - ) -> Box<dyn Future<Item = CreateEditgroupAnnotationResponse, Error = ApiError> + Send>; + ) -> Result<CreateEditgroupAnnotationResponse, ApiError>; - fn create_file( + async fn create_file( &self, editgroup_id: String, file_entity: models::FileEntity, context: &C, - ) -> Box<dyn Future<Item = CreateFileResponse, Error = ApiError> + Send>; + ) -> Result<CreateFileResponse, ApiError>; - fn create_file_auto_batch( + async fn create_file_auto_batch( &self, file_auto_batch: models::FileAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateFileAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateFileAutoBatchResponse, ApiError>; - fn create_fileset( + async fn create_fileset( &self, editgroup_id: String, fileset_entity: models::FilesetEntity, context: &C, - ) -> Box<dyn Future<Item = CreateFilesetResponse, Error = ApiError> + Send>; + ) -> Result<CreateFilesetResponse, ApiError>; - fn create_fileset_auto_batch( + async fn create_fileset_auto_batch( &self, fileset_auto_batch: models::FilesetAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateFilesetAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateFilesetAutoBatchResponse, ApiError>; - fn create_release( + async fn create_release( &self, editgroup_id: String, release_entity: models::ReleaseEntity, context: &C, - ) -> Box<dyn Future<Item = CreateReleaseResponse, Error = ApiError> + Send>; + ) -> Result<CreateReleaseResponse, ApiError>; - fn create_release_auto_batch( + async fn create_release_auto_batch( &self, release_auto_batch: models::ReleaseAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateReleaseAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateReleaseAutoBatchResponse, ApiError>; - fn create_webcapture( + async fn create_webcapture( &self, editgroup_id: String, webcapture_entity: models::WebcaptureEntity, context: &C, - ) -> Box<dyn Future<Item = CreateWebcaptureResponse, Error = ApiError> + Send>; + ) -> Result<CreateWebcaptureResponse, ApiError>; - fn create_webcapture_auto_batch( + async fn create_webcapture_auto_batch( &self, webcapture_auto_batch: models::WebcaptureAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateWebcaptureAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateWebcaptureAutoBatchResponse, ApiError>; - fn create_work( + async fn create_work( &self, editgroup_id: String, work_entity: models::WorkEntity, context: &C, - ) -> Box<dyn Future<Item = CreateWorkResponse, Error = ApiError> + Send>; + ) -> Result<CreateWorkResponse, ApiError>; - fn create_work_auto_batch( + async fn create_work_auto_batch( &self, work_auto_batch: models::WorkAutoBatch, context: &C, - ) -> Box<dyn Future<Item = CreateWorkAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateWorkAutoBatchResponse, ApiError>; - fn delete_container( + async fn delete_container( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteContainerResponse, Error = ApiError> + Send>; + ) -> Result<DeleteContainerResponse, ApiError>; - fn delete_container_edit( + async fn delete_container_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteContainerEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteContainerEditResponse, ApiError>; - fn delete_creator( + async fn delete_creator( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteCreatorResponse, Error = ApiError> + Send>; + ) -> Result<DeleteCreatorResponse, ApiError>; - fn delete_creator_edit( + async fn delete_creator_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteCreatorEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteCreatorEditResponse, ApiError>; - fn delete_file( + async fn delete_file( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFileResponse, Error = ApiError> + Send>; + ) -> Result<DeleteFileResponse, ApiError>; - fn delete_file_edit( + async fn delete_file_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFileEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteFileEditResponse, ApiError>; - fn delete_fileset( + async fn delete_fileset( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFilesetResponse, Error = ApiError> + Send>; + ) -> Result<DeleteFilesetResponse, ApiError>; - fn delete_fileset_edit( + async fn delete_fileset_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteFilesetEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteFilesetEditResponse, ApiError>; - fn delete_release( + async fn delete_release( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteReleaseResponse, Error = ApiError> + Send>; + ) -> Result<DeleteReleaseResponse, ApiError>; - fn delete_release_edit( + async fn delete_release_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteReleaseEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteReleaseEditResponse, ApiError>; - fn delete_webcapture( + async fn delete_webcapture( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWebcaptureResponse, Error = ApiError> + Send>; + ) -> Result<DeleteWebcaptureResponse, ApiError>; - fn delete_webcapture_edit( + async fn delete_webcapture_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWebcaptureEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteWebcaptureEditResponse, ApiError>; - fn delete_work( + async fn delete_work( &self, editgroup_id: String, ident: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWorkResponse, Error = ApiError> + Send>; + ) -> Result<DeleteWorkResponse, ApiError>; - fn delete_work_edit( + async fn delete_work_edit( &self, editgroup_id: String, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = DeleteWorkEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteWorkEditResponse, ApiError>; - fn get_changelog( + async fn get_changelog( &self, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetChangelogResponse, Error = ApiError> + Send>; + ) -> Result<GetChangelogResponse, ApiError>; - fn get_changelog_entry( + async fn get_changelog_entry( &self, index: i64, context: &C, - ) -> Box<dyn Future<Item = GetChangelogEntryResponse, Error = ApiError> + Send>; + ) -> Result<GetChangelogEntryResponse, ApiError>; - fn get_container( + async fn get_container( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetContainerResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerResponse, ApiError>; - fn get_container_edit( + async fn get_container_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetContainerEditResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerEditResponse, ApiError>; - fn get_container_history( + async fn get_container_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetContainerHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerHistoryResponse, ApiError>; - fn get_container_redirects( + async fn get_container_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetContainerRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerRedirectsResponse, ApiError>; - fn get_container_revision( + async fn get_container_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetContainerRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerRevisionResponse, ApiError>; - fn get_creator( + async fn get_creator( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorResponse, ApiError>; - fn get_creator_edit( + async fn get_creator_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetCreatorEditResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorEditResponse, ApiError>; - fn get_creator_history( + async fn get_creator_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorHistoryResponse, ApiError>; - fn get_creator_redirects( + async fn get_creator_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetCreatorRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorRedirectsResponse, ApiError>; - fn get_creator_releases( + async fn get_creator_releases( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorReleasesResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorReleasesResponse, ApiError>; - fn get_creator_revision( + async fn get_creator_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetCreatorRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorRevisionResponse, ApiError>; - fn get_editgroup( + async fn get_editgroup( &self, editgroup_id: String, context: &C, - ) -> Box<dyn Future<Item = GetEditgroupResponse, Error = ApiError> + Send>; + ) -> Result<GetEditgroupResponse, ApiError>; - fn get_editgroup_annotations( + async fn get_editgroup_annotations( &self, editgroup_id: String, expand: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetEditgroupAnnotationsResponse, Error = ApiError> + Send>; + ) -> Result<GetEditgroupAnnotationsResponse, ApiError>; - fn get_editgroups_reviewable( + async fn get_editgroups_reviewable( &self, expand: Option<String>, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, context: &C, - ) -> Box<dyn Future<Item = GetEditgroupsReviewableResponse, Error = ApiError> + Send>; + ) -> Result<GetEditgroupsReviewableResponse, ApiError>; - fn get_editor( + async fn get_editor( &self, editor_id: String, context: &C, - ) -> Box<dyn Future<Item = GetEditorResponse, Error = ApiError> + Send>; + ) -> Result<GetEditorResponse, ApiError>; - fn get_editor_annotations( + async fn get_editor_annotations( &self, editor_id: String, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, context: &C, - ) -> Box<dyn Future<Item = GetEditorAnnotationsResponse, Error = ApiError> + Send>; + ) -> Result<GetEditorAnnotationsResponse, ApiError>; - fn get_editor_editgroups( + async fn get_editor_editgroups( &self, editor_id: String, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, context: &C, - ) -> Box<dyn Future<Item = GetEditorEditgroupsResponse, Error = ApiError> + Send>; + ) -> Result<GetEditorEditgroupsResponse, ApiError>; - fn get_file( + async fn get_file( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFileResponse, Error = ApiError> + Send>; + ) -> Result<GetFileResponse, ApiError>; - fn get_file_edit( + async fn get_file_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetFileEditResponse, Error = ApiError> + Send>; + ) -> Result<GetFileEditResponse, ApiError>; - fn get_file_history( + async fn get_file_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetFileHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetFileHistoryResponse, ApiError>; - fn get_file_redirects( + async fn get_file_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetFileRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetFileRedirectsResponse, ApiError>; - fn get_file_revision( + async fn get_file_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFileRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetFileRevisionResponse, ApiError>; - fn get_fileset( + async fn get_fileset( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFilesetResponse, Error = ApiError> + Send>; + ) -> Result<GetFilesetResponse, ApiError>; - fn get_fileset_edit( + async fn get_fileset_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetFilesetEditResponse, Error = ApiError> + Send>; + ) -> Result<GetFilesetEditResponse, ApiError>; - fn get_fileset_history( + async fn get_fileset_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetFilesetHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetFilesetHistoryResponse, ApiError>; - fn get_fileset_redirects( + async fn get_fileset_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetFilesetRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetFilesetRedirectsResponse, ApiError>; - fn get_fileset_revision( + async fn get_fileset_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetFilesetRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetFilesetRevisionResponse, ApiError>; - fn get_release( + async fn get_release( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseResponse, ApiError>; - fn get_release_edit( + async fn get_release_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetReleaseEditResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseEditResponse, ApiError>; - fn get_release_files( + async fn get_release_files( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseFilesResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseFilesResponse, ApiError>; - fn get_release_filesets( + async fn get_release_filesets( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseFilesetsResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseFilesetsResponse, ApiError>; - fn get_release_history( + async fn get_release_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseHistoryResponse, ApiError>; - fn get_release_redirects( + async fn get_release_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetReleaseRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseRedirectsResponse, ApiError>; - fn get_release_revision( + async fn get_release_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseRevisionResponse, ApiError>; - fn get_release_webcaptures( + async fn get_release_webcaptures( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetReleaseWebcapturesResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseWebcapturesResponse, ApiError>; - fn get_webcapture( + async fn get_webcapture( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureResponse, ApiError>; - fn get_webcapture_edit( + async fn get_webcapture_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureEditResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureEditResponse, ApiError>; - fn get_webcapture_history( + async fn get_webcapture_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureHistoryResponse, ApiError>; - fn get_webcapture_redirects( + async fn get_webcapture_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureRedirectsResponse, ApiError>; - fn get_webcapture_revision( + async fn get_webcapture_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWebcaptureRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureRevisionResponse, ApiError>; - fn get_work( + async fn get_work( &self, ident: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWorkResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkResponse, ApiError>; - fn get_work_edit( + async fn get_work_edit( &self, edit_id: String, context: &C, - ) -> Box<dyn Future<Item = GetWorkEditResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkEditResponse, ApiError>; - fn get_work_history( + async fn get_work_history( &self, ident: String, limit: Option<i64>, context: &C, - ) -> Box<dyn Future<Item = GetWorkHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkHistoryResponse, ApiError>; - fn get_work_redirects( + async fn get_work_redirects( &self, ident: String, context: &C, - ) -> Box<dyn Future<Item = GetWorkRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkRedirectsResponse, ApiError>; - fn get_work_releases( + async fn get_work_releases( &self, ident: String, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWorkReleasesResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkReleasesResponse, ApiError>; - fn get_work_revision( + async fn get_work_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = GetWorkRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkRevisionResponse, ApiError>; - fn lookup_container( + async fn lookup_container( &self, issnl: Option<String>, wikidata_qid: Option<String>, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupContainerResponse, Error = ApiError> + Send>; + ) -> Result<LookupContainerResponse, ApiError>; - fn lookup_creator( + async fn lookup_creator( &self, orcid: Option<String>, wikidata_qid: Option<String>, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupCreatorResponse, Error = ApiError> + Send>; + ) -> Result<LookupCreatorResponse, ApiError>; - fn lookup_file( + async fn lookup_file( &self, md5: Option<String>, sha1: Option<String>, @@ -2160,9 +2168,9 @@ pub trait Api<C> { expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupFileResponse, Error = ApiError> + Send>; + ) -> Result<LookupFileResponse, ApiError>; - fn lookup_release( + async fn lookup_release( &self, doi: Option<String>, wikidata_qid: Option<String>, @@ -2174,594 +2182,568 @@ pub trait Api<C> { jstor: Option<String>, ark: Option<String>, mag: Option<String>, + doaj: Option<String>, + dblp: Option<String>, + oai: Option<String>, expand: Option<String>, hide: Option<String>, context: &C, - ) -> Box<dyn Future<Item = LookupReleaseResponse, Error = ApiError> + Send>; + ) -> Result<LookupReleaseResponse, ApiError>; - fn update_container( + async fn update_container( &self, editgroup_id: String, ident: String, container_entity: models::ContainerEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateContainerResponse, Error = ApiError> + Send>; + ) -> Result<UpdateContainerResponse, ApiError>; - fn update_creator( + async fn update_creator( &self, editgroup_id: String, ident: String, creator_entity: models::CreatorEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateCreatorResponse, Error = ApiError> + Send>; + ) -> Result<UpdateCreatorResponse, ApiError>; - fn update_editgroup( + async fn update_editgroup( &self, editgroup_id: String, editgroup: models::Editgroup, submit: Option<bool>, context: &C, - ) -> Box<dyn Future<Item = UpdateEditgroupResponse, Error = ApiError> + Send>; + ) -> Result<UpdateEditgroupResponse, ApiError>; - fn update_editor( + async fn update_editor( &self, editor_id: String, editor: models::Editor, context: &C, - ) -> Box<dyn Future<Item = UpdateEditorResponse, Error = ApiError> + Send>; + ) -> Result<UpdateEditorResponse, ApiError>; - fn update_file( + async fn update_file( &self, editgroup_id: String, ident: String, file_entity: models::FileEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateFileResponse, Error = ApiError> + Send>; + ) -> Result<UpdateFileResponse, ApiError>; - fn update_fileset( + async fn update_fileset( &self, editgroup_id: String, ident: String, fileset_entity: models::FilesetEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateFilesetResponse, Error = ApiError> + Send>; + ) -> Result<UpdateFilesetResponse, ApiError>; - fn update_release( + async fn update_release( &self, editgroup_id: String, ident: String, release_entity: models::ReleaseEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateReleaseResponse, Error = ApiError> + Send>; + ) -> Result<UpdateReleaseResponse, ApiError>; - fn update_webcapture( + async fn update_webcapture( &self, editgroup_id: String, ident: String, webcapture_entity: models::WebcaptureEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateWebcaptureResponse, Error = ApiError> + Send>; + ) -> Result<UpdateWebcaptureResponse, ApiError>; - fn update_work( + async fn update_work( &self, editgroup_id: String, ident: String, work_entity: models::WorkEntity, context: &C, - ) -> Box<dyn Future<Item = UpdateWorkResponse, Error = ApiError> + Send>; + ) -> Result<UpdateWorkResponse, ApiError>; } -/// API without a `Context` -pub trait ApiNoContext { - fn accept_editgroup( +/// API where `Context` isn't passed on every API call +#[async_trait] +pub trait ApiNoContext<C: Send + Sync> { + fn poll_ready( &self, - editgroup_id: String, - ) -> Box<dyn Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send>; + _cx: &mut Context, + ) -> Poll<Result<(), Box<dyn Error + Send + Sync + 'static>>>; - fn auth_check( - &self, - role: Option<String>, - ) -> Box<dyn Future<Item = AuthCheckResponse, Error = ApiError> + Send>; + fn context(&self) -> &C; - fn auth_oidc( + async fn accept_editgroup( &self, - auth_oidc: models::AuthOidc, - ) -> Box<dyn Future<Item = AuthOidcResponse, Error = ApiError> + Send>; + editgroup_id: String, + ) -> Result<AcceptEditgroupResponse, ApiError>; + + async fn auth_check(&self, role: Option<String>) -> Result<AuthCheckResponse, ApiError>; - fn create_auth_token( + async fn auth_oidc(&self, auth_oidc: models::AuthOidc) -> Result<AuthOidcResponse, ApiError>; + + async fn create_auth_token( &self, editor_id: String, duration_seconds: Option<i32>, - ) -> Box<dyn Future<Item = CreateAuthTokenResponse, Error = ApiError> + Send>; + ) -> Result<CreateAuthTokenResponse, ApiError>; - fn create_container( + async fn create_container( &self, editgroup_id: String, container_entity: models::ContainerEntity, - ) -> Box<dyn Future<Item = CreateContainerResponse, Error = ApiError> + Send>; + ) -> Result<CreateContainerResponse, ApiError>; - fn create_container_auto_batch( + async fn create_container_auto_batch( &self, container_auto_batch: models::ContainerAutoBatch, - ) -> Box<dyn Future<Item = CreateContainerAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateContainerAutoBatchResponse, ApiError>; - fn create_creator( + async fn create_creator( &self, editgroup_id: String, creator_entity: models::CreatorEntity, - ) -> Box<dyn Future<Item = CreateCreatorResponse, Error = ApiError> + Send>; + ) -> Result<CreateCreatorResponse, ApiError>; - fn create_creator_auto_batch( + async fn create_creator_auto_batch( &self, creator_auto_batch: models::CreatorAutoBatch, - ) -> Box<dyn Future<Item = CreateCreatorAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateCreatorAutoBatchResponse, ApiError>; - fn create_editgroup( + async fn create_editgroup( &self, editgroup: models::Editgroup, - ) -> Box<dyn Future<Item = CreateEditgroupResponse, Error = ApiError> + Send>; + ) -> Result<CreateEditgroupResponse, ApiError>; - fn create_editgroup_annotation( + async fn create_editgroup_annotation( &self, editgroup_id: String, editgroup_annotation: models::EditgroupAnnotation, - ) -> Box<dyn Future<Item = CreateEditgroupAnnotationResponse, Error = ApiError> + Send>; + ) -> Result<CreateEditgroupAnnotationResponse, ApiError>; - fn create_file( + async fn create_file( &self, editgroup_id: String, file_entity: models::FileEntity, - ) -> Box<dyn Future<Item = CreateFileResponse, Error = ApiError> + Send>; + ) -> Result<CreateFileResponse, ApiError>; - fn create_file_auto_batch( + async fn create_file_auto_batch( &self, file_auto_batch: models::FileAutoBatch, - ) -> Box<dyn Future<Item = CreateFileAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateFileAutoBatchResponse, ApiError>; - fn create_fileset( + async fn create_fileset( &self, editgroup_id: String, fileset_entity: models::FilesetEntity, - ) -> Box<dyn Future<Item = CreateFilesetResponse, Error = ApiError> + Send>; + ) -> Result<CreateFilesetResponse, ApiError>; - fn create_fileset_auto_batch( + async fn create_fileset_auto_batch( &self, fileset_auto_batch: models::FilesetAutoBatch, - ) -> Box<dyn Future<Item = CreateFilesetAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateFilesetAutoBatchResponse, ApiError>; - fn create_release( + async fn create_release( &self, editgroup_id: String, release_entity: models::ReleaseEntity, - ) -> Box<dyn Future<Item = CreateReleaseResponse, Error = ApiError> + Send>; + ) -> Result<CreateReleaseResponse, ApiError>; - fn create_release_auto_batch( + async fn create_release_auto_batch( &self, release_auto_batch: models::ReleaseAutoBatch, - ) -> Box<dyn Future<Item = CreateReleaseAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateReleaseAutoBatchResponse, ApiError>; - fn create_webcapture( + async fn create_webcapture( &self, editgroup_id: String, webcapture_entity: models::WebcaptureEntity, - ) -> Box<dyn Future<Item = CreateWebcaptureResponse, Error = ApiError> + Send>; + ) -> Result<CreateWebcaptureResponse, ApiError>; - fn create_webcapture_auto_batch( + async fn create_webcapture_auto_batch( &self, webcapture_auto_batch: models::WebcaptureAutoBatch, - ) -> Box<dyn Future<Item = CreateWebcaptureAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateWebcaptureAutoBatchResponse, ApiError>; - fn create_work( + async fn create_work( &self, editgroup_id: String, work_entity: models::WorkEntity, - ) -> Box<dyn Future<Item = CreateWorkResponse, Error = ApiError> + Send>; + ) -> Result<CreateWorkResponse, ApiError>; - fn create_work_auto_batch( + async fn create_work_auto_batch( &self, work_auto_batch: models::WorkAutoBatch, - ) -> Box<dyn Future<Item = CreateWorkAutoBatchResponse, Error = ApiError> + Send>; + ) -> Result<CreateWorkAutoBatchResponse, ApiError>; - fn delete_container( + async fn delete_container( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteContainerResponse, Error = ApiError> + Send>; + ) -> Result<DeleteContainerResponse, ApiError>; - fn delete_container_edit( + async fn delete_container_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteContainerEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteContainerEditResponse, ApiError>; - fn delete_creator( + async fn delete_creator( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteCreatorResponse, Error = ApiError> + Send>; + ) -> Result<DeleteCreatorResponse, ApiError>; - fn delete_creator_edit( + async fn delete_creator_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteCreatorEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteCreatorEditResponse, ApiError>; - fn delete_file( + async fn delete_file( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteFileResponse, Error = ApiError> + Send>; + ) -> Result<DeleteFileResponse, ApiError>; - fn delete_file_edit( + async fn delete_file_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteFileEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteFileEditResponse, ApiError>; - fn delete_fileset( + async fn delete_fileset( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteFilesetResponse, Error = ApiError> + Send>; + ) -> Result<DeleteFilesetResponse, ApiError>; - fn delete_fileset_edit( + async fn delete_fileset_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteFilesetEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteFilesetEditResponse, ApiError>; - fn delete_release( + async fn delete_release( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteReleaseResponse, Error = ApiError> + Send>; + ) -> Result<DeleteReleaseResponse, ApiError>; - fn delete_release_edit( + async fn delete_release_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteReleaseEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteReleaseEditResponse, ApiError>; - fn delete_webcapture( + async fn delete_webcapture( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteWebcaptureResponse, Error = ApiError> + Send>; + ) -> Result<DeleteWebcaptureResponse, ApiError>; - fn delete_webcapture_edit( + async fn delete_webcapture_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteWebcaptureEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteWebcaptureEditResponse, ApiError>; - fn delete_work( + async fn delete_work( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteWorkResponse, Error = ApiError> + Send>; + ) -> Result<DeleteWorkResponse, ApiError>; - fn delete_work_edit( + async fn delete_work_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteWorkEditResponse, Error = ApiError> + Send>; + ) -> Result<DeleteWorkEditResponse, ApiError>; - fn get_changelog( - &self, - limit: Option<i64>, - ) -> Box<dyn Future<Item = GetChangelogResponse, Error = ApiError> + Send>; + async fn get_changelog(&self, limit: Option<i64>) -> Result<GetChangelogResponse, ApiError>; - fn get_changelog_entry( - &self, - index: i64, - ) -> Box<dyn Future<Item = GetChangelogEntryResponse, Error = ApiError> + Send>; + async fn get_changelog_entry(&self, index: i64) -> Result<GetChangelogEntryResponse, ApiError>; - fn get_container( + async fn get_container( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetContainerResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerResponse, ApiError>; - fn get_container_edit( + async fn get_container_edit( &self, edit_id: String, - ) -> Box<dyn Future<Item = GetContainerEditResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerEditResponse, ApiError>; - fn get_container_history( + async fn get_container_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetContainerHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerHistoryResponse, ApiError>; - fn get_container_redirects( + async fn get_container_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetContainerRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerRedirectsResponse, ApiError>; - fn get_container_revision( + async fn get_container_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetContainerRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetContainerRevisionResponse, ApiError>; - fn get_creator( + async fn get_creator( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetCreatorResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorResponse, ApiError>; - fn get_creator_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetCreatorEditResponse, Error = ApiError> + Send>; + async fn get_creator_edit(&self, edit_id: String) -> Result<GetCreatorEditResponse, ApiError>; - fn get_creator_history( + async fn get_creator_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetCreatorHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorHistoryResponse, ApiError>; - fn get_creator_redirects( + async fn get_creator_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetCreatorRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorRedirectsResponse, ApiError>; - fn get_creator_releases( + async fn get_creator_releases( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetCreatorReleasesResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorReleasesResponse, ApiError>; - fn get_creator_revision( + async fn get_creator_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetCreatorRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetCreatorRevisionResponse, ApiError>; - fn get_editgroup( - &self, - editgroup_id: String, - ) -> Box<dyn Future<Item = GetEditgroupResponse, Error = ApiError> + Send>; + async fn get_editgroup(&self, editgroup_id: String) -> Result<GetEditgroupResponse, ApiError>; - fn get_editgroup_annotations( + async fn get_editgroup_annotations( &self, editgroup_id: String, expand: Option<String>, - ) -> Box<dyn Future<Item = GetEditgroupAnnotationsResponse, Error = ApiError> + Send>; + ) -> Result<GetEditgroupAnnotationsResponse, ApiError>; - fn get_editgroups_reviewable( + async fn get_editgroups_reviewable( &self, expand: Option<String>, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, - ) -> Box<dyn Future<Item = GetEditgroupsReviewableResponse, Error = ApiError> + Send>; + ) -> Result<GetEditgroupsReviewableResponse, ApiError>; - fn get_editor( - &self, - editor_id: String, - ) -> Box<dyn Future<Item = GetEditorResponse, Error = ApiError> + Send>; + async fn get_editor(&self, editor_id: String) -> Result<GetEditorResponse, ApiError>; - fn get_editor_annotations( + async fn get_editor_annotations( &self, editor_id: String, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, - ) -> Box<dyn Future<Item = GetEditorAnnotationsResponse, Error = ApiError> + Send>; + ) -> Result<GetEditorAnnotationsResponse, ApiError>; - fn get_editor_editgroups( + async fn get_editor_editgroups( &self, editor_id: String, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, - ) -> Box<dyn Future<Item = GetEditorEditgroupsResponse, Error = ApiError> + Send>; + ) -> Result<GetEditorEditgroupsResponse, ApiError>; - fn get_file( + async fn get_file( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetFileResponse, Error = ApiError> + Send>; + ) -> Result<GetFileResponse, ApiError>; - fn get_file_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetFileEditResponse, Error = ApiError> + Send>; + async fn get_file_edit(&self, edit_id: String) -> Result<GetFileEditResponse, ApiError>; - fn get_file_history( + async fn get_file_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetFileHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetFileHistoryResponse, ApiError>; - fn get_file_redirects( - &self, - ident: String, - ) -> Box<dyn Future<Item = GetFileRedirectsResponse, Error = ApiError> + Send>; + async fn get_file_redirects(&self, ident: String) + -> Result<GetFileRedirectsResponse, ApiError>; - fn get_file_revision( + async fn get_file_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetFileRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetFileRevisionResponse, ApiError>; - fn get_fileset( + async fn get_fileset( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetFilesetResponse, Error = ApiError> + Send>; + ) -> Result<GetFilesetResponse, ApiError>; - fn get_fileset_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetFilesetEditResponse, Error = ApiError> + Send>; + async fn get_fileset_edit(&self, edit_id: String) -> Result<GetFilesetEditResponse, ApiError>; - fn get_fileset_history( + async fn get_fileset_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetFilesetHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetFilesetHistoryResponse, ApiError>; - fn get_fileset_redirects( + async fn get_fileset_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetFilesetRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetFilesetRedirectsResponse, ApiError>; - fn get_fileset_revision( + async fn get_fileset_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetFilesetRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetFilesetRevisionResponse, ApiError>; - fn get_release( + async fn get_release( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseResponse, ApiError>; - fn get_release_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetReleaseEditResponse, Error = ApiError> + Send>; + async fn get_release_edit(&self, edit_id: String) -> Result<GetReleaseEditResponse, ApiError>; - fn get_release_files( + async fn get_release_files( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseFilesResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseFilesResponse, ApiError>; - fn get_release_filesets( + async fn get_release_filesets( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseFilesetsResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseFilesetsResponse, ApiError>; - fn get_release_history( + async fn get_release_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetReleaseHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseHistoryResponse, ApiError>; - fn get_release_redirects( + async fn get_release_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetReleaseRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseRedirectsResponse, ApiError>; - fn get_release_revision( + async fn get_release_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseRevisionResponse, ApiError>; - fn get_release_webcaptures( + async fn get_release_webcaptures( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseWebcapturesResponse, Error = ApiError> + Send>; + ) -> Result<GetReleaseWebcapturesResponse, ApiError>; - fn get_webcapture( + async fn get_webcapture( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWebcaptureResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureResponse, ApiError>; - fn get_webcapture_edit( + async fn get_webcapture_edit( &self, edit_id: String, - ) -> Box<dyn Future<Item = GetWebcaptureEditResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureEditResponse, ApiError>; - fn get_webcapture_history( + async fn get_webcapture_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetWebcaptureHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureHistoryResponse, ApiError>; - fn get_webcapture_redirects( + async fn get_webcapture_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetWebcaptureRedirectsResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureRedirectsResponse, ApiError>; - fn get_webcapture_revision( + async fn get_webcapture_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWebcaptureRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetWebcaptureRevisionResponse, ApiError>; - fn get_work( + async fn get_work( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWorkResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkResponse, ApiError>; - fn get_work_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetWorkEditResponse, Error = ApiError> + Send>; + async fn get_work_edit(&self, edit_id: String) -> Result<GetWorkEditResponse, ApiError>; - fn get_work_history( + async fn get_work_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetWorkHistoryResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkHistoryResponse, ApiError>; - fn get_work_redirects( - &self, - ident: String, - ) -> Box<dyn Future<Item = GetWorkRedirectsResponse, Error = ApiError> + Send>; + async fn get_work_redirects(&self, ident: String) + -> Result<GetWorkRedirectsResponse, ApiError>; - fn get_work_releases( + async fn get_work_releases( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWorkReleasesResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkReleasesResponse, ApiError>; - fn get_work_revision( + async fn get_work_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWorkRevisionResponse, Error = ApiError> + Send>; + ) -> Result<GetWorkRevisionResponse, ApiError>; - fn lookup_container( + async fn lookup_container( &self, issnl: Option<String>, wikidata_qid: Option<String>, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = LookupContainerResponse, Error = ApiError> + Send>; + ) -> Result<LookupContainerResponse, ApiError>; - fn lookup_creator( + async fn lookup_creator( &self, orcid: Option<String>, wikidata_qid: Option<String>, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = LookupCreatorResponse, Error = ApiError> + Send>; + ) -> Result<LookupCreatorResponse, ApiError>; - fn lookup_file( + async fn lookup_file( &self, md5: Option<String>, sha1: Option<String>, sha256: Option<String>, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = LookupFileResponse, Error = ApiError> + Send>; + ) -> Result<LookupFileResponse, ApiError>; - fn lookup_release( + async fn lookup_release( &self, doi: Option<String>, wikidata_qid: Option<String>, @@ -2773,820 +2755,926 @@ pub trait ApiNoContext { jstor: Option<String>, ark: Option<String>, mag: Option<String>, + doaj: Option<String>, + dblp: Option<String>, + oai: Option<String>, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = LookupReleaseResponse, Error = ApiError> + Send>; + ) -> Result<LookupReleaseResponse, ApiError>; - fn update_container( + async fn update_container( &self, editgroup_id: String, ident: String, container_entity: models::ContainerEntity, - ) -> Box<dyn Future<Item = UpdateContainerResponse, Error = ApiError> + Send>; + ) -> Result<UpdateContainerResponse, ApiError>; - fn update_creator( + async fn update_creator( &self, editgroup_id: String, ident: String, creator_entity: models::CreatorEntity, - ) -> Box<dyn Future<Item = UpdateCreatorResponse, Error = ApiError> + Send>; + ) -> Result<UpdateCreatorResponse, ApiError>; - fn update_editgroup( + async fn update_editgroup( &self, editgroup_id: String, editgroup: models::Editgroup, submit: Option<bool>, - ) -> Box<dyn Future<Item = UpdateEditgroupResponse, Error = ApiError> + Send>; + ) -> Result<UpdateEditgroupResponse, ApiError>; - fn update_editor( + async fn update_editor( &self, editor_id: String, editor: models::Editor, - ) -> Box<dyn Future<Item = UpdateEditorResponse, Error = ApiError> + Send>; + ) -> Result<UpdateEditorResponse, ApiError>; - fn update_file( + async fn update_file( &self, editgroup_id: String, ident: String, file_entity: models::FileEntity, - ) -> Box<dyn Future<Item = UpdateFileResponse, Error = ApiError> + Send>; + ) -> Result<UpdateFileResponse, ApiError>; - fn update_fileset( + async fn update_fileset( &self, editgroup_id: String, ident: String, fileset_entity: models::FilesetEntity, - ) -> Box<dyn Future<Item = UpdateFilesetResponse, Error = ApiError> + Send>; + ) -> Result<UpdateFilesetResponse, ApiError>; - fn update_release( + async fn update_release( &self, editgroup_id: String, ident: String, release_entity: models::ReleaseEntity, - ) -> Box<dyn Future<Item = UpdateReleaseResponse, Error = ApiError> + Send>; + ) -> Result<UpdateReleaseResponse, ApiError>; - fn update_webcapture( + async fn update_webcapture( &self, editgroup_id: String, ident: String, webcapture_entity: models::WebcaptureEntity, - ) -> Box<dyn Future<Item = UpdateWebcaptureResponse, Error = ApiError> + Send>; + ) -> Result<UpdateWebcaptureResponse, ApiError>; - fn update_work( + async fn update_work( &self, editgroup_id: String, ident: String, work_entity: models::WorkEntity, - ) -> Box<dyn Future<Item = UpdateWorkResponse, Error = ApiError> + Send>; + ) -> Result<UpdateWorkResponse, ApiError>; } /// Trait to extend an API to make it easy to bind it to a context. -pub trait ContextWrapperExt<'a, C> +pub trait ContextWrapperExt<C: Send + Sync> where Self: Sized, { /// Binds this API to a context. - fn with_context(self: &'a Self, context: C) -> ContextWrapper<'a, Self, C>; + fn with_context(self: Self, context: C) -> ContextWrapper<Self, C>; } -impl<'a, T: Api<C> + Sized, C> ContextWrapperExt<'a, C> for T { - fn with_context(self: &'a T, context: C) -> ContextWrapper<'a, T, C> { +impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ContextWrapperExt<C> for T { + fn with_context(self: T, context: C) -> ContextWrapper<T, C> { ContextWrapper::<T, C>::new(self, context) } } -impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> { - fn accept_editgroup( +#[async_trait] +impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for ContextWrapper<T, C> { + fn poll_ready(&self, cx: &mut Context) -> Poll<Result<(), ServiceError>> { + self.api().poll_ready(cx) + } + + fn context(&self) -> &C { + ContextWrapper::context(self) + } + + async fn accept_editgroup( &self, editgroup_id: String, - ) -> Box<dyn Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> { - self.api().accept_editgroup(editgroup_id, &self.context()) + ) -> Result<AcceptEditgroupResponse, ApiError> { + let context = self.context().clone(); + self.api().accept_editgroup(editgroup_id, &context).await } - fn auth_check( - &self, - role: Option<String>, - ) -> Box<dyn Future<Item = AuthCheckResponse, Error = ApiError> + Send> { - self.api().auth_check(role, &self.context()) + async fn auth_check(&self, role: Option<String>) -> Result<AuthCheckResponse, ApiError> { + let context = self.context().clone(); + self.api().auth_check(role, &context).await } - fn auth_oidc( - &self, - auth_oidc: models::AuthOidc, - ) -> Box<dyn Future<Item = AuthOidcResponse, Error = ApiError> + Send> { - self.api().auth_oidc(auth_oidc, &self.context()) + async fn auth_oidc(&self, auth_oidc: models::AuthOidc) -> Result<AuthOidcResponse, ApiError> { + let context = self.context().clone(); + self.api().auth_oidc(auth_oidc, &context).await } - fn create_auth_token( + async fn create_auth_token( &self, editor_id: String, duration_seconds: Option<i32>, - ) -> Box<dyn Future<Item = CreateAuthTokenResponse, Error = ApiError> + Send> { + ) -> Result<CreateAuthTokenResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_auth_token(editor_id, duration_seconds, &self.context()) + .create_auth_token(editor_id, duration_seconds, &context) + .await } - fn create_container( + async fn create_container( &self, editgroup_id: String, container_entity: models::ContainerEntity, - ) -> Box<dyn Future<Item = CreateContainerResponse, Error = ApiError> + Send> { + ) -> Result<CreateContainerResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_container(editgroup_id, container_entity, &self.context()) + .create_container(editgroup_id, container_entity, &context) + .await } - fn create_container_auto_batch( + async fn create_container_auto_batch( &self, container_auto_batch: models::ContainerAutoBatch, - ) -> Box<dyn Future<Item = CreateContainerAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateContainerAutoBatchResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_container_auto_batch(container_auto_batch, &self.context()) + .create_container_auto_batch(container_auto_batch, &context) + .await } - fn create_creator( + async fn create_creator( &self, editgroup_id: String, creator_entity: models::CreatorEntity, - ) -> Box<dyn Future<Item = CreateCreatorResponse, Error = ApiError> + Send> { + ) -> Result<CreateCreatorResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_creator(editgroup_id, creator_entity, &self.context()) + .create_creator(editgroup_id, creator_entity, &context) + .await } - fn create_creator_auto_batch( + async fn create_creator_auto_batch( &self, creator_auto_batch: models::CreatorAutoBatch, - ) -> Box<dyn Future<Item = CreateCreatorAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateCreatorAutoBatchResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_creator_auto_batch(creator_auto_batch, &self.context()) + .create_creator_auto_batch(creator_auto_batch, &context) + .await } - fn create_editgroup( + async fn create_editgroup( &self, editgroup: models::Editgroup, - ) -> Box<dyn Future<Item = CreateEditgroupResponse, Error = ApiError> + Send> { - self.api().create_editgroup(editgroup, &self.context()) + ) -> Result<CreateEditgroupResponse, ApiError> { + let context = self.context().clone(); + self.api().create_editgroup(editgroup, &context).await } - fn create_editgroup_annotation( + async fn create_editgroup_annotation( &self, editgroup_id: String, editgroup_annotation: models::EditgroupAnnotation, - ) -> Box<dyn Future<Item = CreateEditgroupAnnotationResponse, Error = ApiError> + Send> { + ) -> Result<CreateEditgroupAnnotationResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_editgroup_annotation(editgroup_id, editgroup_annotation, &self.context()) + .create_editgroup_annotation(editgroup_id, editgroup_annotation, &context) + .await } - fn create_file( + async fn create_file( &self, editgroup_id: String, file_entity: models::FileEntity, - ) -> Box<dyn Future<Item = CreateFileResponse, Error = ApiError> + Send> { + ) -> Result<CreateFileResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_file(editgroup_id, file_entity, &self.context()) + .create_file(editgroup_id, file_entity, &context) + .await } - fn create_file_auto_batch( + async fn create_file_auto_batch( &self, file_auto_batch: models::FileAutoBatch, - ) -> Box<dyn Future<Item = CreateFileAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateFileAutoBatchResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_file_auto_batch(file_auto_batch, &self.context()) + .create_file_auto_batch(file_auto_batch, &context) + .await } - fn create_fileset( + async fn create_fileset( &self, editgroup_id: String, fileset_entity: models::FilesetEntity, - ) -> Box<dyn Future<Item = CreateFilesetResponse, Error = ApiError> + Send> { + ) -> Result<CreateFilesetResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_fileset(editgroup_id, fileset_entity, &self.context()) + .create_fileset(editgroup_id, fileset_entity, &context) + .await } - fn create_fileset_auto_batch( + async fn create_fileset_auto_batch( &self, fileset_auto_batch: models::FilesetAutoBatch, - ) -> Box<dyn Future<Item = CreateFilesetAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateFilesetAutoBatchResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_fileset_auto_batch(fileset_auto_batch, &self.context()) + .create_fileset_auto_batch(fileset_auto_batch, &context) + .await } - fn create_release( + async fn create_release( &self, editgroup_id: String, release_entity: models::ReleaseEntity, - ) -> Box<dyn Future<Item = CreateReleaseResponse, Error = ApiError> + Send> { + ) -> Result<CreateReleaseResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_release(editgroup_id, release_entity, &self.context()) + .create_release(editgroup_id, release_entity, &context) + .await } - fn create_release_auto_batch( + async fn create_release_auto_batch( &self, release_auto_batch: models::ReleaseAutoBatch, - ) -> Box<dyn Future<Item = CreateReleaseAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateReleaseAutoBatchResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_release_auto_batch(release_auto_batch, &self.context()) + .create_release_auto_batch(release_auto_batch, &context) + .await } - fn create_webcapture( + async fn create_webcapture( &self, editgroup_id: String, webcapture_entity: models::WebcaptureEntity, - ) -> Box<dyn Future<Item = CreateWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<CreateWebcaptureResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_webcapture(editgroup_id, webcapture_entity, &self.context()) + .create_webcapture(editgroup_id, webcapture_entity, &context) + .await } - fn create_webcapture_auto_batch( + async fn create_webcapture_auto_batch( &self, webcapture_auto_batch: models::WebcaptureAutoBatch, - ) -> Box<dyn Future<Item = CreateWebcaptureAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateWebcaptureAutoBatchResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_webcapture_auto_batch(webcapture_auto_batch, &self.context()) + .create_webcapture_auto_batch(webcapture_auto_batch, &context) + .await } - fn create_work( + async fn create_work( &self, editgroup_id: String, work_entity: models::WorkEntity, - ) -> Box<dyn Future<Item = CreateWorkResponse, Error = ApiError> + Send> { + ) -> Result<CreateWorkResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_work(editgroup_id, work_entity, &self.context()) + .create_work(editgroup_id, work_entity, &context) + .await } - fn create_work_auto_batch( + async fn create_work_auto_batch( &self, work_auto_batch: models::WorkAutoBatch, - ) -> Box<dyn Future<Item = CreateWorkAutoBatchResponse, Error = ApiError> + Send> { + ) -> Result<CreateWorkAutoBatchResponse, ApiError> { + let context = self.context().clone(); self.api() - .create_work_auto_batch(work_auto_batch, &self.context()) + .create_work_auto_batch(work_auto_batch, &context) + .await } - fn delete_container( + async fn delete_container( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteContainerResponse, Error = ApiError> + Send> { + ) -> Result<DeleteContainerResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_container(editgroup_id, ident, &self.context()) + .delete_container(editgroup_id, ident, &context) + .await } - fn delete_container_edit( + async fn delete_container_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteContainerEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteContainerEditResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_container_edit(editgroup_id, edit_id, &self.context()) + .delete_container_edit(editgroup_id, edit_id, &context) + .await } - fn delete_creator( + async fn delete_creator( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteCreatorResponse, Error = ApiError> + Send> { + ) -> Result<DeleteCreatorResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_creator(editgroup_id, ident, &self.context()) + .delete_creator(editgroup_id, ident, &context) + .await } - fn delete_creator_edit( + async fn delete_creator_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteCreatorEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteCreatorEditResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_creator_edit(editgroup_id, edit_id, &self.context()) + .delete_creator_edit(editgroup_id, edit_id, &context) + .await } - fn delete_file( + async fn delete_file( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteFileResponse, Error = ApiError> + Send> { - self.api().delete_file(editgroup_id, ident, &self.context()) + ) -> Result<DeleteFileResponse, ApiError> { + let context = self.context().clone(); + self.api().delete_file(editgroup_id, ident, &context).await } - fn delete_file_edit( + async fn delete_file_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteFileEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFileEditResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_file_edit(editgroup_id, edit_id, &self.context()) + .delete_file_edit(editgroup_id, edit_id, &context) + .await } - fn delete_fileset( + async fn delete_fileset( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteFilesetResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFilesetResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_fileset(editgroup_id, ident, &self.context()) + .delete_fileset(editgroup_id, ident, &context) + .await } - fn delete_fileset_edit( + async fn delete_fileset_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteFilesetEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteFilesetEditResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_fileset_edit(editgroup_id, edit_id, &self.context()) + .delete_fileset_edit(editgroup_id, edit_id, &context) + .await } - fn delete_release( + async fn delete_release( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteReleaseResponse, Error = ApiError> + Send> { + ) -> Result<DeleteReleaseResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_release(editgroup_id, ident, &self.context()) + .delete_release(editgroup_id, ident, &context) + .await } - fn delete_release_edit( + async fn delete_release_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteReleaseEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteReleaseEditResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_release_edit(editgroup_id, edit_id, &self.context()) + .delete_release_edit(editgroup_id, edit_id, &context) + .await } - fn delete_webcapture( + async fn delete_webcapture( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWebcaptureResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_webcapture(editgroup_id, ident, &self.context()) + .delete_webcapture(editgroup_id, ident, &context) + .await } - fn delete_webcapture_edit( + async fn delete_webcapture_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteWebcaptureEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWebcaptureEditResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_webcapture_edit(editgroup_id, edit_id, &self.context()) + .delete_webcapture_edit(editgroup_id, edit_id, &context) + .await } - fn delete_work( + async fn delete_work( &self, editgroup_id: String, ident: String, - ) -> Box<dyn Future<Item = DeleteWorkResponse, Error = ApiError> + Send> { - self.api().delete_work(editgroup_id, ident, &self.context()) + ) -> Result<DeleteWorkResponse, ApiError> { + let context = self.context().clone(); + self.api().delete_work(editgroup_id, ident, &context).await } - fn delete_work_edit( + async fn delete_work_edit( &self, editgroup_id: String, edit_id: String, - ) -> Box<dyn Future<Item = DeleteWorkEditResponse, Error = ApiError> + Send> { + ) -> Result<DeleteWorkEditResponse, ApiError> { + let context = self.context().clone(); self.api() - .delete_work_edit(editgroup_id, edit_id, &self.context()) + .delete_work_edit(editgroup_id, edit_id, &context) + .await } - fn get_changelog( - &self, - limit: Option<i64>, - ) -> Box<dyn Future<Item = GetChangelogResponse, Error = ApiError> + Send> { - self.api().get_changelog(limit, &self.context()) + async fn get_changelog(&self, limit: Option<i64>) -> Result<GetChangelogResponse, ApiError> { + let context = self.context().clone(); + self.api().get_changelog(limit, &context).await } - fn get_changelog_entry( - &self, - index: i64, - ) -> Box<dyn Future<Item = GetChangelogEntryResponse, Error = ApiError> + Send> { - self.api().get_changelog_entry(index, &self.context()) + async fn get_changelog_entry(&self, index: i64) -> Result<GetChangelogEntryResponse, ApiError> { + let context = self.context().clone(); + self.api().get_changelog_entry(index, &context).await } - fn get_container( + async fn get_container( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetContainerResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_container(ident, expand, hide, &self.context()) + .get_container(ident, expand, hide, &context) + .await } - fn get_container_edit( + async fn get_container_edit( &self, edit_id: String, - ) -> Box<dyn Future<Item = GetContainerEditResponse, Error = ApiError> + Send> { - self.api().get_container_edit(edit_id, &self.context()) + ) -> Result<GetContainerEditResponse, ApiError> { + let context = self.context().clone(); + self.api().get_container_edit(edit_id, &context).await } - fn get_container_history( + async fn get_container_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetContainerHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerHistoryResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_container_history(ident, limit, &self.context()) + .get_container_history(ident, limit, &context) + .await } - fn get_container_redirects( + async fn get_container_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetContainerRedirectsResponse, Error = ApiError> + Send> { - self.api().get_container_redirects(ident, &self.context()) + ) -> Result<GetContainerRedirectsResponse, ApiError> { + let context = self.context().clone(); + self.api().get_container_redirects(ident, &context).await } - fn get_container_revision( + async fn get_container_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetContainerRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetContainerRevisionResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_container_revision(rev_id, expand, hide, &self.context()) + .get_container_revision(rev_id, expand, hide, &context) + .await } - fn get_creator( + async fn get_creator( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetCreatorResponse, Error = ApiError> + Send> { - self.api().get_creator(ident, expand, hide, &self.context()) + ) -> Result<GetCreatorResponse, ApiError> { + let context = self.context().clone(); + self.api().get_creator(ident, expand, hide, &context).await } - fn get_creator_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetCreatorEditResponse, Error = ApiError> + Send> { - self.api().get_creator_edit(edit_id, &self.context()) + async fn get_creator_edit(&self, edit_id: String) -> Result<GetCreatorEditResponse, ApiError> { + let context = self.context().clone(); + self.api().get_creator_edit(edit_id, &context).await } - fn get_creator_history( + async fn get_creator_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetCreatorHistoryResponse, Error = ApiError> + Send> { - self.api() - .get_creator_history(ident, limit, &self.context()) + ) -> Result<GetCreatorHistoryResponse, ApiError> { + let context = self.context().clone(); + self.api().get_creator_history(ident, limit, &context).await } - fn get_creator_redirects( + async fn get_creator_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetCreatorRedirectsResponse, Error = ApiError> + Send> { - self.api().get_creator_redirects(ident, &self.context()) + ) -> Result<GetCreatorRedirectsResponse, ApiError> { + let context = self.context().clone(); + self.api().get_creator_redirects(ident, &context).await } - fn get_creator_releases( + async fn get_creator_releases( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetCreatorReleasesResponse, Error = ApiError> + Send> { - self.api() - .get_creator_releases(ident, hide, &self.context()) + ) -> Result<GetCreatorReleasesResponse, ApiError> { + let context = self.context().clone(); + self.api().get_creator_releases(ident, hide, &context).await } - fn get_creator_revision( + async fn get_creator_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetCreatorRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetCreatorRevisionResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_creator_revision(rev_id, expand, hide, &self.context()) + .get_creator_revision(rev_id, expand, hide, &context) + .await } - fn get_editgroup( - &self, - editgroup_id: String, - ) -> Box<dyn Future<Item = GetEditgroupResponse, Error = ApiError> + Send> { - self.api().get_editgroup(editgroup_id, &self.context()) + async fn get_editgroup(&self, editgroup_id: String) -> Result<GetEditgroupResponse, ApiError> { + let context = self.context().clone(); + self.api().get_editgroup(editgroup_id, &context).await } - fn get_editgroup_annotations( + async fn get_editgroup_annotations( &self, editgroup_id: String, expand: Option<String>, - ) -> Box<dyn Future<Item = GetEditgroupAnnotationsResponse, Error = ApiError> + Send> { + ) -> Result<GetEditgroupAnnotationsResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_editgroup_annotations(editgroup_id, expand, &self.context()) + .get_editgroup_annotations(editgroup_id, expand, &context) + .await } - fn get_editgroups_reviewable( + async fn get_editgroups_reviewable( &self, expand: Option<String>, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, - ) -> Box<dyn Future<Item = GetEditgroupsReviewableResponse, Error = ApiError> + Send> { + ) -> Result<GetEditgroupsReviewableResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_editgroups_reviewable(expand, limit, before, since, &self.context()) + .get_editgroups_reviewable(expand, limit, before, since, &context) + .await } - fn get_editor( - &self, - editor_id: String, - ) -> Box<dyn Future<Item = GetEditorResponse, Error = ApiError> + Send> { - self.api().get_editor(editor_id, &self.context()) + async fn get_editor(&self, editor_id: String) -> Result<GetEditorResponse, ApiError> { + let context = self.context().clone(); + self.api().get_editor(editor_id, &context).await } - fn get_editor_annotations( + async fn get_editor_annotations( &self, editor_id: String, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, - ) -> Box<dyn Future<Item = GetEditorAnnotationsResponse, Error = ApiError> + Send> { + ) -> Result<GetEditorAnnotationsResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_editor_annotations(editor_id, limit, before, since, &self.context()) + .get_editor_annotations(editor_id, limit, before, since, &context) + .await } - fn get_editor_editgroups( + async fn get_editor_editgroups( &self, editor_id: String, limit: Option<i64>, before: Option<chrono::DateTime<chrono::Utc>>, since: Option<chrono::DateTime<chrono::Utc>>, - ) -> Box<dyn Future<Item = GetEditorEditgroupsResponse, Error = ApiError> + Send> { + ) -> Result<GetEditorEditgroupsResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_editor_editgroups(editor_id, limit, before, since, &self.context()) + .get_editor_editgroups(editor_id, limit, before, since, &context) + .await } - fn get_file( + async fn get_file( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetFileResponse, Error = ApiError> + Send> { - self.api().get_file(ident, expand, hide, &self.context()) + ) -> Result<GetFileResponse, ApiError> { + let context = self.context().clone(); + self.api().get_file(ident, expand, hide, &context).await } - fn get_file_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetFileEditResponse, Error = ApiError> + Send> { - self.api().get_file_edit(edit_id, &self.context()) + async fn get_file_edit(&self, edit_id: String) -> Result<GetFileEditResponse, ApiError> { + let context = self.context().clone(); + self.api().get_file_edit(edit_id, &context).await } - fn get_file_history( + async fn get_file_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetFileHistoryResponse, Error = ApiError> + Send> { - self.api().get_file_history(ident, limit, &self.context()) + ) -> Result<GetFileHistoryResponse, ApiError> { + let context = self.context().clone(); + self.api().get_file_history(ident, limit, &context).await } - fn get_file_redirects( + async fn get_file_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetFileRedirectsResponse, Error = ApiError> + Send> { - self.api().get_file_redirects(ident, &self.context()) + ) -> Result<GetFileRedirectsResponse, ApiError> { + let context = self.context().clone(); + self.api().get_file_redirects(ident, &context).await } - fn get_file_revision( + async fn get_file_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetFileRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetFileRevisionResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_file_revision(rev_id, expand, hide, &self.context()) + .get_file_revision(rev_id, expand, hide, &context) + .await } - fn get_fileset( + async fn get_fileset( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetFilesetResponse, Error = ApiError> + Send> { - self.api().get_fileset(ident, expand, hide, &self.context()) + ) -> Result<GetFilesetResponse, ApiError> { + let context = self.context().clone(); + self.api().get_fileset(ident, expand, hide, &context).await } - fn get_fileset_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetFilesetEditResponse, Error = ApiError> + Send> { - self.api().get_fileset_edit(edit_id, &self.context()) + async fn get_fileset_edit(&self, edit_id: String) -> Result<GetFilesetEditResponse, ApiError> { + let context = self.context().clone(); + self.api().get_fileset_edit(edit_id, &context).await } - fn get_fileset_history( + async fn get_fileset_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetFilesetHistoryResponse, Error = ApiError> + Send> { - self.api() - .get_fileset_history(ident, limit, &self.context()) + ) -> Result<GetFilesetHistoryResponse, ApiError> { + let context = self.context().clone(); + self.api().get_fileset_history(ident, limit, &context).await } - fn get_fileset_redirects( + async fn get_fileset_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetFilesetRedirectsResponse, Error = ApiError> + Send> { - self.api().get_fileset_redirects(ident, &self.context()) + ) -> Result<GetFilesetRedirectsResponse, ApiError> { + let context = self.context().clone(); + self.api().get_fileset_redirects(ident, &context).await } - fn get_fileset_revision( + async fn get_fileset_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetFilesetRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetFilesetRevisionResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_fileset_revision(rev_id, expand, hide, &self.context()) + .get_fileset_revision(rev_id, expand, hide, &context) + .await } - fn get_release( + async fn get_release( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseResponse, Error = ApiError> + Send> { - self.api().get_release(ident, expand, hide, &self.context()) + ) -> Result<GetReleaseResponse, ApiError> { + let context = self.context().clone(); + self.api().get_release(ident, expand, hide, &context).await } - fn get_release_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetReleaseEditResponse, Error = ApiError> + Send> { - self.api().get_release_edit(edit_id, &self.context()) + async fn get_release_edit(&self, edit_id: String) -> Result<GetReleaseEditResponse, ApiError> { + let context = self.context().clone(); + self.api().get_release_edit(edit_id, &context).await } - fn get_release_files( + async fn get_release_files( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseFilesResponse, Error = ApiError> + Send> { - self.api().get_release_files(ident, hide, &self.context()) + ) -> Result<GetReleaseFilesResponse, ApiError> { + let context = self.context().clone(); + self.api().get_release_files(ident, hide, &context).await } - fn get_release_filesets( + async fn get_release_filesets( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseFilesetsResponse, Error = ApiError> + Send> { - self.api() - .get_release_filesets(ident, hide, &self.context()) + ) -> Result<GetReleaseFilesetsResponse, ApiError> { + let context = self.context().clone(); + self.api().get_release_filesets(ident, hide, &context).await } - fn get_release_history( + async fn get_release_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetReleaseHistoryResponse, Error = ApiError> + Send> { - self.api() - .get_release_history(ident, limit, &self.context()) + ) -> Result<GetReleaseHistoryResponse, ApiError> { + let context = self.context().clone(); + self.api().get_release_history(ident, limit, &context).await } - fn get_release_redirects( + async fn get_release_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetReleaseRedirectsResponse, Error = ApiError> + Send> { - self.api().get_release_redirects(ident, &self.context()) + ) -> Result<GetReleaseRedirectsResponse, ApiError> { + let context = self.context().clone(); + self.api().get_release_redirects(ident, &context).await } - fn get_release_revision( + async fn get_release_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseRevisionResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_release_revision(rev_id, expand, hide, &self.context()) + .get_release_revision(rev_id, expand, hide, &context) + .await } - fn get_release_webcaptures( + async fn get_release_webcaptures( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetReleaseWebcapturesResponse, Error = ApiError> + Send> { + ) -> Result<GetReleaseWebcapturesResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_release_webcaptures(ident, hide, &self.context()) + .get_release_webcaptures(ident, hide, &context) + .await } - fn get_webcapture( + async fn get_webcapture( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_webcapture(ident, expand, hide, &self.context()) + .get_webcapture(ident, expand, hide, &context) + .await } - fn get_webcapture_edit( + async fn get_webcapture_edit( &self, edit_id: String, - ) -> Box<dyn Future<Item = GetWebcaptureEditResponse, Error = ApiError> + Send> { - self.api().get_webcapture_edit(edit_id, &self.context()) + ) -> Result<GetWebcaptureEditResponse, ApiError> { + let context = self.context().clone(); + self.api().get_webcapture_edit(edit_id, &context).await } - fn get_webcapture_history( + async fn get_webcapture_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetWebcaptureHistoryResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureHistoryResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_webcapture_history(ident, limit, &self.context()) + .get_webcapture_history(ident, limit, &context) + .await } - fn get_webcapture_redirects( + async fn get_webcapture_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetWebcaptureRedirectsResponse, Error = ApiError> + Send> { - self.api().get_webcapture_redirects(ident, &self.context()) + ) -> Result<GetWebcaptureRedirectsResponse, ApiError> { + let context = self.context().clone(); + self.api().get_webcapture_redirects(ident, &context).await } - fn get_webcapture_revision( + async fn get_webcapture_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWebcaptureRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetWebcaptureRevisionResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_webcapture_revision(rev_id, expand, hide, &self.context()) + .get_webcapture_revision(rev_id, expand, hide, &context) + .await } - fn get_work( + async fn get_work( &self, ident: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWorkResponse, Error = ApiError> + Send> { - self.api().get_work(ident, expand, hide, &self.context()) + ) -> Result<GetWorkResponse, ApiError> { + let context = self.context().clone(); + self.api().get_work(ident, expand, hide, &context).await } - fn get_work_edit( - &self, - edit_id: String, - ) -> Box<dyn Future<Item = GetWorkEditResponse, Error = ApiError> + Send> { - self.api().get_work_edit(edit_id, &self.context()) + async fn get_work_edit(&self, edit_id: String) -> Result<GetWorkEditResponse, ApiError> { + let context = self.context().clone(); + self.api().get_work_edit(edit_id, &context).await } - fn get_work_history( + async fn get_work_history( &self, ident: String, limit: Option<i64>, - ) -> Box<dyn Future<Item = GetWorkHistoryResponse, Error = ApiError> + Send> { - self.api().get_work_history(ident, limit, &self.context()) + ) -> Result<GetWorkHistoryResponse, ApiError> { + let context = self.context().clone(); + self.api().get_work_history(ident, limit, &context).await } - fn get_work_redirects( + async fn get_work_redirects( &self, ident: String, - ) -> Box<dyn Future<Item = GetWorkRedirectsResponse, Error = ApiError> + Send> { - self.api().get_work_redirects(ident, &self.context()) + ) -> Result<GetWorkRedirectsResponse, ApiError> { + let context = self.context().clone(); + self.api().get_work_redirects(ident, &context).await } - fn get_work_releases( + async fn get_work_releases( &self, ident: String, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWorkReleasesResponse, Error = ApiError> + Send> { - self.api().get_work_releases(ident, hide, &self.context()) + ) -> Result<GetWorkReleasesResponse, ApiError> { + let context = self.context().clone(); + self.api().get_work_releases(ident, hide, &context).await } - fn get_work_revision( + async fn get_work_revision( &self, rev_id: String, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = GetWorkRevisionResponse, Error = ApiError> + Send> { + ) -> Result<GetWorkRevisionResponse, ApiError> { + let context = self.context().clone(); self.api() - .get_work_revision(rev_id, expand, hide, &self.context()) + .get_work_revision(rev_id, expand, hide, &context) + .await } - fn lookup_container( + async fn lookup_container( &self, issnl: Option<String>, wikidata_qid: Option<String>, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = LookupContainerResponse, Error = ApiError> + Send> { + ) -> Result<LookupContainerResponse, ApiError> { + let context = self.context().clone(); self.api() - .lookup_container(issnl, wikidata_qid, expand, hide, &self.context()) + .lookup_container(issnl, wikidata_qid, expand, hide, &context) + .await } - fn lookup_creator( + async fn lookup_creator( &self, orcid: Option<String>, wikidata_qid: Option<String>, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = LookupCreatorResponse, Error = ApiError> + Send> { + ) -> Result<LookupCreatorResponse, ApiError> { + let context = self.context().clone(); self.api() - .lookup_creator(orcid, wikidata_qid, expand, hide, &self.context()) + .lookup_creator(orcid, wikidata_qid, expand, hide, &context) + .await } - fn lookup_file( + async fn lookup_file( &self, md5: Option<String>, sha1: Option<String>, sha256: Option<String>, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = LookupFileResponse, Error = ApiError> + Send> { + ) -> Result<LookupFileResponse, ApiError> { + let context = self.context().clone(); self.api() - .lookup_file(md5, sha1, sha256, expand, hide, &self.context()) + .lookup_file(md5, sha1, sha256, expand, hide, &context) + .await } - fn lookup_release( + async fn lookup_release( &self, doi: Option<String>, wikidata_qid: Option<String>, @@ -3598,112 +3686,138 @@ impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> { jstor: Option<String>, ark: Option<String>, mag: Option<String>, + doaj: Option<String>, + dblp: Option<String>, + oai: Option<String>, expand: Option<String>, hide: Option<String>, - ) -> Box<dyn Future<Item = LookupReleaseResponse, Error = ApiError> + Send> { - self.api().lookup_release( - doi, - wikidata_qid, - isbn13, - pmid, - pmcid, - core, - arxiv, - jstor, - ark, - mag, - expand, - hide, - &self.context(), - ) - } - - fn update_container( + ) -> Result<LookupReleaseResponse, ApiError> { + let context = self.context().clone(); + self.api() + .lookup_release( + doi, + wikidata_qid, + isbn13, + pmid, + pmcid, + core, + arxiv, + jstor, + ark, + mag, + doaj, + dblp, + oai, + expand, + hide, + &context, + ) + .await + } + + async fn update_container( &self, editgroup_id: String, ident: String, container_entity: models::ContainerEntity, - ) -> Box<dyn Future<Item = UpdateContainerResponse, Error = ApiError> + Send> { + ) -> Result<UpdateContainerResponse, ApiError> { + let context = self.context().clone(); self.api() - .update_container(editgroup_id, ident, container_entity, &self.context()) + .update_container(editgroup_id, ident, container_entity, &context) + .await } - fn update_creator( + async fn update_creator( &self, editgroup_id: String, ident: String, creator_entity: models::CreatorEntity, - ) -> Box<dyn Future<Item = UpdateCreatorResponse, Error = ApiError> + Send> { + ) -> Result<UpdateCreatorResponse, ApiError> { + let context = self.context().clone(); self.api() - .update_creator(editgroup_id, ident, creator_entity, &self.context()) + .update_creator(editgroup_id, ident, creator_entity, &context) + .await } - fn update_editgroup( + async fn update_editgroup( &self, editgroup_id: String, editgroup: models::Editgroup, submit: Option<bool>, - ) -> Box<dyn Future<Item = UpdateEditgroupResponse, Error = ApiError> + Send> { + ) -> Result<UpdateEditgroupResponse, ApiError> { + let context = self.context().clone(); self.api() - .update_editgroup(editgroup_id, editgroup, submit, &self.context()) + .update_editgroup(editgroup_id, editgroup, submit, &context) + .await } - fn update_editor( + async fn update_editor( &self, editor_id: String, editor: models::Editor, - ) -> Box<dyn Future<Item = UpdateEditorResponse, Error = ApiError> + Send> { - self.api().update_editor(editor_id, editor, &self.context()) + ) -> Result<UpdateEditorResponse, ApiError> { + let context = self.context().clone(); + self.api().update_editor(editor_id, editor, &context).await } - fn update_file( + async fn update_file( &self, editgroup_id: String, ident: String, file_entity: models::FileEntity, - ) -> Box<dyn Future<Item = UpdateFileResponse, Error = ApiError> + Send> { + ) -> Result<UpdateFileResponse, ApiError> { + let context = self.context().clone(); self.api() - .update_file(editgroup_id, ident, file_entity, &self.context()) + .update_file(editgroup_id, ident, file_entity, &context) + .await } - fn update_fileset( + async fn update_fileset( &self, editgroup_id: String, ident: String, fileset_entity: models::FilesetEntity, - ) -> Box<dyn Future<Item = UpdateFilesetResponse, Error = ApiError> + Send> { + ) -> Result<UpdateFilesetResponse, ApiError> { + let context = self.context().clone(); self.api() - .update_fileset(editgroup_id, ident, fileset_entity, &self.context()) + .update_fileset(editgroup_id, ident, fileset_entity, &context) + .await } - fn update_release( + async fn update_release( &self, editgroup_id: String, ident: String, release_entity: models::ReleaseEntity, - ) -> Box<dyn Future<Item = UpdateReleaseResponse, Error = ApiError> + Send> { + ) -> Result<UpdateReleaseResponse, ApiError> { + let context = self.context().clone(); self.api() - .update_release(editgroup_id, ident, release_entity, &self.context()) + .update_release(editgroup_id, ident, release_entity, &context) + .await } - fn update_webcapture( + async fn update_webcapture( &self, editgroup_id: String, ident: String, webcapture_entity: models::WebcaptureEntity, - ) -> Box<dyn Future<Item = UpdateWebcaptureResponse, Error = ApiError> + Send> { + ) -> Result<UpdateWebcaptureResponse, ApiError> { + let context = self.context().clone(); self.api() - .update_webcapture(editgroup_id, ident, webcapture_entity, &self.context()) + .update_webcapture(editgroup_id, ident, webcapture_entity, &context) + .await } - fn update_work( + async fn update_work( &self, editgroup_id: String, ident: String, work_entity: models::WorkEntity, - ) -> Box<dyn Future<Item = UpdateWorkResponse, Error = ApiError> + Send> { + ) -> Result<UpdateWorkResponse, ApiError> { + let context = self.context().clone(); self.api() - .update_work(editgroup_id, ident, work_entity, &self.context()) + .update_work(editgroup_id, ident, work_entity, &context) + .await } } diff --git a/rust/fatcat-openapi/src/models.rs b/rust/fatcat-openapi/src/models.rs index b0a802c..d642c62 100644 --- a/rust/fatcat-openapi/src/models.rs +++ b/rust/fatcat-openapi/src/models.rs @@ -5779,6 +5779,21 @@ pub struct ReleaseExtIds { #[serde(rename = "mag")] #[serde(skip_serializing_if = "Option::is_none")] pub mag: Option<String>, + + /// DOAJ article-level identifier + #[serde(rename = "doaj")] + #[serde(skip_serializing_if = "Option::is_none")] + pub doaj: Option<String>, + + /// dblp (https://dblp.uni-trier.de/) paper identifier; eg for conference proceedings + #[serde(rename = "dblp")] + #[serde(skip_serializing_if = "Option::is_none")] + pub dblp: Option<String>, + + /// OAI-PMH identifier; only used when an OAI-PMH record is the only authoritative metadata (eg, journal OAI-PMH feeds w/o DOIs) + #[serde(rename = "oai")] + #[serde(skip_serializing_if = "Option::is_none")] + pub oai: Option<String>, } impl ReleaseExtIds { @@ -5794,6 +5809,9 @@ impl ReleaseExtIds { jstor: None, ark: None, mag: None, + doaj: None, + dblp: None, + oai: None, } } } @@ -5855,6 +5873,21 @@ impl std::string::ToString for ReleaseExtIds { params.push(mag.to_string()); } + if let Some(ref doaj) = self.doaj { + params.push("doaj".to_string()); + params.push(doaj.to_string()); + } + + if let Some(ref dblp) = self.dblp { + params.push("dblp".to_string()); + params.push(dblp.to_string()); + } + + if let Some(ref oai) = self.oai { + params.push("oai".to_string()); + params.push(oai.to_string()); + } + params.join(",").to_string() } } @@ -5879,6 +5912,9 @@ impl std::str::FromStr for ReleaseExtIds { pub jstor: Vec<String>, pub ark: Vec<String>, pub mag: Vec<String>, + pub doaj: Vec<String>, + pub dblp: Vec<String>, + pub oai: Vec<String>, } let mut intermediate_rep = IntermediateRep::default(); @@ -5929,6 +5965,15 @@ impl std::str::FromStr for ReleaseExtIds { "mag" => intermediate_rep .mag .push(String::from_str(val).map_err(|x| format!("{}", x))?), + "doaj" => intermediate_rep + .doaj + .push(String::from_str(val).map_err(|x| format!("{}", x))?), + "dblp" => intermediate_rep + .dblp + .push(String::from_str(val).map_err(|x| format!("{}", x))?), + "oai" => intermediate_rep + .oai + .push(String::from_str(val).map_err(|x| format!("{}", x))?), _ => { return std::result::Result::Err( "Unexpected key while parsing ReleaseExtIds".to_string(), @@ -5953,6 +5998,9 @@ impl std::str::FromStr for ReleaseExtIds { jstor: intermediate_rep.jstor.into_iter().next(), ark: intermediate_rep.ark.into_iter().next(), mag: intermediate_rep.mag.into_iter().next(), + doaj: intermediate_rep.doaj.into_iter().next(), + dblp: intermediate_rep.dblp.into_iter().next(), + oai: intermediate_rep.oai.into_iter().next(), }) } } diff --git a/rust/fatcat-openapi/src/server/mod.rs b/rust/fatcat-openapi/src/server/mod.rs index 96ed29a..ac07c6e 100644 --- a/rust/fatcat-openapi/src/server/mod.rs +++ b/rust/fatcat-openapi/src/server/mod.rs @@ -1,19 +1,16 @@ -use futures::{future, stream, Future, Stream}; -use hyper; +use futures::{future, future::BoxFuture, future::FutureExt, stream, stream::TryStreamExt, Stream}; use hyper::header::{HeaderName, HeaderValue, CONTENT_TYPE}; -use hyper::{Body, Error, HeaderMap, Request, Response, StatusCode}; +use hyper::{Body, HeaderMap, Request, Response, StatusCode}; use log::warn; -use serde_json; #[allow(unused_imports)] use std::convert::{TryFrom, TryInto}; -use std::io; +use std::error::Error; +use std::future::Future; use std::marker::PhantomData; -#[allow(unused_imports)] -use swagger; +use std::task::{Context, Poll}; pub use swagger::auth::Authorization; use swagger::auth::Scopes; -use swagger::context::ContextualPayload; -use swagger::{ApiError, Has, RequestParser, XSpanIdString}; +use swagger::{ApiError, BodyExt, Has, RequestParser, XSpanIdString}; use url::form_urlencoded; use crate::header; @@ -22,6 +19,8 @@ use crate::models; pub use crate::context; +type ServiceFuture = BoxFuture<'static, Result<Response<Body>, crate::ServiceError>>; + use crate::{ AcceptEditgroupResponse, Api, AuthCheckResponse, AuthOidcResponse, CreateAuthTokenResponse, CreateContainerAutoBatchResponse, CreateContainerResponse, CreateCreatorAutoBatchResponse, @@ -610,15 +609,19 @@ mod paths { } } -pub struct MakeService<T, RC> { +pub struct MakeService<T, C> +where + T: Api<C> + Clone + Send + 'static, + C: Has<XSpanIdString> + Has<Option<Authorization>> + Send + Sync + 'static, +{ api_impl: T, - marker: PhantomData<RC>, + marker: PhantomData<C>, } -impl<T, RC> MakeService<T, RC> +impl<T, C> MakeService<T, C> where - T: Api<RC> + Clone + Send + 'static, - RC: Has<XSpanIdString> + Has<Option<Authorization>> + 'static, + T: Api<C> + Clone + Send + 'static, + C: Has<XSpanIdString> + Has<Option<Authorization>> + Send + Sync + 'static, { pub fn new(api_impl: T) -> Self { MakeService { @@ -628,43 +631,44 @@ where } } -impl<'a, T, SC, RC> hyper::service::MakeService<&'a SC> for MakeService<T, RC> +impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where - T: Api<RC> + Clone + Send + 'static, - RC: Has<XSpanIdString> + Has<Option<Authorization>> + 'static + Send, + T: Api<C> + Clone + Send + 'static, + C: Has<XSpanIdString> + Has<Option<Authorization>> + Send + Sync + 'static, { - type ReqBody = ContextualPayload<Body, RC>; - type ResBody = Body; - type Error = Error; - type Service = Service<T, RC>; - type Future = future::FutureResult<Self::Service, Self::MakeError>; - type MakeError = Error; - - fn make_service(&mut self, _ctx: &'a SC) -> Self::Future { - future::FutureResult::from(Ok(Service::new(self.api_impl.clone()))) + type Response = Service<T, C>; + type Error = crate::ServiceError; + type Future = future::Ready<Result<Self::Response, Self::Error>>; + + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { + Poll::Ready(Ok(())) } -} -type ServiceFuture = Box<dyn Future<Item = Response<Body>, Error = Error> + Send>; + fn call(&mut self, target: Target) -> Self::Future { + futures::future::ok(Service::new(self.api_impl.clone())) + } +} -fn method_not_allowed() -> ServiceFuture { - Box::new(future::ok( - Response::builder() - .status(StatusCode::METHOD_NOT_ALLOWED) - .body(Body::empty()) - .expect("Unable to create Method Not Allowed response"), - )) +fn method_not_allowed() -> Result<Response<Body>, crate::ServiceError> { + Ok(Response::builder() + .status(StatusCode::METHOD_NOT_ALLOWED) + .body(Body::empty()) + .expect("Unable to create Method Not Allowed response")) } -pub struct Service<T, RC> { +pub struct Service<T, C> +where + T: Api<C> + Clone + Send + 'static, + C: Has<XSpanIdString> + Has<Option<Authorization>> + Send + Sync + 'static, +{ api_impl: T, - marker: PhantomData<RC>, + marker: PhantomData<C>, } -impl<T, RC> Service<T, RC> +impl<T, C> Service<T, C> where - T: Api<RC> + Clone + Send + 'static, - RC: Has<XSpanIdString> + Has<Option<Authorization>> + 'static, + T: Api<C> + Clone + Send + 'static, + C: Has<XSpanIdString> + Has<Option<Authorization>> + Send + Sync + 'static, { pub fn new(api_impl: T) -> Self { Service { @@ -674,345 +678,376 @@ where } } -impl<T, C> hyper::service::Service for Service<T, C> +impl<T, C> Clone for Service<T, C> where T: Api<C> + Clone + Send + 'static, - C: Has<XSpanIdString> + Has<Option<Authorization>> + 'static + Send, + C: Has<XSpanIdString> + Has<Option<Authorization>> + Send + Sync + 'static, +{ + fn clone(&self) -> Self { + Service { + api_impl: self.api_impl.clone(), + marker: self.marker.clone(), + } + } +} + +impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> +where + T: Api<C> + Clone + Send + Sync + 'static, + C: Has<XSpanIdString> + Has<Option<Authorization>> + Send + Sync + 'static, { - type ReqBody = ContextualPayload<Body, C>; - type ResBody = Body; - type Error = Error; + type Response = Response<Body>; + type Error = crate::ServiceError; type Future = ServiceFuture; - fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future { - let api_impl = self.api_impl.clone(); - let (parts, body) = req.into_parts(); - let (method, uri, headers) = (parts.method, parts.uri, parts.headers); - let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); - let mut context = body.context; - let body = body.inner; + fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> { + self.api_impl.poll_ready(cx) + } - match &method { - // AcceptEditgroup - POST /editgroup/{editgroup_id}/accept - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ACCEPT) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + fn call(&mut self, req: (Request<Body>, C)) -> Self::Future { + async fn run<T, C>( + mut api_impl: T, + req: (Request<Body>, C), + ) -> Result<Response<Body>, crate::ServiceError> + where + T: Api<C> + Clone + Send + 'static, + C: Has<XSpanIdString> + Has<Option<Authorization>> + Send + Sync + 'static, + { + let (request, context) = req; + let (parts, body) = request.into_parts(); + let (method, uri, headers) = (parts.method, parts.uri, parts.headers); + let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); + + match &method { + // AcceptEditgroup - POST /editgroup/{editgroup_id}/accept + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ACCEPT) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_ACCEPT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_ACCEPT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_ACCEPT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.accept_editgroup( - param_editgroup_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .accept_editgroup(param_editgroup_id, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - AcceptEditgroupResponse::MergedSuccessfully - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + AcceptEditgroupResponse::MergedSuccessfully(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ACCEPT_EDITGROUP_MERGED_SUCCESSFULLY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AcceptEditgroupResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AcceptEditgroupResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ACCEPT_EDITGROUP_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AcceptEditgroupResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AcceptEditgroupResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ACCEPT_EDITGROUP_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AcceptEditgroupResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AcceptEditgroupResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ACCEPT_EDITGROUP_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AcceptEditgroupResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AcceptEditgroupResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ACCEPT_EDITGROUP_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AcceptEditgroupResponse::EditConflict - (body) - => { - *response.status_mut() = StatusCode::from_u16(409).expect("Unable to turn 409 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AcceptEditgroupResponse::EditConflict(body) => { + *response.status_mut() = StatusCode::from_u16(409) + .expect("Unable to turn 409 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ACCEPT_EDITGROUP_EDIT_CONFLICT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AcceptEditgroupResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AcceptEditgroupResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for ACCEPT_EDITGROUP_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // AuthCheck - GET /auth/check - &hyper::Method::GET if path.matched(paths::ID_AUTH_CHECK) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() - .status(StatusCode::FORBIDDEN) - .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; + Ok(response) } - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_role = query_params - .iter() - .filter(|e| e.0 == "role") - .map(|e| e.1.to_owned()) - .nth(0); - let param_role = param_role.and_then(|param_role| param_role.parse().ok()); - - Box::new({ + // AuthCheck - GET /auth/check + &hyper::Method::GET if path.matched(paths::ID_AUTH_CHECK) => { { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() { - Box::new( - api_impl.auth_check( - param_role, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() + .status(StatusCode::FORBIDDEN) + .body(Body::from("Unauthenticated")) + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - match result { - Ok(rsp) => match rsp { - AuthCheckResponse::Success - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_role = query_params + .iter() + .filter(|e| e.0 == "role") + .map(|e| e.1.to_owned()) + .nth(0); + let param_role = match param_role { + Some(param_role) => { + let param_role = <String as std::str::FromStr>::from_str(¶m_role); + match param_role { + Ok(param_role) => Some(param_role), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter role - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter role")), + } + } + None => None, + }; + + let result = api_impl.auth_check(param_role, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + AuthCheckResponse::Success(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for AUTH_CHECK_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AuthCheckResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AuthCheckResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for AUTH_CHECK_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AuthCheckResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AuthCheckResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for AUTH_CHECK_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AuthCheckResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AuthCheckResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for AUTH_CHECK_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - AuthCheckResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + AuthCheckResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for AUTH_CHECK_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // AuthOidc - POST /auth/oidc - &hyper::Method::POST if path.matched(paths::ID_AUTH_OIDC) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + Ok(response) + } + + // AuthOidc - POST /auth/oidc + &hyper::Method::POST if path.matched(paths::ID_AUTH_OIDC) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_auth_oidc: Option<models::AuthOidc> = if !body.is_empty() { @@ -1022,29 +1057,28 @@ where unused_elements.push(path.to_string()); }) { Ok(param_auth_oidc) => param_auth_oidc, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter AuthOidc - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter AuthOidc due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter AuthOidc due to schema")), } } else { None }; let param_auth_oidc = match param_auth_oidc { Some(param_auth_oidc) => param_auth_oidc, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter AuthOidc")) - .expect("Unable to create Bad Request response for missing body parameter AuthOidc"))), + .expect("Unable to create Bad Request response for missing body parameter AuthOidc")), }; - Box::new( - api_impl.auth_oidc( + let result = api_impl.auth_oidc( param_auth_oidc, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -1097,21 +1131,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -1161,221 +1197,229 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter AuthOidc: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter AuthOidc"))), + .expect("Unable to create Bad Request response due to unable to read body parameter AuthOidc")), } - }) - ) as Self::Future - } + } - // CreateAuthToken - POST /auth/token/{editor_id} - &hyper::Method::POST if path.matched(paths::ID_AUTH_TOKEN_EDITOR_ID) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateAuthToken - POST /auth/token/{editor_id} + &hyper::Method::POST if path.matched(paths::ID_AUTH_TOKEN_EDITOR_ID) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_AUTH_TOKEN_EDITOR_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE AUTH_TOKEN_EDITOR_ID in set but failed match against \"{}\"", path, paths::REGEX_AUTH_TOKEN_EDITOR_ID.as_str()) ); - let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { + let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { Ok(param_editor_id) => match param_editor_id.parse::<String>() { Ok(param_editor_id) => param_editor_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editor_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editor_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_duration_seconds = query_params - .iter() - .filter(|e| e.0 == "duration_seconds") - .map(|e| e.1.to_owned()) - .nth(0); - let param_duration_seconds = param_duration_seconds - .and_then(|param_duration_seconds| param_duration_seconds.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.create_auth_token( - param_editor_id, - param_duration_seconds, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_duration_seconds = query_params + .iter() + .filter(|e| e.0 == "duration_seconds") + .map(|e| e.1.to_owned()) + .nth(0); + let param_duration_seconds = match param_duration_seconds { + Some(param_duration_seconds) => { + let param_duration_seconds = + <i32 as std::str::FromStr>::from_str(¶m_duration_seconds); + match param_duration_seconds { + Ok(param_duration_seconds) => Some(param_duration_seconds), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter duration_seconds - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter duration_seconds")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - CreateAuthTokenResponse::Success - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .create_auth_token(param_editor_id, param_duration_seconds, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + CreateAuthTokenResponse::Success(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for CREATE_AUTH_TOKEN_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - CreateAuthTokenResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + CreateAuthTokenResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for CREATE_AUTH_TOKEN_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - CreateAuthTokenResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + CreateAuthTokenResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for CREATE_AUTH_TOKEN_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - CreateAuthTokenResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + CreateAuthTokenResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for CREATE_AUTH_TOKEN_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - CreateAuthTokenResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + CreateAuthTokenResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for CREATE_AUTH_TOKEN_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // CreateContainer - POST /editgroup/{editgroup_id}/container - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER) => { + Ok(response) + } + + // CreateContainer - POST /editgroup/{editgroup_id}/container + &hyper::Method::POST + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_CONTAINER .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_CONTAINER in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_CONTAINER.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_container_entity: Option<models::ContainerEntity> = if !body.is_empty() { @@ -1385,30 +1429,29 @@ where unused_elements.push(path.to_string()); }) { Ok(param_container_entity) => param_container_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter ContainerEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter ContainerEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter ContainerEntity due to schema")), } } else { None }; let param_container_entity = match param_container_entity { Some(param_container_entity) => param_container_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter ContainerEntity")) - .expect("Unable to create Bad Request response for missing body parameter ContainerEntity"))), + .expect("Unable to create Bad Request response for missing body parameter ContainerEntity")), }; - Box::new( - api_impl.create_container( + let result = api_impl.create_container( param_editgroup_id, param_container_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -1450,21 +1493,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -1514,41 +1559,36 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter ContainerEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter ContainerEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter ContainerEntity")), } - }) - ) as Self::Future - } + } - // CreateContainerAutoBatch - POST /editgroup/auto/container/batch - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_CONTAINER_BATCH) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateContainerAutoBatch - POST /editgroup/auto/container/batch + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_CONTAINER_BATCH) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_container_auto_batch: Option<models::ContainerAutoBatch> = if !body.is_empty() { @@ -1558,29 +1598,28 @@ where unused_elements.push(path.to_string()); }) { Ok(param_container_auto_batch) => param_container_auto_batch, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter ContainerAutoBatch - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter ContainerAutoBatch due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter ContainerAutoBatch due to schema")), } } else { None }; let param_container_auto_batch = match param_container_auto_batch { Some(param_container_auto_batch) => param_container_auto_batch, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter ContainerAutoBatch")) - .expect("Unable to create Bad Request response for missing body parameter ContainerAutoBatch"))), + .expect("Unable to create Bad Request response for missing body parameter ContainerAutoBatch")), }; - Box::new( - api_impl.create_container_auto_batch( + let result = api_impl.create_container_auto_batch( param_container_auto_batch, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -1622,21 +1661,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -1686,64 +1727,59 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter ContainerAutoBatch: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter ContainerAutoBatch"))), + .expect("Unable to create Bad Request response due to unable to read body parameter ContainerAutoBatch")), } - }) - ) as Self::Future - } + } - // CreateCreator - POST /editgroup/{editgroup_id}/creator - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateCreator - POST /editgroup/{editgroup_id}/creator + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_CREATOR .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_CREATOR in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_CREATOR.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_creator_entity: Option<models::CreatorEntity> = if !body.is_empty() { @@ -1753,30 +1789,29 @@ where unused_elements.push(path.to_string()); }) { Ok(param_creator_entity) => param_creator_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter CreatorEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter CreatorEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter CreatorEntity due to schema")), } } else { None }; let param_creator_entity = match param_creator_entity { Some(param_creator_entity) => param_creator_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter CreatorEntity")) - .expect("Unable to create Bad Request response for missing body parameter CreatorEntity"))), + .expect("Unable to create Bad Request response for missing body parameter CreatorEntity")), }; - Box::new( - api_impl.create_creator( + let result = api_impl.create_creator( param_editgroup_id, param_creator_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -1818,21 +1853,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -1882,41 +1919,36 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter CreatorEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter CreatorEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter CreatorEntity")), } - }) - ) as Self::Future - } + } - // CreateCreatorAutoBatch - POST /editgroup/auto/creator/batch - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_CREATOR_BATCH) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateCreatorAutoBatch - POST /editgroup/auto/creator/batch + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_CREATOR_BATCH) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_creator_auto_batch: Option<models::CreatorAutoBatch> = if !body.is_empty() { @@ -1926,29 +1958,28 @@ where unused_elements.push(path.to_string()); }) { Ok(param_creator_auto_batch) => param_creator_auto_batch, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter CreatorAutoBatch - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter CreatorAutoBatch due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter CreatorAutoBatch due to schema")), } } else { None }; let param_creator_auto_batch = match param_creator_auto_batch { Some(param_creator_auto_batch) => param_creator_auto_batch, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter CreatorAutoBatch")) - .expect("Unable to create Bad Request response for missing body parameter CreatorAutoBatch"))), + .expect("Unable to create Bad Request response for missing body parameter CreatorAutoBatch")), }; - Box::new( - api_impl.create_creator_auto_batch( + let result = api_impl.create_creator_auto_batch( param_creator_auto_batch, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -1990,21 +2021,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -2054,41 +2087,36 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter CreatorAutoBatch: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter CreatorAutoBatch"))), + .expect("Unable to create Bad Request response due to unable to read body parameter CreatorAutoBatch")), } - }) - ) as Self::Future - } + } - // CreateEditgroup - POST /editgroup - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateEditgroup - POST /editgroup + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_editgroup: Option<models::Editgroup> = if !body.is_empty() { @@ -2098,29 +2126,28 @@ where unused_elements.push(path.to_string()); }) { Ok(param_editgroup) => param_editgroup, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter Editgroup - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter Editgroup due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter Editgroup due to schema")), } } else { None }; let param_editgroup = match param_editgroup { Some(param_editgroup) => param_editgroup, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter Editgroup")) - .expect("Unable to create Bad Request response for missing body parameter Editgroup"))), + .expect("Unable to create Bad Request response for missing body parameter Editgroup")), }; - Box::new( - api_impl.create_editgroup( + let result = api_impl.create_editgroup( param_editgroup, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -2162,21 +2189,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -2226,64 +2255,61 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter Editgroup: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter Editgroup"))), + .expect("Unable to create Bad Request response due to unable to read body parameter Editgroup")), } - }) - ) as Self::Future - } + } - // CreateEditgroupAnnotation - POST /editgroup/{editgroup_id}/annotation - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ANNOTATION) => { + // CreateEditgroupAnnotation - POST /editgroup/{editgroup_id}/annotation + &hyper::Method::POST + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ANNOTATION) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_ANNOTATION .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_ANNOTATION in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_ANNOTATION.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_editgroup_annotation: Option<models::EditgroupAnnotation> = if !body.is_empty() { @@ -2293,30 +2319,29 @@ where unused_elements.push(path.to_string()); }) { Ok(param_editgroup_annotation) => param_editgroup_annotation, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter EditgroupAnnotation - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter EditgroupAnnotation due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter EditgroupAnnotation due to schema")), } } else { None }; let param_editgroup_annotation = match param_editgroup_annotation { Some(param_editgroup_annotation) => param_editgroup_annotation, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter EditgroupAnnotation")) - .expect("Unable to create Bad Request response for missing body parameter EditgroupAnnotation"))), + .expect("Unable to create Bad Request response for missing body parameter EditgroupAnnotation")), }; - Box::new( - api_impl.create_editgroup_annotation( + let result = api_impl.create_editgroup_annotation( param_editgroup_id, param_editgroup_annotation, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -2358,21 +2383,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -2422,64 +2449,59 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter EditgroupAnnotation: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter EditgroupAnnotation"))), + .expect("Unable to create Bad Request response due to unable to read body parameter EditgroupAnnotation")), } - }) - ) as Self::Future - } + } - // CreateFile - POST /editgroup/{editgroup_id}/file - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateFile - POST /editgroup/{editgroup_id}/file + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_FILE .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_FILE in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_FILE.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_file_entity: Option<models::FileEntity> = if !body.is_empty() { @@ -2489,30 +2511,29 @@ where unused_elements.push(path.to_string()); }) { Ok(param_file_entity) => param_file_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter FileEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter FileEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter FileEntity due to schema")), } } else { None }; let param_file_entity = match param_file_entity { Some(param_file_entity) => param_file_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter FileEntity")) - .expect("Unable to create Bad Request response for missing body parameter FileEntity"))), + .expect("Unable to create Bad Request response for missing body parameter FileEntity")), }; - Box::new( - api_impl.create_file( + let result = api_impl.create_file( param_editgroup_id, param_file_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -2554,21 +2575,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -2618,41 +2641,36 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter FileEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter FileEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter FileEntity")), } - }) - ) as Self::Future - } + } - // CreateFileAutoBatch - POST /editgroup/auto/file/batch - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_FILE_BATCH) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateFileAutoBatch - POST /editgroup/auto/file/batch + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_FILE_BATCH) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_file_auto_batch: Option<models::FileAutoBatch> = if !body.is_empty() { @@ -2662,29 +2680,28 @@ where unused_elements.push(path.to_string()); }) { Ok(param_file_auto_batch) => param_file_auto_batch, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter FileAutoBatch - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter FileAutoBatch due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter FileAutoBatch due to schema")), } } else { None }; let param_file_auto_batch = match param_file_auto_batch { Some(param_file_auto_batch) => param_file_auto_batch, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter FileAutoBatch")) - .expect("Unable to create Bad Request response for missing body parameter FileAutoBatch"))), + .expect("Unable to create Bad Request response for missing body parameter FileAutoBatch")), }; - Box::new( - api_impl.create_file_auto_batch( + let result = api_impl.create_file_auto_batch( param_file_auto_batch, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -2726,21 +2743,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -2790,64 +2809,59 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter FileAutoBatch: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter FileAutoBatch"))), + .expect("Unable to create Bad Request response due to unable to read body parameter FileAutoBatch")), } - }) - ) as Self::Future - } + } - // CreateFileset - POST /editgroup/{editgroup_id}/fileset - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateFileset - POST /editgroup/{editgroup_id}/fileset + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_FILESET .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_FILESET in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_FILESET.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_fileset_entity: Option<models::FilesetEntity> = if !body.is_empty() { @@ -2857,30 +2871,29 @@ where unused_elements.push(path.to_string()); }) { Ok(param_fileset_entity) => param_fileset_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter FilesetEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter FilesetEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter FilesetEntity due to schema")), } } else { None }; let param_fileset_entity = match param_fileset_entity { Some(param_fileset_entity) => param_fileset_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter FilesetEntity")) - .expect("Unable to create Bad Request response for missing body parameter FilesetEntity"))), + .expect("Unable to create Bad Request response for missing body parameter FilesetEntity")), }; - Box::new( - api_impl.create_fileset( + let result = api_impl.create_fileset( param_editgroup_id, param_fileset_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -2922,21 +2935,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -2986,41 +3001,36 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter FilesetEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter FilesetEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter FilesetEntity")), } - }) - ) as Self::Future - } + } - // CreateFilesetAutoBatch - POST /editgroup/auto/fileset/batch - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_FILESET_BATCH) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateFilesetAutoBatch - POST /editgroup/auto/fileset/batch + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_FILESET_BATCH) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_fileset_auto_batch: Option<models::FilesetAutoBatch> = if !body.is_empty() { @@ -3030,29 +3040,28 @@ where unused_elements.push(path.to_string()); }) { Ok(param_fileset_auto_batch) => param_fileset_auto_batch, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter FilesetAutoBatch - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter FilesetAutoBatch due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter FilesetAutoBatch due to schema")), } } else { None }; let param_fileset_auto_batch = match param_fileset_auto_batch { Some(param_fileset_auto_batch) => param_fileset_auto_batch, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter FilesetAutoBatch")) - .expect("Unable to create Bad Request response for missing body parameter FilesetAutoBatch"))), + .expect("Unable to create Bad Request response for missing body parameter FilesetAutoBatch")), }; - Box::new( - api_impl.create_fileset_auto_batch( + let result = api_impl.create_fileset_auto_batch( param_fileset_auto_batch, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -3094,21 +3103,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -3158,64 +3169,59 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter FilesetAutoBatch: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter FilesetAutoBatch"))), + .expect("Unable to create Bad Request response due to unable to read body parameter FilesetAutoBatch")), } - }) - ) as Self::Future - } + } - // CreateRelease - POST /editgroup/{editgroup_id}/release - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateRelease - POST /editgroup/{editgroup_id}/release + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_RELEASE .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_RELEASE in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_RELEASE.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_release_entity: Option<models::ReleaseEntity> = if !body.is_empty() { @@ -3225,30 +3231,29 @@ where unused_elements.push(path.to_string()); }) { Ok(param_release_entity) => param_release_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter ReleaseEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter ReleaseEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter ReleaseEntity due to schema")), } } else { None }; let param_release_entity = match param_release_entity { Some(param_release_entity) => param_release_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter ReleaseEntity")) - .expect("Unable to create Bad Request response for missing body parameter ReleaseEntity"))), + .expect("Unable to create Bad Request response for missing body parameter ReleaseEntity")), }; - Box::new( - api_impl.create_release( + let result = api_impl.create_release( param_editgroup_id, param_release_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -3290,21 +3295,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -3354,41 +3361,36 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter ReleaseEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter ReleaseEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter ReleaseEntity")), } - }) - ) as Self::Future - } + } - // CreateReleaseAutoBatch - POST /editgroup/auto/release/batch - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_RELEASE_BATCH) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateReleaseAutoBatch - POST /editgroup/auto/release/batch + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_RELEASE_BATCH) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_release_auto_batch: Option<models::ReleaseAutoBatch> = if !body.is_empty() { @@ -3398,29 +3400,28 @@ where unused_elements.push(path.to_string()); }) { Ok(param_release_auto_batch) => param_release_auto_batch, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter ReleaseAutoBatch - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter ReleaseAutoBatch due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter ReleaseAutoBatch due to schema")), } } else { None }; let param_release_auto_batch = match param_release_auto_batch { Some(param_release_auto_batch) => param_release_auto_batch, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter ReleaseAutoBatch")) - .expect("Unable to create Bad Request response for missing body parameter ReleaseAutoBatch"))), + .expect("Unable to create Bad Request response for missing body parameter ReleaseAutoBatch")), }; - Box::new( - api_impl.create_release_auto_batch( + let result = api_impl.create_release_auto_batch( param_release_auto_batch, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -3462,21 +3463,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -3526,64 +3529,61 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter ReleaseAutoBatch: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter ReleaseAutoBatch"))), + .expect("Unable to create Bad Request response due to unable to read body parameter ReleaseAutoBatch")), } - }) - ) as Self::Future - } + } - // CreateWebcapture - POST /editgroup/{editgroup_id}/webcapture - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE) => { + // CreateWebcapture - POST /editgroup/{editgroup_id}/webcapture + &hyper::Method::POST + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_WEBCAPTURE .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_WEBCAPTURE in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_WEBCAPTURE.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_webcapture_entity: Option<models::WebcaptureEntity> = if !body.is_empty() { @@ -3593,30 +3593,29 @@ where unused_elements.push(path.to_string()); }) { Ok(param_webcapture_entity) => param_webcapture_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter WebcaptureEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter WebcaptureEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter WebcaptureEntity due to schema")), } } else { None }; let param_webcapture_entity = match param_webcapture_entity { Some(param_webcapture_entity) => param_webcapture_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter WebcaptureEntity")) - .expect("Unable to create Bad Request response for missing body parameter WebcaptureEntity"))), + .expect("Unable to create Bad Request response for missing body parameter WebcaptureEntity")), }; - Box::new( - api_impl.create_webcapture( + let result = api_impl.create_webcapture( param_editgroup_id, param_webcapture_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -3658,21 +3657,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -3722,41 +3723,36 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter WebcaptureEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter WebcaptureEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter WebcaptureEntity")), } - }) - ) as Self::Future - } + } - // CreateWebcaptureAutoBatch - POST /editgroup/auto/webcapture/batch - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_WEBCAPTURE_BATCH) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateWebcaptureAutoBatch - POST /editgroup/auto/webcapture/batch + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_WEBCAPTURE_BATCH) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_webcapture_auto_batch: Option<models::WebcaptureAutoBatch> = if !body.is_empty() { @@ -3766,29 +3762,28 @@ where unused_elements.push(path.to_string()); }) { Ok(param_webcapture_auto_batch) => param_webcapture_auto_batch, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter WebcaptureAutoBatch - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter WebcaptureAutoBatch due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter WebcaptureAutoBatch due to schema")), } } else { None }; let param_webcapture_auto_batch = match param_webcapture_auto_batch { Some(param_webcapture_auto_batch) => param_webcapture_auto_batch, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter WebcaptureAutoBatch")) - .expect("Unable to create Bad Request response for missing body parameter WebcaptureAutoBatch"))), + .expect("Unable to create Bad Request response for missing body parameter WebcaptureAutoBatch")), }; - Box::new( - api_impl.create_webcapture_auto_batch( + let result = api_impl.create_webcapture_auto_batch( param_webcapture_auto_batch, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -3830,21 +3825,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -3894,64 +3891,59 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter WebcaptureAutoBatch: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter WebcaptureAutoBatch"))), + .expect("Unable to create Bad Request response due to unable to read body parameter WebcaptureAutoBatch")), } - }) - ) as Self::Future - } + } - // CreateWork - POST /editgroup/{editgroup_id}/work - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateWork - POST /editgroup/{editgroup_id}/work + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_WORK .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_WORK in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_WORK.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_work_entity: Option<models::WorkEntity> = if !body.is_empty() { @@ -3961,30 +3953,29 @@ where unused_elements.push(path.to_string()); }) { Ok(param_work_entity) => param_work_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter WorkEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter WorkEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter WorkEntity due to schema")), } } else { None }; let param_work_entity = match param_work_entity { Some(param_work_entity) => param_work_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter WorkEntity")) - .expect("Unable to create Bad Request response for missing body parameter WorkEntity"))), + .expect("Unable to create Bad Request response for missing body parameter WorkEntity")), }; - Box::new( - api_impl.create_work( + let result = api_impl.create_work( param_editgroup_id, param_work_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -4026,21 +4017,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -4090,41 +4083,36 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter WorkEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter WorkEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter WorkEntity")), } - }) - ) as Self::Future - } + } - // CreateWorkAutoBatch - POST /editgroup/auto/work/batch - &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_WORK_BATCH) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // CreateWorkAutoBatch - POST /editgroup/auto/work/batch + &hyper::Method::POST if path.matched(paths::ID_EDITGROUP_AUTO_WORK_BATCH) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_work_auto_batch: Option<models::WorkAutoBatch> = if !body.is_empty() { @@ -4134,29 +4122,28 @@ where unused_elements.push(path.to_string()); }) { Ok(param_work_auto_batch) => param_work_auto_batch, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter WorkAutoBatch - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter WorkAutoBatch due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter WorkAutoBatch due to schema")), } } else { None }; let param_work_auto_batch = match param_work_auto_batch { Some(param_work_auto_batch) => param_work_auto_batch, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter WorkAutoBatch")) - .expect("Unable to create Bad Request response for missing body parameter WorkAutoBatch"))), + .expect("Unable to create Bad Request response for missing body parameter WorkAutoBatch")), }; - Box::new( - api_impl.create_work_auto_batch( + let result = api_impl.create_work_auto_batch( param_work_auto_batch, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -4198,21 +4185,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -4262,8430 +4251,9286 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter WorkAutoBatch: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter WorkAutoBatch"))), + .expect("Unable to create Bad Request response due to unable to read body parameter WorkAutoBatch")), } - }) - ) as Self::Future - } + } - // DeleteContainer - DELETE /editgroup/{editgroup_id}/container/{ident} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT) => - { + // DeleteContainer - DELETE /editgroup/{editgroup_id}/container/{ident} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_container( - param_editgroup_id, - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_container(param_editgroup_id, param_ident, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteContainerResponse::DeletedEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteContainerResponse::DeletedEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_DELETED_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteContainerEdit - DELETE /editgroup/{editgroup_id}/container/edit/{edit_id} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_EDIT_EDIT_ID) => - { + Ok(response) + } + + // DeleteContainerEdit - DELETE /editgroup/{editgroup_id}/container/edit/{edit_id} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_EDIT_EDIT_ID) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_CONTAINER_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_CONTAINER_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_CONTAINER_EDIT_EDIT_ID.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_container_edit( - param_editgroup_id, - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_container_edit(param_editgroup_id, param_edit_id, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteContainerEditResponse::DeletedEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteContainerEditResponse::DeletedEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_EDIT_DELETED_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerEditResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerEditResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_EDIT_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerEditResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerEditResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_EDIT_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteContainerEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteContainerEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CONTAINER_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteCreator - DELETE /editgroup/{editgroup_id}/creator/{ident} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT) => - { + Ok(response) + } + + // DeleteCreator - DELETE /editgroup/{editgroup_id}/creator/{ident} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_CREATOR_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_creator( - param_editgroup_id, - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_creator(param_editgroup_id, param_ident, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteCreatorResponse::DeletedEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteCreatorResponse::DeletedEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_DELETED_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteCreatorEdit - DELETE /editgroup/{editgroup_id}/creator/edit/{edit_id} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_EDIT_EDIT_ID) => - { + Ok(response) + } + + // DeleteCreatorEdit - DELETE /editgroup/{editgroup_id}/creator/edit/{edit_id} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_EDIT_EDIT_ID) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_CREATOR_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_CREATOR_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_CREATOR_EDIT_EDIT_ID.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_creator_edit( - param_editgroup_id, - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_creator_edit(param_editgroup_id, param_edit_id, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteCreatorEditResponse::DeletedEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteCreatorEditResponse::DeletedEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_EDIT_DELETED_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorEditResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorEditResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_EDIT_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorEditResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorEditResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_EDIT_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteCreatorEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteCreatorEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_CREATOR_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteFile - DELETE /editgroup/{editgroup_id}/file/{ident} - &hyper::Method::DELETE if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_IDENT) => { + Ok(response) + } + + // DeleteFile - DELETE /editgroup/{editgroup_id}/file/{ident} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_FILE_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_FILE_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_FILE_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_file( - param_editgroup_id, - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_file(param_editgroup_id, param_ident, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteFileResponse::DeletedEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteFileResponse::DeletedEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_DELETED_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteFileEdit - DELETE /editgroup/{editgroup_id}/file/edit/{edit_id} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_EDIT_EDIT_ID) => - { + Ok(response) + } + + // DeleteFileEdit - DELETE /editgroup/{editgroup_id}/file/edit/{edit_id} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_EDIT_EDIT_ID) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_FILE_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_FILE_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_FILE_EDIT_EDIT_ID.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_file_edit( - param_editgroup_id, - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_file_edit(param_editgroup_id, param_edit_id, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteFileEditResponse::DeletedEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteFileEditResponse::DeletedEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_EDIT_DELETED_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileEditResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileEditResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_EDIT_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileEditResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileEditResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_EDIT_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFileEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFileEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILE_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteFileset - DELETE /editgroup/{editgroup_id}/fileset/{ident} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_IDENT) => - { + Ok(response) + } + + // DeleteFileset - DELETE /editgroup/{editgroup_id}/fileset/{ident} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_FILESET_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_FILESET_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_FILESET_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_fileset( - param_editgroup_id, - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_fileset(param_editgroup_id, param_ident, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteFilesetResponse::DeletedEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteFilesetResponse::DeletedEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_DELETED_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteFilesetEdit - DELETE /editgroup/{editgroup_id}/fileset/edit/{edit_id} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_EDIT_EDIT_ID) => - { + Ok(response) + } + + // DeleteFilesetEdit - DELETE /editgroup/{editgroup_id}/fileset/edit/{edit_id} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_EDIT_EDIT_ID) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_FILESET_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_FILESET_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_FILESET_EDIT_EDIT_ID.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_fileset_edit( - param_editgroup_id, - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_fileset_edit(param_editgroup_id, param_edit_id, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteFilesetEditResponse::DeletedEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteFilesetEditResponse::DeletedEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_EDIT_DELETED_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetEditResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetEditResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_EDIT_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetEditResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetEditResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_EDIT_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteFilesetEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteFilesetEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_FILESET_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteRelease - DELETE /editgroup/{editgroup_id}/release/{ident} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT) => - { + Ok(response) + } + + // DeleteRelease - DELETE /editgroup/{editgroup_id}/release/{ident} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_RELEASE_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_release( - param_editgroup_id, - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_release(param_editgroup_id, param_ident, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteReleaseResponse::DeletedEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteReleaseResponse::DeletedEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_DELETED_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteReleaseEdit - DELETE /editgroup/{editgroup_id}/release/edit/{edit_id} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_EDIT_EDIT_ID) => - { + Ok(response) + } + + // DeleteReleaseEdit - DELETE /editgroup/{editgroup_id}/release/edit/{edit_id} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_EDIT_EDIT_ID) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_RELEASE_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_RELEASE_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_RELEASE_EDIT_EDIT_ID.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_release_edit( - param_editgroup_id, - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_release_edit(param_editgroup_id, param_edit_id, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteReleaseEditResponse::DeletedEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteReleaseEditResponse::DeletedEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_EDIT_DELETED_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseEditResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseEditResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_EDIT_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseEditResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseEditResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_EDIT_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteReleaseEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteReleaseEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_RELEASE_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteWebcapture - DELETE /editgroup/{editgroup_id}/webcapture/{ident} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT) => - { + Ok(response) + } + + // DeleteWebcapture - DELETE /editgroup/{editgroup_id}/webcapture/{ident} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_webcapture( - param_editgroup_id, - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_webcapture(param_editgroup_id, param_ident, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteWebcaptureResponse::DeletedEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteWebcaptureResponse::DeletedEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_DELETED_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteWebcaptureEdit - DELETE /editgroup/{editgroup_id}/webcapture/edit/{edit_id} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_EDIT_EDIT_ID) => - { + Ok(response) + } + + // DeleteWebcaptureEdit - DELETE /editgroup/{editgroup_id}/webcapture/edit/{edit_id} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_EDIT_EDIT_ID) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_WEBCAPTURE_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_EDIT_EDIT_ID.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_webcapture_edit( - param_editgroup_id, - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_webcapture_edit(param_editgroup_id, param_edit_id, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteWebcaptureEditResponse::DeletedEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteWebcaptureEditResponse::DeletedEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_EDIT_DELETED_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureEditResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureEditResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_EDIT_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureEditResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureEditResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_EDIT_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWebcaptureEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWebcaptureEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WEBCAPTURE_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteWork - DELETE /editgroup/{editgroup_id}/work/{ident} - &hyper::Method::DELETE if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_IDENT) => { + Ok(response) + } + + // DeleteWork - DELETE /editgroup/{editgroup_id}/work/{ident} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_WORK_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_WORK_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_WORK_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_work( - param_editgroup_id, - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_work(param_editgroup_id, param_ident, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteWorkResponse::DeletedEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteWorkResponse::DeletedEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_DELETED_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // DeleteWorkEdit - DELETE /editgroup/{editgroup_id}/work/edit/{edit_id} - &hyper::Method::DELETE - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_EDIT_EDIT_ID) => - { + Ok(response) + } + + // DeleteWorkEdit - DELETE /editgroup/{editgroup_id}/work/edit/{edit_id} + &hyper::Method::DELETE + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_EDIT_EDIT_ID) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_WORK_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_WORK_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_WORK_EDIT_EDIT_ID.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.delete_work_edit( - param_editgroup_id, - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .delete_work_edit(param_editgroup_id, param_edit_id, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - DeleteWorkEditResponse::DeletedEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + DeleteWorkEditResponse::DeletedEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_EDIT_DELETED_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkEditResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkEditResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_EDIT_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkEditResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkEditResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_EDIT_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - DeleteWorkEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + DeleteWorkEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for DELETE_WORK_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetChangelog - GET /changelog - &hyper::Method::GET if path.matched(paths::ID_CHANGELOG) => { - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_changelog( - param_limit, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + Ok(response) + } - match result { - Ok(rsp) => match rsp { - GetChangelogResponse::Success - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + // GetChangelog - GET /changelog + &hyper::Method::GET if path.matched(paths::ID_CHANGELOG) => { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; + + let result = api_impl.get_changelog(param_limit, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetChangelogResponse::Success(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CHANGELOG_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetChangelogResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetChangelogResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CHANGELOG_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetChangelogResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetChangelogResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CHANGELOG_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetChangelogEntry - GET /changelog/{index} - &hyper::Method::GET if path.matched(paths::ID_CHANGELOG_INDEX) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetChangelogEntry - GET /changelog/{index} + &hyper::Method::GET if path.matched(paths::ID_CHANGELOG_INDEX) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CHANGELOG_INDEX .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CHANGELOG_INDEX in set but failed match against \"{}\"", path, paths::REGEX_CHANGELOG_INDEX.as_str()) ); - let param_index = match percent_encoding::percent_decode(path_params["index"].as_bytes()).decode_utf8() { + let param_index = match percent_encoding::percent_decode(path_params["index"].as_bytes()).decode_utf8() { Ok(param_index) => match param_index.parse::<i64>() { Ok(param_index) => param_index, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter index: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["index"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_changelog_entry( - param_index, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_changelog_entry(param_index, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetChangelogEntryResponse::FoundChangelogEntry - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetChangelogEntryResponse::FoundChangelogEntry(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CHANGELOG_ENTRY_FOUND_CHANGELOG_ENTRY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetChangelogEntryResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetChangelogEntryResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CHANGELOG_ENTRY_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetChangelogEntryResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetChangelogEntryResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CHANGELOG_ENTRY_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetChangelogEntryResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetChangelogEntryResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CHANGELOG_ENTRY_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetContainer - GET /container/{ident} - &hyper::Method::GET if path.matched(paths::ID_CONTAINER_IDENT) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetContainer - GET /container/{ident} + &hyper::Method::GET if path.matched(paths::ID_CONTAINER_IDENT) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CONTAINER_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CONTAINER_IDENT in set but failed match against \"{}\"", path, paths::REGEX_CONTAINER_IDENT.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_container( - param_ident, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetContainerResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_container(param_ident, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetContainerResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetContainerEdit - GET /container/edit/{edit_id} - &hyper::Method::GET if path.matched(paths::ID_CONTAINER_EDIT_EDIT_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetContainerEdit - GET /container/edit/{edit_id} + &hyper::Method::GET if path.matched(paths::ID_CONTAINER_EDIT_EDIT_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CONTAINER_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CONTAINER_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_CONTAINER_EDIT_EDIT_ID.as_str()) ); - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_container_edit( - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_container_edit(param_edit_id, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetContainerEditResponse::FoundEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetContainerEditResponse::FoundEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_EDIT_FOUND_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetContainerHistory - GET /container/{ident}/history - &hyper::Method::GET if path.matched(paths::ID_CONTAINER_IDENT_HISTORY) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetContainerHistory - GET /container/{ident}/history + &hyper::Method::GET if path.matched(paths::ID_CONTAINER_IDENT_HISTORY) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CONTAINER_IDENT_HISTORY .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CONTAINER_IDENT_HISTORY in set but failed match against \"{}\"", path, paths::REGEX_CONTAINER_IDENT_HISTORY.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_container_history( - param_ident, - param_limit, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetContainerHistoryResponse::FoundEntityHistory - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_container_history(param_ident, param_limit, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetContainerHistoryResponse::FoundEntityHistory(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_HISTORY_FOUND_ENTITY_HISTORY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerHistoryResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerHistoryResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_HISTORY_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerHistoryResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerHistoryResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_HISTORY_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerHistoryResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerHistoryResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_HISTORY_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetContainerRedirects - GET /container/{ident}/redirects - &hyper::Method::GET if path.matched(paths::ID_CONTAINER_IDENT_REDIRECTS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetContainerRedirects - GET /container/{ident}/redirects + &hyper::Method::GET if path.matched(paths::ID_CONTAINER_IDENT_REDIRECTS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CONTAINER_IDENT_REDIRECTS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CONTAINER_IDENT_REDIRECTS in set but failed match against \"{}\"", path, paths::REGEX_CONTAINER_IDENT_REDIRECTS.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_container_redirects( - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .get_container_redirects(param_ident, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetContainerRedirectsResponse::FoundEntityRedirects - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetContainerRedirectsResponse::FoundEntityRedirects(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_REDIRECTS_FOUND_ENTITY_REDIRECTS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerRedirectsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerRedirectsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_REDIRECTS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerRedirectsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerRedirectsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_REDIRECTS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerRedirectsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerRedirectsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_REDIRECTS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetContainerRevision - GET /container/rev/{rev_id} - &hyper::Method::GET if path.matched(paths::ID_CONTAINER_REV_REV_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetContainerRevision - GET /container/rev/{rev_id} + &hyper::Method::GET if path.matched(paths::ID_CONTAINER_REV_REV_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CONTAINER_REV_REV_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CONTAINER_REV_REV_ID in set but failed match against \"{}\"", path, paths::REGEX_CONTAINER_REV_REV_ID.as_str()) ); - let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { + let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { Ok(param_rev_id) => match param_rev_id.parse::<String>() { Ok(param_rev_id) => param_rev_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter rev_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["rev_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_container_revision( - param_rev_id, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetContainerRevisionResponse::FoundEntityRevision - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_container_revision(param_rev_id, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetContainerRevisionResponse::FoundEntityRevision(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_REVISION_FOUND_ENTITY_REVISION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerRevisionResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerRevisionResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_REVISION_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerRevisionResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerRevisionResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_REVISION_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetContainerRevisionResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetContainerRevisionResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CONTAINER_REVISION_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetCreator - GET /creator/{ident} - &hyper::Method::GET if path.matched(paths::ID_CREATOR_IDENT) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetCreator - GET /creator/{ident} + &hyper::Method::GET if path.matched(paths::ID_CREATOR_IDENT) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CREATOR_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CREATOR_IDENT in set but failed match against \"{}\"", path, paths::REGEX_CREATOR_IDENT.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_creator( - param_ident, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetCreatorResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_creator(param_ident, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetCreatorResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetCreatorEdit - GET /creator/edit/{edit_id} - &hyper::Method::GET if path.matched(paths::ID_CREATOR_EDIT_EDIT_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetCreatorEdit - GET /creator/edit/{edit_id} + &hyper::Method::GET if path.matched(paths::ID_CREATOR_EDIT_EDIT_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CREATOR_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CREATOR_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_CREATOR_EDIT_EDIT_ID.as_str()) ); - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_creator_edit( - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_creator_edit(param_edit_id, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetCreatorEditResponse::FoundEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetCreatorEditResponse::FoundEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_EDIT_FOUND_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetCreatorHistory - GET /creator/{ident}/history - &hyper::Method::GET if path.matched(paths::ID_CREATOR_IDENT_HISTORY) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetCreatorHistory - GET /creator/{ident}/history + &hyper::Method::GET if path.matched(paths::ID_CREATOR_IDENT_HISTORY) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CREATOR_IDENT_HISTORY .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CREATOR_IDENT_HISTORY in set but failed match against \"{}\"", path, paths::REGEX_CREATOR_IDENT_HISTORY.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_creator_history( - param_ident, - param_limit, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetCreatorHistoryResponse::FoundEntityHistory - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_creator_history(param_ident, param_limit, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetCreatorHistoryResponse::FoundEntityHistory(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_HISTORY_FOUND_ENTITY_HISTORY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorHistoryResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorHistoryResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_HISTORY_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorHistoryResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorHistoryResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_HISTORY_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorHistoryResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorHistoryResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_HISTORY_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetCreatorRedirects - GET /creator/{ident}/redirects - &hyper::Method::GET if path.matched(paths::ID_CREATOR_IDENT_REDIRECTS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetCreatorRedirects - GET /creator/{ident}/redirects + &hyper::Method::GET if path.matched(paths::ID_CREATOR_IDENT_REDIRECTS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CREATOR_IDENT_REDIRECTS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CREATOR_IDENT_REDIRECTS in set but failed match against \"{}\"", path, paths::REGEX_CREATOR_IDENT_REDIRECTS.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_creator_redirects( - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_creator_redirects(param_ident, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetCreatorRedirectsResponse::FoundEntityRedirects - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetCreatorRedirectsResponse::FoundEntityRedirects(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_REDIRECTS_FOUND_ENTITY_REDIRECTS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorRedirectsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorRedirectsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_REDIRECTS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorRedirectsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorRedirectsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_REDIRECTS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorRedirectsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorRedirectsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_REDIRECTS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetCreatorReleases - GET /creator/{ident}/releases - &hyper::Method::GET if path.matched(paths::ID_CREATOR_IDENT_RELEASES) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetCreatorReleases - GET /creator/{ident}/releases + &hyper::Method::GET if path.matched(paths::ID_CREATOR_IDENT_RELEASES) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CREATOR_IDENT_RELEASES .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CREATOR_IDENT_RELEASES in set but failed match against \"{}\"", path, paths::REGEX_CREATOR_IDENT_RELEASES.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_creator_releases( - param_ident, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetCreatorReleasesResponse::Found - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_creator_releases(param_ident, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetCreatorReleasesResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_RELEASES_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorReleasesResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorReleasesResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_RELEASES_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorReleasesResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorReleasesResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_RELEASES_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorReleasesResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorReleasesResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_RELEASES_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetCreatorRevision - GET /creator/rev/{rev_id} - &hyper::Method::GET if path.matched(paths::ID_CREATOR_REV_REV_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetCreatorRevision - GET /creator/rev/{rev_id} + &hyper::Method::GET if path.matched(paths::ID_CREATOR_REV_REV_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_CREATOR_REV_REV_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE CREATOR_REV_REV_ID in set but failed match against \"{}\"", path, paths::REGEX_CREATOR_REV_REV_ID.as_str()) ); - let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { + let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { Ok(param_rev_id) => match param_rev_id.parse::<String>() { Ok(param_rev_id) => param_rev_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter rev_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["rev_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_creator_revision( - param_rev_id, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetCreatorRevisionResponse::FoundEntityRevision - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_creator_revision(param_rev_id, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetCreatorRevisionResponse::FoundEntityRevision(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_REVISION_FOUND_ENTITY_REVISION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorRevisionResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorRevisionResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_REVISION_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorRevisionResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorRevisionResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_REVISION_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetCreatorRevisionResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetCreatorRevisionResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_CREATOR_REVISION_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetEditgroup - GET /editgroup/{editgroup_id} - &hyper::Method::GET if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetEditgroup - GET /editgroup/{editgroup_id} + &hyper::Method::GET if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_editgroup( - param_editgroup_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_editgroup(param_editgroup_id, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetEditgroupResponse::Found - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetEditgroupResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetEditgroupAnnotations - GET /editgroup/{editgroup_id}/annotations - &hyper::Method::GET if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ANNOTATIONS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetEditgroupAnnotations - GET /editgroup/{editgroup_id}/annotations + &hyper::Method::GET + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ANNOTATIONS) => + { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_ANNOTATIONS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_ANNOTATIONS in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_ANNOTATIONS.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_editgroup_annotations( - param_editgroup_id, - param_expand, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetEditgroupAnnotationsResponse::Success - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_editgroup_annotations(param_editgroup_id, param_expand, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetEditgroupAnnotationsResponse::Success(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_ANNOTATIONS_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupAnnotationsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupAnnotationsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_ANNOTATIONS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupAnnotationsResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupAnnotationsResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_ANNOTATIONS_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupAnnotationsResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupAnnotationsResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_ANNOTATIONS_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupAnnotationsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupAnnotationsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_ANNOTATIONS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupAnnotationsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupAnnotationsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUP_ANNOTATIONS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetEditgroupsReviewable - GET /editgroup/reviewable - &hyper::Method::GET if path.matched(paths::ID_EDITGROUP_REVIEWABLE) => { - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - let param_before = query_params - .iter() - .filter(|e| e.0 == "before") - .map(|e| e.1.to_owned()) - .nth(0); - let param_before = param_before.and_then(|param_before| param_before.parse().ok()); - let param_since = query_params - .iter() - .filter(|e| e.0 == "since") - .map(|e| e.1.to_owned()) - .nth(0); - let param_since = param_since.and_then(|param_since| param_since.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_editgroups_reviewable( - param_expand, - param_limit, - param_before, - param_since, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + Ok(response) + } - match result { - Ok(rsp) => match rsp { - GetEditgroupsReviewableResponse::Found - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + // GetEditgroupsReviewable - GET /editgroup/reviewable + &hyper::Method::GET if path.matched(paths::ID_EDITGROUP_REVIEWABLE) => { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; + let param_before = query_params + .iter() + .filter(|e| e.0 == "before") + .map(|e| e.1.to_owned()) + .nth(0); + let param_before = match param_before { + Some(param_before) => { + let param_before = + <chrono::DateTime<chrono::Utc> as std::str::FromStr>::from_str( + ¶m_before, + ); + match param_before { + Ok(param_before) => Some(param_before), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter before - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter before")), + } + } + None => None, + }; + let param_since = query_params + .iter() + .filter(|e| e.0 == "since") + .map(|e| e.1.to_owned()) + .nth(0); + let param_since = match param_since { + Some(param_since) => { + let param_since = + <chrono::DateTime<chrono::Utc> as std::str::FromStr>::from_str( + ¶m_since, + ); + match param_since { + Ok(param_since) => Some(param_since), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter since - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter since")), + } + } + None => None, + }; + + let result = api_impl + .get_editgroups_reviewable( + param_expand, + param_limit, + param_before, + param_since, + &context, + ) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetEditgroupsReviewableResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUPS_REVIEWABLE_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupsReviewableResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupsReviewableResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUPS_REVIEWABLE_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupsReviewableResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupsReviewableResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUPS_REVIEWABLE_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditgroupsReviewableResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditgroupsReviewableResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITGROUPS_REVIEWABLE_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetEditor - GET /editor/{editor_id} - &hyper::Method::GET if path.matched(paths::ID_EDITOR_EDITOR_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetEditor - GET /editor/{editor_id} + &hyper::Method::GET if path.matched(paths::ID_EDITOR_EDITOR_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITOR_EDITOR_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITOR_EDITOR_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITOR_EDITOR_ID.as_str()) ); - let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { + let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { Ok(param_editor_id) => match param_editor_id.parse::<String>() { Ok(param_editor_id) => param_editor_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editor_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editor_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_editor( - param_editor_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_editor(param_editor_id, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetEditorResponse::Found - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => { + match rsp { + GetEditorResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + } + } + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetEditorAnnotations - GET /editor/{editor_id}/annotations - &hyper::Method::GET if path.matched(paths::ID_EDITOR_EDITOR_ID_ANNOTATIONS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetEditorAnnotations - GET /editor/{editor_id}/annotations + &hyper::Method::GET if path.matched(paths::ID_EDITOR_EDITOR_ID_ANNOTATIONS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITOR_EDITOR_ID_ANNOTATIONS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITOR_EDITOR_ID_ANNOTATIONS in set but failed match against \"{}\"", path, paths::REGEX_EDITOR_EDITOR_ID_ANNOTATIONS.as_str()) ); - let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { + let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { Ok(param_editor_id) => match param_editor_id.parse::<String>() { Ok(param_editor_id) => param_editor_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editor_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editor_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - let param_before = query_params - .iter() - .filter(|e| e.0 == "before") - .map(|e| e.1.to_owned()) - .nth(0); - let param_before = param_before.and_then(|param_before| param_before.parse().ok()); - let param_since = query_params - .iter() - .filter(|e| e.0 == "since") - .map(|e| e.1.to_owned()) - .nth(0); - let param_since = param_since.and_then(|param_since| param_since.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_editor_annotations( - param_editor_id, - param_limit, - param_before, - param_since, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; + let param_before = query_params + .iter() + .filter(|e| e.0 == "before") + .map(|e| e.1.to_owned()) + .nth(0); + let param_before = match param_before { + Some(param_before) => { + let param_before = + <chrono::DateTime<chrono::Utc> as std::str::FromStr>::from_str( + ¶m_before, + ); + match param_before { + Ok(param_before) => Some(param_before), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter before - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter before")), + } + } + None => None, + }; + let param_since = query_params + .iter() + .filter(|e| e.0 == "since") + .map(|e| e.1.to_owned()) + .nth(0); + let param_since = match param_since { + Some(param_since) => { + let param_since = + <chrono::DateTime<chrono::Utc> as std::str::FromStr>::from_str( + ¶m_since, + ); + match param_since { + Ok(param_since) => Some(param_since), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter since - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter since")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetEditorAnnotationsResponse::Success - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_editor_annotations( + param_editor_id, + param_limit, + param_before, + param_since, + &context, + ) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetEditorAnnotationsResponse::Success(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_ANNOTATIONS_SUCCESS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorAnnotationsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorAnnotationsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_ANNOTATIONS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorAnnotationsResponse::NotAuthorized - { - body, - www_authenticate - } - => { - let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorAnnotationsResponse::NotAuthorized { + body, + www_authenticate, + } => { + if let Some(www_authenticate) = www_authenticate { + let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); - response.headers_mut().insert( - HeaderName::from_static("www_authenticate"), - www_authenticate - ); - response.headers_mut().insert( + response.headers_mut().insert( + HeaderName::from_static("www_authenticate"), + www_authenticate, + ); + } + *response.status_mut() = StatusCode::from_u16(401) + .expect("Unable to turn 401 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_ANNOTATIONS_NOT_AUTHORIZED")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorAnnotationsResponse::Forbidden - (body) - => { - *response.status_mut() = StatusCode::from_u16(403).expect("Unable to turn 403 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorAnnotationsResponse::Forbidden(body) => { + *response.status_mut() = StatusCode::from_u16(403) + .expect("Unable to turn 403 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_ANNOTATIONS_FORBIDDEN")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorAnnotationsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorAnnotationsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_ANNOTATIONS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorAnnotationsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorAnnotationsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_ANNOTATIONS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetEditorEditgroups - GET /editor/{editor_id}/editgroups - &hyper::Method::GET if path.matched(paths::ID_EDITOR_EDITOR_ID_EDITGROUPS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetEditorEditgroups - GET /editor/{editor_id}/editgroups + &hyper::Method::GET if path.matched(paths::ID_EDITOR_EDITOR_ID_EDITGROUPS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITOR_EDITOR_ID_EDITGROUPS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITOR_EDITOR_ID_EDITGROUPS in set but failed match against \"{}\"", path, paths::REGEX_EDITOR_EDITOR_ID_EDITGROUPS.as_str()) ); - let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { + let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { Ok(param_editor_id) => match param_editor_id.parse::<String>() { Ok(param_editor_id) => param_editor_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editor_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editor_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - let param_before = query_params - .iter() - .filter(|e| e.0 == "before") - .map(|e| e.1.to_owned()) - .nth(0); - let param_before = param_before.and_then(|param_before| param_before.parse().ok()); - let param_since = query_params - .iter() - .filter(|e| e.0 == "since") - .map(|e| e.1.to_owned()) - .nth(0); - let param_since = param_since.and_then(|param_since| param_since.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_editor_editgroups( - param_editor_id, - param_limit, - param_before, - param_since, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; + let param_before = query_params + .iter() + .filter(|e| e.0 == "before") + .map(|e| e.1.to_owned()) + .nth(0); + let param_before = match param_before { + Some(param_before) => { + let param_before = + <chrono::DateTime<chrono::Utc> as std::str::FromStr>::from_str( + ¶m_before, + ); + match param_before { + Ok(param_before) => Some(param_before), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter before - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter before")), + } + } + None => None, + }; + let param_since = query_params + .iter() + .filter(|e| e.0 == "since") + .map(|e| e.1.to_owned()) + .nth(0); + let param_since = match param_since { + Some(param_since) => { + let param_since = + <chrono::DateTime<chrono::Utc> as std::str::FromStr>::from_str( + ¶m_since, + ); + match param_since { + Ok(param_since) => Some(param_since), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter since - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter since")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetEditorEditgroupsResponse::Found - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_editor_editgroups( + param_editor_id, + param_limit, + param_before, + param_since, + &context, + ) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetEditorEditgroupsResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_EDITGROUPS_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorEditgroupsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorEditgroupsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_EDITGROUPS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorEditgroupsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorEditgroupsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_EDITGROUPS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetEditorEditgroupsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetEditorEditgroupsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_EDITOR_EDITGROUPS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFile - GET /file/{ident} - &hyper::Method::GET if path.matched(paths::ID_FILE_IDENT) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = paths::REGEX_FILE_IDENT.captures(&path).unwrap_or_else(|| { - panic!( - "Path {} matched RE FILE_IDENT in set but failed match against \"{}\"", - path, - paths::REGEX_FILE_IDENT.as_str() - ) - }); - - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + Ok(response) + } + + // GetFile - GET /file/{ident} + &hyper::Method::GET if path.matched(paths::ID_FILE_IDENT) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = + paths::REGEX_FILE_IDENT + .captures(&path) + .unwrap_or_else(|| + panic!("Path {} matched RE FILE_IDENT in set but failed match against \"{}\"", path, paths::REGEX_FILE_IDENT.as_str()) + ); + + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_file( - param_ident, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetFileResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_file(param_ident, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetFileResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFileEdit - GET /file/edit/{edit_id} - &hyper::Method::GET if path.matched(paths::ID_FILE_EDIT_EDIT_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetFileEdit - GET /file/edit/{edit_id} + &hyper::Method::GET if path.matched(paths::ID_FILE_EDIT_EDIT_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_FILE_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE FILE_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_FILE_EDIT_EDIT_ID.as_str()) ); - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_file_edit( - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_file_edit(param_edit_id, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetFileEditResponse::FoundEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetFileEditResponse::FoundEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_EDIT_FOUND_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFileHistory - GET /file/{ident}/history - &hyper::Method::GET if path.matched(paths::ID_FILE_IDENT_HISTORY) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetFileHistory - GET /file/{ident}/history + &hyper::Method::GET if path.matched(paths::ID_FILE_IDENT_HISTORY) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_FILE_IDENT_HISTORY .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE FILE_IDENT_HISTORY in set but failed match against \"{}\"", path, paths::REGEX_FILE_IDENT_HISTORY.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_file_history( - param_ident, - param_limit, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetFileHistoryResponse::FoundEntityHistory - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_file_history(param_ident, param_limit, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetFileHistoryResponse::FoundEntityHistory(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_HISTORY_FOUND_ENTITY_HISTORY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileHistoryResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileHistoryResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_HISTORY_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileHistoryResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileHistoryResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_HISTORY_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileHistoryResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileHistoryResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_HISTORY_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFileRedirects - GET /file/{ident}/redirects - &hyper::Method::GET if path.matched(paths::ID_FILE_IDENT_REDIRECTS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetFileRedirects - GET /file/{ident}/redirects + &hyper::Method::GET if path.matched(paths::ID_FILE_IDENT_REDIRECTS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_FILE_IDENT_REDIRECTS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE FILE_IDENT_REDIRECTS in set but failed match against \"{}\"", path, paths::REGEX_FILE_IDENT_REDIRECTS.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_file_redirects( - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_file_redirects(param_ident, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetFileRedirectsResponse::FoundEntityRedirects - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetFileRedirectsResponse::FoundEntityRedirects(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_REDIRECTS_FOUND_ENTITY_REDIRECTS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileRedirectsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileRedirectsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_REDIRECTS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileRedirectsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileRedirectsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_REDIRECTS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileRedirectsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileRedirectsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_REDIRECTS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFileRevision - GET /file/rev/{rev_id} - &hyper::Method::GET if path.matched(paths::ID_FILE_REV_REV_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetFileRevision - GET /file/rev/{rev_id} + &hyper::Method::GET if path.matched(paths::ID_FILE_REV_REV_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_FILE_REV_REV_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE FILE_REV_REV_ID in set but failed match against \"{}\"", path, paths::REGEX_FILE_REV_REV_ID.as_str()) ); - let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { + let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { Ok(param_rev_id) => match param_rev_id.parse::<String>() { Ok(param_rev_id) => param_rev_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter rev_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["rev_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_file_revision( - param_rev_id, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetFileRevisionResponse::FoundEntityRevision - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_file_revision(param_rev_id, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetFileRevisionResponse::FoundEntityRevision(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_REVISION_FOUND_ENTITY_REVISION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileRevisionResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileRevisionResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_REVISION_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileRevisionResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileRevisionResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_REVISION_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFileRevisionResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFileRevisionResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILE_REVISION_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFileset - GET /fileset/{ident} - &hyper::Method::GET if path.matched(paths::ID_FILESET_IDENT) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetFileset - GET /fileset/{ident} + &hyper::Method::GET if path.matched(paths::ID_FILESET_IDENT) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_FILESET_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE FILESET_IDENT in set but failed match against \"{}\"", path, paths::REGEX_FILESET_IDENT.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_fileset( - param_ident, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetFilesetResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_fileset(param_ident, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetFilesetResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFilesetEdit - GET /fileset/edit/{edit_id} - &hyper::Method::GET if path.matched(paths::ID_FILESET_EDIT_EDIT_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetFilesetEdit - GET /fileset/edit/{edit_id} + &hyper::Method::GET if path.matched(paths::ID_FILESET_EDIT_EDIT_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_FILESET_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE FILESET_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_FILESET_EDIT_EDIT_ID.as_str()) ); - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_fileset_edit( - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_fileset_edit(param_edit_id, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetFilesetEditResponse::FoundEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetFilesetEditResponse::FoundEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_EDIT_FOUND_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFilesetHistory - GET /fileset/{ident}/history - &hyper::Method::GET if path.matched(paths::ID_FILESET_IDENT_HISTORY) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetFilesetHistory - GET /fileset/{ident}/history + &hyper::Method::GET if path.matched(paths::ID_FILESET_IDENT_HISTORY) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_FILESET_IDENT_HISTORY .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE FILESET_IDENT_HISTORY in set but failed match against \"{}\"", path, paths::REGEX_FILESET_IDENT_HISTORY.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_fileset_history( - param_ident, - param_limit, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetFilesetHistoryResponse::FoundEntityHistory - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_fileset_history(param_ident, param_limit, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetFilesetHistoryResponse::FoundEntityHistory(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_HISTORY_FOUND_ENTITY_HISTORY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetHistoryResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetHistoryResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_HISTORY_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetHistoryResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetHistoryResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_HISTORY_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetHistoryResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetHistoryResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_HISTORY_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFilesetRedirects - GET /fileset/{ident}/redirects - &hyper::Method::GET if path.matched(paths::ID_FILESET_IDENT_REDIRECTS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetFilesetRedirects - GET /fileset/{ident}/redirects + &hyper::Method::GET if path.matched(paths::ID_FILESET_IDENT_REDIRECTS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_FILESET_IDENT_REDIRECTS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE FILESET_IDENT_REDIRECTS in set but failed match against \"{}\"", path, paths::REGEX_FILESET_IDENT_REDIRECTS.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_fileset_redirects( - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_fileset_redirects(param_ident, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetFilesetRedirectsResponse::FoundEntityRedirects - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetFilesetRedirectsResponse::FoundEntityRedirects(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_REDIRECTS_FOUND_ENTITY_REDIRECTS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetRedirectsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetRedirectsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_REDIRECTS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetRedirectsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetRedirectsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_REDIRECTS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetRedirectsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetRedirectsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_REDIRECTS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetFilesetRevision - GET /fileset/rev/{rev_id} - &hyper::Method::GET if path.matched(paths::ID_FILESET_REV_REV_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetFilesetRevision - GET /fileset/rev/{rev_id} + &hyper::Method::GET if path.matched(paths::ID_FILESET_REV_REV_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_FILESET_REV_REV_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE FILESET_REV_REV_ID in set but failed match against \"{}\"", path, paths::REGEX_FILESET_REV_REV_ID.as_str()) ); - let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { + let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { Ok(param_rev_id) => match param_rev_id.parse::<String>() { Ok(param_rev_id) => param_rev_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter rev_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["rev_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_fileset_revision( - param_rev_id, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetFilesetRevisionResponse::FoundEntityRevision - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_fileset_revision(param_rev_id, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetFilesetRevisionResponse::FoundEntityRevision(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_REVISION_FOUND_ENTITY_REVISION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetRevisionResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetRevisionResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_REVISION_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetRevisionResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetRevisionResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_REVISION_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetFilesetRevisionResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetFilesetRevisionResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_FILESET_REVISION_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetRelease - GET /release/{ident} - &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetRelease - GET /release/{ident} + &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_RELEASE_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE RELEASE_IDENT in set but failed match against \"{}\"", path, paths::REGEX_RELEASE_IDENT.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_release( - param_ident, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetReleaseResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_release(param_ident, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetReleaseResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetReleaseEdit - GET /release/edit/{edit_id} - &hyper::Method::GET if path.matched(paths::ID_RELEASE_EDIT_EDIT_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetReleaseEdit - GET /release/edit/{edit_id} + &hyper::Method::GET if path.matched(paths::ID_RELEASE_EDIT_EDIT_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_RELEASE_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE RELEASE_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_RELEASE_EDIT_EDIT_ID.as_str()) ); - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_release_edit( - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_release_edit(param_edit_id, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetReleaseEditResponse::FoundEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetReleaseEditResponse::FoundEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_EDIT_FOUND_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetReleaseFiles - GET /release/{ident}/files - &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_FILES) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetReleaseFiles - GET /release/{ident}/files + &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_FILES) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_RELEASE_IDENT_FILES .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE RELEASE_IDENT_FILES in set but failed match against \"{}\"", path, paths::REGEX_RELEASE_IDENT_FILES.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_release_files( - param_ident, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetReleaseFilesResponse::Found - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_release_files(param_ident, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetReleaseFilesResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_FILES_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseFilesResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseFilesResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_FILES_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseFilesResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseFilesResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_FILES_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseFilesResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseFilesResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_FILES_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetReleaseFilesets - GET /release/{ident}/filesets - &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_FILESETS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetReleaseFilesets - GET /release/{ident}/filesets + &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_FILESETS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_RELEASE_IDENT_FILESETS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE RELEASE_IDENT_FILESETS in set but failed match against \"{}\"", path, paths::REGEX_RELEASE_IDENT_FILESETS.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_release_filesets( - param_ident, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetReleaseFilesetsResponse::Found - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_release_filesets(param_ident, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetReleaseFilesetsResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_FILESETS_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseFilesetsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseFilesetsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_FILESETS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseFilesetsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseFilesetsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_FILESETS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseFilesetsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseFilesetsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_FILESETS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetReleaseHistory - GET /release/{ident}/history - &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_HISTORY) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetReleaseHistory - GET /release/{ident}/history + &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_HISTORY) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_RELEASE_IDENT_HISTORY .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE RELEASE_IDENT_HISTORY in set but failed match against \"{}\"", path, paths::REGEX_RELEASE_IDENT_HISTORY.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_release_history( - param_ident, - param_limit, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetReleaseHistoryResponse::FoundEntityHistory - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_release_history(param_ident, param_limit, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetReleaseHistoryResponse::FoundEntityHistory(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_HISTORY_FOUND_ENTITY_HISTORY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseHistoryResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseHistoryResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_HISTORY_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseHistoryResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseHistoryResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_HISTORY_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseHistoryResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseHistoryResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_HISTORY_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetReleaseRedirects - GET /release/{ident}/redirects - &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_REDIRECTS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetReleaseRedirects - GET /release/{ident}/redirects + &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_REDIRECTS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_RELEASE_IDENT_REDIRECTS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE RELEASE_IDENT_REDIRECTS in set but failed match against \"{}\"", path, paths::REGEX_RELEASE_IDENT_REDIRECTS.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_release_redirects( - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_release_redirects(param_ident, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetReleaseRedirectsResponse::FoundEntityRedirects - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetReleaseRedirectsResponse::FoundEntityRedirects(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_REDIRECTS_FOUND_ENTITY_REDIRECTS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseRedirectsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseRedirectsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_REDIRECTS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseRedirectsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseRedirectsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_REDIRECTS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseRedirectsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseRedirectsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_REDIRECTS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetReleaseRevision - GET /release/rev/{rev_id} - &hyper::Method::GET if path.matched(paths::ID_RELEASE_REV_REV_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetReleaseRevision - GET /release/rev/{rev_id} + &hyper::Method::GET if path.matched(paths::ID_RELEASE_REV_REV_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_RELEASE_REV_REV_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE RELEASE_REV_REV_ID in set but failed match against \"{}\"", path, paths::REGEX_RELEASE_REV_REV_ID.as_str()) ); - let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { + let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { Ok(param_rev_id) => match param_rev_id.parse::<String>() { Ok(param_rev_id) => param_rev_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter rev_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["rev_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_release_revision( - param_rev_id, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetReleaseRevisionResponse::FoundEntityRevision - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_release_revision(param_rev_id, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetReleaseRevisionResponse::FoundEntityRevision(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_REVISION_FOUND_ENTITY_REVISION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseRevisionResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseRevisionResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_REVISION_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseRevisionResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseRevisionResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_REVISION_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseRevisionResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseRevisionResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_REVISION_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetReleaseWebcaptures - GET /release/{ident}/webcaptures - &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_WEBCAPTURES) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetReleaseWebcaptures - GET /release/{ident}/webcaptures + &hyper::Method::GET if path.matched(paths::ID_RELEASE_IDENT_WEBCAPTURES) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_RELEASE_IDENT_WEBCAPTURES .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE RELEASE_IDENT_WEBCAPTURES in set but failed match against \"{}\"", path, paths::REGEX_RELEASE_IDENT_WEBCAPTURES.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_release_webcaptures( - param_ident, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetReleaseWebcapturesResponse::Found - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_release_webcaptures(param_ident, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetReleaseWebcapturesResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_WEBCAPTURES_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseWebcapturesResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseWebcapturesResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_WEBCAPTURES_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseWebcapturesResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseWebcapturesResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_WEBCAPTURES_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetReleaseWebcapturesResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetReleaseWebcapturesResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_RELEASE_WEBCAPTURES_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWebcapture - GET /webcapture/{ident} - &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_IDENT) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWebcapture - GET /webcapture/{ident} + &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_IDENT) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WEBCAPTURE_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WEBCAPTURE_IDENT in set but failed match against \"{}\"", path, paths::REGEX_WEBCAPTURE_IDENT.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_webcapture( - param_ident, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetWebcaptureResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_webcapture(param_ident, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetWebcaptureResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWebcaptureEdit - GET /webcapture/edit/{edit_id} - &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_EDIT_EDIT_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWebcaptureEdit - GET /webcapture/edit/{edit_id} + &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_EDIT_EDIT_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WEBCAPTURE_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WEBCAPTURE_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_WEBCAPTURE_EDIT_EDIT_ID.as_str()) ); - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_webcapture_edit( - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_webcapture_edit(param_edit_id, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetWebcaptureEditResponse::FoundEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetWebcaptureEditResponse::FoundEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_EDIT_FOUND_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWebcaptureHistory - GET /webcapture/{ident}/history - &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_IDENT_HISTORY) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWebcaptureHistory - GET /webcapture/{ident}/history + &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_IDENT_HISTORY) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WEBCAPTURE_IDENT_HISTORY .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WEBCAPTURE_IDENT_HISTORY in set but failed match against \"{}\"", path, paths::REGEX_WEBCAPTURE_IDENT_HISTORY.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_webcapture_history( - param_ident, - param_limit, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetWebcaptureHistoryResponse::FoundEntityHistory - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_webcapture_history(param_ident, param_limit, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetWebcaptureHistoryResponse::FoundEntityHistory(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_HISTORY_FOUND_ENTITY_HISTORY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureHistoryResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureHistoryResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_HISTORY_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureHistoryResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureHistoryResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_HISTORY_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureHistoryResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureHistoryResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_HISTORY_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWebcaptureRedirects - GET /webcapture/{ident}/redirects - &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_IDENT_REDIRECTS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWebcaptureRedirects - GET /webcapture/{ident}/redirects + &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_IDENT_REDIRECTS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WEBCAPTURE_IDENT_REDIRECTS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WEBCAPTURE_IDENT_REDIRECTS in set but failed match against \"{}\"", path, paths::REGEX_WEBCAPTURE_IDENT_REDIRECTS.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_webcapture_redirects( - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl + .get_webcapture_redirects(param_ident, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetWebcaptureRedirectsResponse::FoundEntityRedirects - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetWebcaptureRedirectsResponse::FoundEntityRedirects(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_REDIRECTS_FOUND_ENTITY_REDIRECTS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureRedirectsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureRedirectsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_REDIRECTS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureRedirectsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureRedirectsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_REDIRECTS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureRedirectsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureRedirectsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_REDIRECTS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWebcaptureRevision - GET /webcapture/rev/{rev_id} - &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_REV_REV_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWebcaptureRevision - GET /webcapture/rev/{rev_id} + &hyper::Method::GET if path.matched(paths::ID_WEBCAPTURE_REV_REV_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WEBCAPTURE_REV_REV_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WEBCAPTURE_REV_REV_ID in set but failed match against \"{}\"", path, paths::REGEX_WEBCAPTURE_REV_REV_ID.as_str()) ); - let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { + let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { Ok(param_rev_id) => match param_rev_id.parse::<String>() { Ok(param_rev_id) => param_rev_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter rev_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["rev_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_webcapture_revision( - param_rev_id, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetWebcaptureRevisionResponse::FoundEntityRevision - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_webcapture_revision(param_rev_id, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetWebcaptureRevisionResponse::FoundEntityRevision(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_REVISION_FOUND_ENTITY_REVISION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureRevisionResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureRevisionResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_REVISION_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureRevisionResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureRevisionResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_REVISION_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWebcaptureRevisionResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWebcaptureRevisionResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WEBCAPTURE_REVISION_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWork - GET /work/{ident} - &hyper::Method::GET if path.matched(paths::ID_WORK_IDENT) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = paths::REGEX_WORK_IDENT.captures(&path).unwrap_or_else(|| { - panic!( - "Path {} matched RE WORK_IDENT in set but failed match against \"{}\"", - path, - paths::REGEX_WORK_IDENT.as_str() - ) - }); - - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + Ok(response) + } + + // GetWork - GET /work/{ident} + &hyper::Method::GET if path.matched(paths::ID_WORK_IDENT) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = + paths::REGEX_WORK_IDENT + .captures(&path) + .unwrap_or_else(|| + panic!("Path {} matched RE WORK_IDENT in set but failed match against \"{}\"", path, paths::REGEX_WORK_IDENT.as_str()) + ); + + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_work( - param_ident, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetWorkResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_work(param_ident, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetWorkResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWorkEdit - GET /work/edit/{edit_id} - &hyper::Method::GET if path.matched(paths::ID_WORK_EDIT_EDIT_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWorkEdit - GET /work/edit/{edit_id} + &hyper::Method::GET if path.matched(paths::ID_WORK_EDIT_EDIT_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WORK_EDIT_EDIT_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WORK_EDIT_EDIT_ID in set but failed match against \"{}\"", path, paths::REGEX_WORK_EDIT_EDIT_ID.as_str()) ); - let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { + let param_edit_id = match percent_encoding::percent_decode(path_params["edit_id"].as_bytes()).decode_utf8() { Ok(param_edit_id) => match param_edit_id.parse::<String>() { Ok(param_edit_id) => param_edit_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter edit_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["edit_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_work_edit( - param_edit_id, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_work_edit(param_edit_id, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetWorkEditResponse::FoundEdit - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetWorkEditResponse::FoundEdit(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_EDIT_FOUND_EDIT")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkEditResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkEditResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_EDIT_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkEditResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkEditResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_EDIT_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkEditResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkEditResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_EDIT_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWorkHistory - GET /work/{ident}/history - &hyper::Method::GET if path.matched(paths::ID_WORK_IDENT_HISTORY) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWorkHistory - GET /work/{ident}/history + &hyper::Method::GET if path.matched(paths::ID_WORK_IDENT_HISTORY) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WORK_IDENT_HISTORY .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WORK_IDENT_HISTORY in set but failed match against \"{}\"", path, paths::REGEX_WORK_IDENT_HISTORY.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_limit = query_params - .iter() - .filter(|e| e.0 == "limit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_limit = param_limit.and_then(|param_limit| param_limit.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_work_history( - param_ident, - param_limit, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_limit = query_params + .iter() + .filter(|e| e.0 == "limit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_limit = match param_limit { + Some(param_limit) => { + let param_limit = <i64 as std::str::FromStr>::from_str(¶m_limit); + match param_limit { + Ok(param_limit) => Some(param_limit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter limit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter limit")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetWorkHistoryResponse::FoundEntityHistory - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_work_history(param_ident, param_limit, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetWorkHistoryResponse::FoundEntityHistory(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_HISTORY_FOUND_ENTITY_HISTORY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkHistoryResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkHistoryResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_HISTORY_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkHistoryResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkHistoryResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_HISTORY_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkHistoryResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkHistoryResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_HISTORY_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWorkRedirects - GET /work/{ident}/redirects - &hyper::Method::GET if path.matched(paths::ID_WORK_IDENT_REDIRECTS) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWorkRedirects - GET /work/{ident}/redirects + &hyper::Method::GET if path.matched(paths::ID_WORK_IDENT_REDIRECTS) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WORK_IDENT_REDIRECTS .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WORK_IDENT_REDIRECTS in set but failed match against \"{}\"", path, paths::REGEX_WORK_IDENT_REDIRECTS.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - Box::new({ - { - { - Box::new( - api_impl.get_work_redirects( - param_ident, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + let result = api_impl.get_work_redirects(param_ident, &context).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); - match result { - Ok(rsp) => match rsp { - GetWorkRedirectsResponse::FoundEntityRedirects - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + match result { + Ok(rsp) => match rsp { + GetWorkRedirectsResponse::FoundEntityRedirects(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_REDIRECTS_FOUND_ENTITY_REDIRECTS")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkRedirectsResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkRedirectsResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_REDIRECTS_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkRedirectsResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkRedirectsResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_REDIRECTS_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkRedirectsResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkRedirectsResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_REDIRECTS_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWorkReleases - GET /work/{ident}/releases - &hyper::Method::GET if path.matched(paths::ID_WORK_IDENT_RELEASES) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWorkReleases - GET /work/{ident}/releases + &hyper::Method::GET if path.matched(paths::ID_WORK_IDENT_RELEASES) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WORK_IDENT_RELEASES .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WORK_IDENT_RELEASES in set but failed match against \"{}\"", path, paths::REGEX_WORK_IDENT_RELEASES.as_str()) ); - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_work_releases( - param_ident, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetWorkReleasesResponse::Found - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_work_releases(param_ident, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetWorkReleasesResponse::Found(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_RELEASES_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkReleasesResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkReleasesResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_RELEASES_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkReleasesResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkReleasesResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_RELEASES_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkReleasesResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkReleasesResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_RELEASES_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // GetWorkRevision - GET /work/rev/{rev_id} - &hyper::Method::GET if path.matched(paths::ID_WORK_REV_REV_ID) => { - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + Ok(response) + } + + // GetWorkRevision - GET /work/rev/{rev_id} + &hyper::Method::GET if path.matched(paths::ID_WORK_REV_REV_ID) => { + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_WORK_REV_REV_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE WORK_REV_REV_ID in set but failed match against \"{}\"", path, paths::REGEX_WORK_REV_REV_ID.as_str()) ); - let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { + let param_rev_id = match percent_encoding::percent_decode(path_params["rev_id"].as_bytes()).decode_utf8() { Ok(param_rev_id) => match param_rev_id.parse::<String>() { Ok(param_rev_id) => param_rev_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter rev_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["rev_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.get_work_revision( - param_rev_id, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; - match result { - Ok(rsp) => match rsp { - GetWorkRevisionResponse::FoundEntityRevision - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + let result = api_impl + .get_work_revision(param_rev_id, param_expand, param_hide, &context) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + GetWorkRevisionResponse::FoundEntityRevision(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_REVISION_FOUND_ENTITY_REVISION")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkRevisionResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkRevisionResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_REVISION_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkRevisionResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkRevisionResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_REVISION_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - GetWorkRevisionResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + GetWorkRevisionResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for GET_WORK_REVISION_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // LookupContainer - GET /container/lookup - &hyper::Method::GET if path.matched(paths::ID_CONTAINER_LOOKUP) => { - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_issnl = query_params - .iter() - .filter(|e| e.0 == "issnl") - .map(|e| e.1.to_owned()) - .nth(0); - let param_issnl = param_issnl.and_then(|param_issnl| param_issnl.parse().ok()); - let param_wikidata_qid = query_params - .iter() - .filter(|e| e.0 == "wikidata_qid") - .map(|e| e.1.to_owned()) - .nth(0); - let param_wikidata_qid = param_wikidata_qid - .and_then(|param_wikidata_qid| param_wikidata_qid.parse().ok()); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.lookup_container( - param_issnl, - param_wikidata_qid, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + Ok(response) + } - match result { - Ok(rsp) => match rsp { - LookupContainerResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + // LookupContainer - GET /container/lookup + &hyper::Method::GET if path.matched(paths::ID_CONTAINER_LOOKUP) => { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_issnl = query_params + .iter() + .filter(|e| e.0 == "issnl") + .map(|e| e.1.to_owned()) + .nth(0); + let param_issnl = match param_issnl { + Some(param_issnl) => { + let param_issnl = <String as std::str::FromStr>::from_str(¶m_issnl); + match param_issnl { + Ok(param_issnl) => Some(param_issnl), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter issnl - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter issnl")), + } + } + None => None, + }; + let param_wikidata_qid = query_params + .iter() + .filter(|e| e.0 == "wikidata_qid") + .map(|e| e.1.to_owned()) + .nth(0); + let param_wikidata_qid = match param_wikidata_qid { + Some(param_wikidata_qid) => { + let param_wikidata_qid = + <String as std::str::FromStr>::from_str(¶m_wikidata_qid); + match param_wikidata_qid { + Ok(param_wikidata_qid) => Some(param_wikidata_qid), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter wikidata_qid - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter wikidata_qid")), + } + } + None => None, + }; + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; + + let result = api_impl + .lookup_container( + param_issnl, + param_wikidata_qid, + param_expand, + param_hide, + &context, + ) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + LookupContainerResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_CONTAINER_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupContainerResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupContainerResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_CONTAINER_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupContainerResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupContainerResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_CONTAINER_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupContainerResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupContainerResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_CONTAINER_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // LookupCreator - GET /creator/lookup - &hyper::Method::GET if path.matched(paths::ID_CREATOR_LOOKUP) => { - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_orcid = query_params - .iter() - .filter(|e| e.0 == "orcid") - .map(|e| e.1.to_owned()) - .nth(0); - let param_orcid = param_orcid.and_then(|param_orcid| param_orcid.parse().ok()); - let param_wikidata_qid = query_params - .iter() - .filter(|e| e.0 == "wikidata_qid") - .map(|e| e.1.to_owned()) - .nth(0); - let param_wikidata_qid = param_wikidata_qid - .and_then(|param_wikidata_qid| param_wikidata_qid.parse().ok()); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.lookup_creator( - param_orcid, - param_wikidata_qid, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + Ok(response) + } - match result { - Ok(rsp) => match rsp { - LookupCreatorResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + // LookupCreator - GET /creator/lookup + &hyper::Method::GET if path.matched(paths::ID_CREATOR_LOOKUP) => { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_orcid = query_params + .iter() + .filter(|e| e.0 == "orcid") + .map(|e| e.1.to_owned()) + .nth(0); + let param_orcid = match param_orcid { + Some(param_orcid) => { + let param_orcid = <String as std::str::FromStr>::from_str(¶m_orcid); + match param_orcid { + Ok(param_orcid) => Some(param_orcid), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter orcid - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter orcid")), + } + } + None => None, + }; + let param_wikidata_qid = query_params + .iter() + .filter(|e| e.0 == "wikidata_qid") + .map(|e| e.1.to_owned()) + .nth(0); + let param_wikidata_qid = match param_wikidata_qid { + Some(param_wikidata_qid) => { + let param_wikidata_qid = + <String as std::str::FromStr>::from_str(¶m_wikidata_qid); + match param_wikidata_qid { + Ok(param_wikidata_qid) => Some(param_wikidata_qid), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter wikidata_qid - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter wikidata_qid")), + } + } + None => None, + }; + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; + + let result = api_impl + .lookup_creator( + param_orcid, + param_wikidata_qid, + param_expand, + param_hide, + &context, + ) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + LookupCreatorResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_CREATOR_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupCreatorResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupCreatorResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_CREATOR_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupCreatorResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupCreatorResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_CREATOR_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupCreatorResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupCreatorResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_CREATOR_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // LookupFile - GET /file/lookup - &hyper::Method::GET if path.matched(paths::ID_FILE_LOOKUP) => { - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_md5 = query_params - .iter() - .filter(|e| e.0 == "md5") - .map(|e| e.1.to_owned()) - .nth(0); - let param_md5 = param_md5.and_then(|param_md5| param_md5.parse().ok()); - let param_sha1 = query_params - .iter() - .filter(|e| e.0 == "sha1") - .map(|e| e.1.to_owned()) - .nth(0); - let param_sha1 = param_sha1.and_then(|param_sha1| param_sha1.parse().ok()); - let param_sha256 = query_params - .iter() - .filter(|e| e.0 == "sha256") - .map(|e| e.1.to_owned()) - .nth(0); - let param_sha256 = param_sha256.and_then(|param_sha256| param_sha256.parse().ok()); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.lookup_file( - param_md5, - param_sha1, - param_sha256, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + Ok(response) + } - match result { - Ok(rsp) => match rsp { - LookupFileResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + // LookupFile - GET /file/lookup + &hyper::Method::GET if path.matched(paths::ID_FILE_LOOKUP) => { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_md5 = query_params + .iter() + .filter(|e| e.0 == "md5") + .map(|e| e.1.to_owned()) + .nth(0); + let param_md5 = match param_md5 { + Some(param_md5) => { + let param_md5 = <String as std::str::FromStr>::from_str(¶m_md5); + match param_md5 { + Ok(param_md5) => Some(param_md5), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter md5 - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter md5")), + } + } + None => None, + }; + let param_sha1 = query_params + .iter() + .filter(|e| e.0 == "sha1") + .map(|e| e.1.to_owned()) + .nth(0); + let param_sha1 = match param_sha1 { + Some(param_sha1) => { + let param_sha1 = <String as std::str::FromStr>::from_str(¶m_sha1); + match param_sha1 { + Ok(param_sha1) => Some(param_sha1), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter sha1 - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter sha1")), + } + } + None => None, + }; + let param_sha256 = query_params + .iter() + .filter(|e| e.0 == "sha256") + .map(|e| e.1.to_owned()) + .nth(0); + let param_sha256 = match param_sha256 { + Some(param_sha256) => { + let param_sha256 = + <String as std::str::FromStr>::from_str(¶m_sha256); + match param_sha256 { + Ok(param_sha256) => Some(param_sha256), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter sha256 - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter sha256")), + } + } + None => None, + }; + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; + + let result = api_impl + .lookup_file( + param_md5, + param_sha1, + param_sha256, + param_expand, + param_hide, + &context, + ) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + LookupFileResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_FILE_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupFileResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupFileResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_FILE_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupFileResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupFileResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_FILE_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupFileResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupFileResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_FILE_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // LookupRelease - GET /release/lookup - &hyper::Method::GET if path.matched(paths::ID_RELEASE_LOOKUP) => { - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_doi = query_params - .iter() - .filter(|e| e.0 == "doi") - .map(|e| e.1.to_owned()) - .nth(0); - let param_doi = param_doi.and_then(|param_doi| param_doi.parse().ok()); - let param_wikidata_qid = query_params - .iter() - .filter(|e| e.0 == "wikidata_qid") - .map(|e| e.1.to_owned()) - .nth(0); - let param_wikidata_qid = param_wikidata_qid - .and_then(|param_wikidata_qid| param_wikidata_qid.parse().ok()); - let param_isbn13 = query_params - .iter() - .filter(|e| e.0 == "isbn13") - .map(|e| e.1.to_owned()) - .nth(0); - let param_isbn13 = param_isbn13.and_then(|param_isbn13| param_isbn13.parse().ok()); - let param_pmid = query_params - .iter() - .filter(|e| e.0 == "pmid") - .map(|e| e.1.to_owned()) - .nth(0); - let param_pmid = param_pmid.and_then(|param_pmid| param_pmid.parse().ok()); - let param_pmcid = query_params - .iter() - .filter(|e| e.0 == "pmcid") - .map(|e| e.1.to_owned()) - .nth(0); - let param_pmcid = param_pmcid.and_then(|param_pmcid| param_pmcid.parse().ok()); - let param_core = query_params - .iter() - .filter(|e| e.0 == "core") - .map(|e| e.1.to_owned()) - .nth(0); - let param_core = param_core.and_then(|param_core| param_core.parse().ok()); - let param_arxiv = query_params - .iter() - .filter(|e| e.0 == "arxiv") - .map(|e| e.1.to_owned()) - .nth(0); - let param_arxiv = param_arxiv.and_then(|param_arxiv| param_arxiv.parse().ok()); - let param_jstor = query_params - .iter() - .filter(|e| e.0 == "jstor") - .map(|e| e.1.to_owned()) - .nth(0); - let param_jstor = param_jstor.and_then(|param_jstor| param_jstor.parse().ok()); - let param_ark = query_params - .iter() - .filter(|e| e.0 == "ark") - .map(|e| e.1.to_owned()) - .nth(0); - let param_ark = param_ark.and_then(|param_ark| param_ark.parse().ok()); - let param_mag = query_params - .iter() - .filter(|e| e.0 == "mag") - .map(|e| e.1.to_owned()) - .nth(0); - let param_mag = param_mag.and_then(|param_mag| param_mag.parse().ok()); - let param_expand = query_params - .iter() - .filter(|e| e.0 == "expand") - .map(|e| e.1.to_owned()) - .nth(0); - let param_expand = param_expand.and_then(|param_expand| param_expand.parse().ok()); - let param_hide = query_params - .iter() - .filter(|e| e.0 == "hide") - .map(|e| e.1.to_owned()) - .nth(0); - let param_hide = param_hide.and_then(|param_hide| param_hide.parse().ok()); - - Box::new({ - { - { - Box::new( - api_impl.lookup_release( - param_doi, - param_wikidata_qid, - param_isbn13, - param_pmid, - param_pmcid, - param_core, - param_arxiv, - param_jstor, - param_ark, - param_mag, - param_expand, - param_hide, - &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( - HeaderName::from_static("x-span-id"), - HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) - .expect("Unable to create X-Span-ID header value")); + Ok(response) + } - match result { - Ok(rsp) => match rsp { - LookupReleaseResponse::FoundEntity - (body) - => { - *response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode"); - response.headers_mut().insert( + // LookupRelease - GET /release/lookup + &hyper::Method::GET if path.matched(paths::ID_RELEASE_LOOKUP) => { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_doi = query_params + .iter() + .filter(|e| e.0 == "doi") + .map(|e| e.1.to_owned()) + .nth(0); + let param_doi = match param_doi { + Some(param_doi) => { + let param_doi = <String as std::str::FromStr>::from_str(¶m_doi); + match param_doi { + Ok(param_doi) => Some(param_doi), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter doi - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter doi")), + } + } + None => None, + }; + let param_wikidata_qid = query_params + .iter() + .filter(|e| e.0 == "wikidata_qid") + .map(|e| e.1.to_owned()) + .nth(0); + let param_wikidata_qid = match param_wikidata_qid { + Some(param_wikidata_qid) => { + let param_wikidata_qid = + <String as std::str::FromStr>::from_str(¶m_wikidata_qid); + match param_wikidata_qid { + Ok(param_wikidata_qid) => Some(param_wikidata_qid), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter wikidata_qid - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter wikidata_qid")), + } + } + None => None, + }; + let param_isbn13 = query_params + .iter() + .filter(|e| e.0 == "isbn13") + .map(|e| e.1.to_owned()) + .nth(0); + let param_isbn13 = match param_isbn13 { + Some(param_isbn13) => { + let param_isbn13 = + <String as std::str::FromStr>::from_str(¶m_isbn13); + match param_isbn13 { + Ok(param_isbn13) => Some(param_isbn13), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter isbn13 - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter isbn13")), + } + } + None => None, + }; + let param_pmid = query_params + .iter() + .filter(|e| e.0 == "pmid") + .map(|e| e.1.to_owned()) + .nth(0); + let param_pmid = match param_pmid { + Some(param_pmid) => { + let param_pmid = <String as std::str::FromStr>::from_str(¶m_pmid); + match param_pmid { + Ok(param_pmid) => Some(param_pmid), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter pmid - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter pmid")), + } + } + None => None, + }; + let param_pmcid = query_params + .iter() + .filter(|e| e.0 == "pmcid") + .map(|e| e.1.to_owned()) + .nth(0); + let param_pmcid = match param_pmcid { + Some(param_pmcid) => { + let param_pmcid = <String as std::str::FromStr>::from_str(¶m_pmcid); + match param_pmcid { + Ok(param_pmcid) => Some(param_pmcid), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter pmcid - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter pmcid")), + } + } + None => None, + }; + let param_core = query_params + .iter() + .filter(|e| e.0 == "core") + .map(|e| e.1.to_owned()) + .nth(0); + let param_core = match param_core { + Some(param_core) => { + let param_core = <String as std::str::FromStr>::from_str(¶m_core); + match param_core { + Ok(param_core) => Some(param_core), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter core - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter core")), + } + } + None => None, + }; + let param_arxiv = query_params + .iter() + .filter(|e| e.0 == "arxiv") + .map(|e| e.1.to_owned()) + .nth(0); + let param_arxiv = match param_arxiv { + Some(param_arxiv) => { + let param_arxiv = <String as std::str::FromStr>::from_str(¶m_arxiv); + match param_arxiv { + Ok(param_arxiv) => Some(param_arxiv), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter arxiv - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter arxiv")), + } + } + None => None, + }; + let param_jstor = query_params + .iter() + .filter(|e| e.0 == "jstor") + .map(|e| e.1.to_owned()) + .nth(0); + let param_jstor = match param_jstor { + Some(param_jstor) => { + let param_jstor = <String as std::str::FromStr>::from_str(¶m_jstor); + match param_jstor { + Ok(param_jstor) => Some(param_jstor), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter jstor - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter jstor")), + } + } + None => None, + }; + let param_ark = query_params + .iter() + .filter(|e| e.0 == "ark") + .map(|e| e.1.to_owned()) + .nth(0); + let param_ark = match param_ark { + Some(param_ark) => { + let param_ark = <String as std::str::FromStr>::from_str(¶m_ark); + match param_ark { + Ok(param_ark) => Some(param_ark), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter ark - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter ark")), + } + } + None => None, + }; + let param_mag = query_params + .iter() + .filter(|e| e.0 == "mag") + .map(|e| e.1.to_owned()) + .nth(0); + let param_mag = match param_mag { + Some(param_mag) => { + let param_mag = <String as std::str::FromStr>::from_str(¶m_mag); + match param_mag { + Ok(param_mag) => Some(param_mag), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter mag - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter mag")), + } + } + None => None, + }; + let param_doaj = query_params + .iter() + .filter(|e| e.0 == "doaj") + .map(|e| e.1.to_owned()) + .nth(0); + let param_doaj = match param_doaj { + Some(param_doaj) => { + let param_doaj = <String as std::str::FromStr>::from_str(¶m_doaj); + match param_doaj { + Ok(param_doaj) => Some(param_doaj), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter doaj - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter doaj")), + } + } + None => None, + }; + let param_dblp = query_params + .iter() + .filter(|e| e.0 == "dblp") + .map(|e| e.1.to_owned()) + .nth(0); + let param_dblp = match param_dblp { + Some(param_dblp) => { + let param_dblp = <String as std::str::FromStr>::from_str(¶m_dblp); + match param_dblp { + Ok(param_dblp) => Some(param_dblp), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter dblp - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter dblp")), + } + } + None => None, + }; + let param_oai = query_params + .iter() + .filter(|e| e.0 == "oai") + .map(|e| e.1.to_owned()) + .nth(0); + let param_oai = match param_oai { + Some(param_oai) => { + let param_oai = <String as std::str::FromStr>::from_str(¶m_oai); + match param_oai { + Ok(param_oai) => Some(param_oai), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter oai - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter oai")), + } + } + None => None, + }; + let param_expand = query_params + .iter() + .filter(|e| e.0 == "expand") + .map(|e| e.1.to_owned()) + .nth(0); + let param_expand = match param_expand { + Some(param_expand) => { + let param_expand = + <String as std::str::FromStr>::from_str(¶m_expand); + match param_expand { + Ok(param_expand) => Some(param_expand), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter expand - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter expand")), + } + } + None => None, + }; + let param_hide = query_params + .iter() + .filter(|e| e.0 == "hide") + .map(|e| e.1.to_owned()) + .nth(0); + let param_hide = match param_hide { + Some(param_hide) => { + let param_hide = <String as std::str::FromStr>::from_str(¶m_hide); + match param_hide { + Ok(param_hide) => Some(param_hide), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter hide - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter hide")), + } + } + None => None, + }; + + let result = api_impl + .lookup_release( + param_doi, + param_wikidata_qid, + param_isbn13, + param_pmid, + param_pmcid, + param_core, + param_arxiv, + param_jstor, + param_ark, + param_mag, + param_doaj, + param_dblp, + param_oai, + param_expand, + param_hide, + &context, + ) + .await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( + HeaderName::from_static("x-span-id"), + HeaderValue::from_str( + (&context as &dyn Has<XSpanIdString>) + .get() + .0 + .clone() + .to_string() + .as_str(), + ) + .expect("Unable to create X-Span-ID header value"), + ); + + match result { + Ok(rsp) => match rsp { + LookupReleaseResponse::FoundEntity(body) => { + *response.status_mut() = StatusCode::from_u16(200) + .expect("Unable to turn 200 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_RELEASE_FOUND_ENTITY")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupReleaseResponse::BadRequest - (body) - => { - *response.status_mut() = StatusCode::from_u16(400).expect("Unable to turn 400 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupReleaseResponse::BadRequest(body) => { + *response.status_mut() = StatusCode::from_u16(400) + .expect("Unable to turn 400 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_RELEASE_BAD_REQUEST")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupReleaseResponse::NotFound - (body) - => { - *response.status_mut() = StatusCode::from_u16(404).expect("Unable to turn 404 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupReleaseResponse::NotFound(body) => { + *response.status_mut() = StatusCode::from_u16(404) + .expect("Unable to turn 404 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_RELEASE_NOT_FOUND")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - LookupReleaseResponse::GenericError - (body) - => { - *response.status_mut() = StatusCode::from_u16(500).expect("Unable to turn 500 into a StatusCode"); - response.headers_mut().insert( + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + LookupReleaseResponse::GenericError(body) => { + *response.status_mut() = StatusCode::from_u16(500) + .expect("Unable to turn 500 into a StatusCode"); + response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") .expect("Unable to create Content-Type header for LOOKUP_RELEASE_GENERIC_ERROR")); - let body = serde_json::to_string(&body).expect("impossible to fail to serialize"); - *response.body_mut() = Body::from(body); - }, - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - *response.body_mut() = Body::from("An internal error occurred"); - }, - } - - future::ok(response) - } - )) + let body = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + *response.body_mut() = Body::from(body); + } + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + *response.body_mut() = Body::from("An internal error occurred"); } } - }) as Self::Future - } - // UpdateContainer - PUT /editgroup/{editgroup_id}/container/{ident} - &hyper::Method::PUT - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT) => - { + Ok(response) + } + + // UpdateContainer - PUT /editgroup/{editgroup_id}/container/{ident} + &hyper::Method::PUT + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_container_entity: Option<models::ContainerEntity> = if !body.is_empty() { @@ -12695,31 +13540,30 @@ where unused_elements.push(path.to_string()); }) { Ok(param_container_entity) => param_container_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter ContainerEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter ContainerEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter ContainerEntity due to schema")), } } else { None }; let param_container_entity = match param_container_entity { Some(param_container_entity) => param_container_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter ContainerEntity")) - .expect("Unable to create Bad Request response for missing body parameter ContainerEntity"))), + .expect("Unable to create Bad Request response for missing body parameter ContainerEntity")), }; - Box::new( - api_impl.update_container( + let result = api_impl.update_container( param_editgroup_id, param_ident, param_container_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -12761,21 +13605,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -12825,78 +13671,75 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter ContainerEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter ContainerEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter ContainerEntity")), } - }) - ) as Self::Future - } + } - // UpdateCreator - PUT /editgroup/{editgroup_id}/creator/{ident} - &hyper::Method::PUT if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT) => { + // UpdateCreator - PUT /editgroup/{editgroup_id}/creator/{ident} + &hyper::Method::PUT + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_CREATOR_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_creator_entity: Option<models::CreatorEntity> = if !body.is_empty() { @@ -12906,31 +13749,30 @@ where unused_elements.push(path.to_string()); }) { Ok(param_creator_entity) => param_creator_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter CreatorEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter CreatorEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter CreatorEntity due to schema")), } } else { None }; let param_creator_entity = match param_creator_entity { Some(param_creator_entity) => param_creator_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter CreatorEntity")) - .expect("Unable to create Bad Request response for missing body parameter CreatorEntity"))), + .expect("Unable to create Bad Request response for missing body parameter CreatorEntity")), }; - Box::new( - api_impl.update_creator( + let result = api_impl.update_creator( param_editgroup_id, param_ident, param_creator_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -12972,21 +13814,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -13036,75 +13880,82 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter CreatorEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter CreatorEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter CreatorEntity")), } - }) - ) as Self::Future - } + } - // UpdateEditgroup - PUT /editgroup/{editgroup_id} - &hyper::Method::PUT if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // UpdateEditgroup - PUT /editgroup/{editgroup_id} + &hyper::Method::PUT if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = - form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) - .collect::<Vec<_>>(); - let param_submit = query_params - .iter() - .filter(|e| e.0 == "submit") - .map(|e| e.1.to_owned()) - .nth(0); - let param_submit = param_submit.and_then(|param_submit| param_submit.parse().ok()); - - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = + form_urlencoded::parse(uri.query().unwrap_or_default().as_bytes()) + .collect::<Vec<_>>(); + let param_submit = query_params + .iter() + .filter(|e| e.0 == "submit") + .map(|e| e.1.to_owned()) + .nth(0); + let param_submit = match param_submit { + Some(param_submit) => { + let param_submit = <bool as std::str::FromStr>::from_str(¶m_submit); + match param_submit { + Ok(param_submit) => Some(param_submit), + Err(e) => return Ok(Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from(format!("Couldn't parse query parameter submit - doesn't match schema: {}", e))) + .expect("Unable to create Bad Request response for invalid query parameter submit")), + } + } + None => None, + }; + + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_editgroup: Option<models::Editgroup> = if !body.is_empty() { @@ -13114,31 +13965,30 @@ where unused_elements.push(path.to_string()); }) { Ok(param_editgroup) => param_editgroup, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter Editgroup - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter Editgroup due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter Editgroup due to schema")), } } else { None }; let param_editgroup = match param_editgroup { Some(param_editgroup) => param_editgroup, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter Editgroup")) - .expect("Unable to create Bad Request response for missing body parameter Editgroup"))), + .expect("Unable to create Bad Request response for missing body parameter Editgroup")), }; - Box::new( - api_impl.update_editgroup( + let result = api_impl.update_editgroup( param_editgroup_id, param_editgroup, param_submit, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -13180,21 +14030,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -13244,64 +14096,59 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter Editgroup: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter Editgroup"))), + .expect("Unable to create Bad Request response due to unable to read body parameter Editgroup")), } - }) - ) as Self::Future - } + } - // UpdateEditor - PUT /editor/{editor_id} - &hyper::Method::PUT if path.matched(paths::ID_EDITOR_EDITOR_ID) => { - { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + // UpdateEditor - PUT /editor/{editor_id} + &hyper::Method::PUT if path.matched(paths::ID_EDITOR_EDITOR_ID) => { + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITOR_EDITOR_ID .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITOR_EDITOR_ID in set but failed match against \"{}\"", path, paths::REGEX_EDITOR_EDITOR_ID.as_str()) ); - let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { + let param_editor_id = match percent_encoding::percent_decode(path_params["editor_id"].as_bytes()).decode_utf8() { Ok(param_editor_id) => match param_editor_id.parse::<String>() { Ok(param_editor_id) => param_editor_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editor_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editor_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_editor: Option<models::Editor> = if !body.is_empty() { @@ -13311,30 +14158,29 @@ where unused_elements.push(path.to_string()); }) { Ok(param_editor) => param_editor, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter Editor - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter Editor due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter Editor due to schema")), } } else { None }; let param_editor = match param_editor { Some(param_editor) => param_editor, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter Editor")) - .expect("Unable to create Bad Request response for missing body parameter Editor"))), + .expect("Unable to create Bad Request response for missing body parameter Editor")), }; - Box::new( - api_impl.update_editor( + let result = api_impl.update_editor( param_editor_id, param_editor, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -13376,21 +14222,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -13440,78 +14288,75 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter Editor: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter Editor"))), + .expect("Unable to create Bad Request response due to unable to read body parameter Editor")), } - }) - ) as Self::Future - } + } - // UpdateFile - PUT /editgroup/{editgroup_id}/file/{ident} - &hyper::Method::PUT if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_IDENT) => { + // UpdateFile - PUT /editgroup/{editgroup_id}/file/{ident} + &hyper::Method::PUT + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_FILE_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_FILE_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_FILE_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_file_entity: Option<models::FileEntity> = if !body.is_empty() { @@ -13521,31 +14366,30 @@ where unused_elements.push(path.to_string()); }) { Ok(param_file_entity) => param_file_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter FileEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter FileEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter FileEntity due to schema")), } } else { None }; let param_file_entity = match param_file_entity { Some(param_file_entity) => param_file_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter FileEntity")) - .expect("Unable to create Bad Request response for missing body parameter FileEntity"))), + .expect("Unable to create Bad Request response for missing body parameter FileEntity")), }; - Box::new( - api_impl.update_file( + let result = api_impl.update_file( param_editgroup_id, param_ident, param_file_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -13587,21 +14431,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -13651,78 +14497,75 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter FileEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter FileEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter FileEntity")), } - }) - ) as Self::Future - } + } - // UpdateFileset - PUT /editgroup/{editgroup_id}/fileset/{ident} - &hyper::Method::PUT if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_IDENT) => { + // UpdateFileset - PUT /editgroup/{editgroup_id}/fileset/{ident} + &hyper::Method::PUT + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_FILESET_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_FILESET_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_FILESET_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_fileset_entity: Option<models::FilesetEntity> = if !body.is_empty() { @@ -13732,31 +14575,30 @@ where unused_elements.push(path.to_string()); }) { Ok(param_fileset_entity) => param_fileset_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter FilesetEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter FilesetEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter FilesetEntity due to schema")), } } else { None }; let param_fileset_entity = match param_fileset_entity { Some(param_fileset_entity) => param_fileset_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter FilesetEntity")) - .expect("Unable to create Bad Request response for missing body parameter FilesetEntity"))), + .expect("Unable to create Bad Request response for missing body parameter FilesetEntity")), }; - Box::new( - api_impl.update_fileset( + let result = api_impl.update_fileset( param_editgroup_id, param_ident, param_fileset_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -13798,21 +14640,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -13862,78 +14706,75 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter FilesetEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter FilesetEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter FilesetEntity")), } - }) - ) as Self::Future - } + } - // UpdateRelease - PUT /editgroup/{editgroup_id}/release/{ident} - &hyper::Method::PUT if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT) => { + // UpdateRelease - PUT /editgroup/{editgroup_id}/release/{ident} + &hyper::Method::PUT + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_RELEASE_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_release_entity: Option<models::ReleaseEntity> = if !body.is_empty() { @@ -13943,31 +14784,30 @@ where unused_elements.push(path.to_string()); }) { Ok(param_release_entity) => param_release_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter ReleaseEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter ReleaseEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter ReleaseEntity due to schema")), } } else { None }; let param_release_entity = match param_release_entity { Some(param_release_entity) => param_release_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter ReleaseEntity")) - .expect("Unable to create Bad Request response for missing body parameter ReleaseEntity"))), + .expect("Unable to create Bad Request response for missing body parameter ReleaseEntity")), }; - Box::new( - api_impl.update_release( + let result = api_impl.update_release( param_editgroup_id, param_ident, param_release_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -14009,21 +14849,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -14073,80 +14915,75 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter ReleaseEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter ReleaseEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter ReleaseEntity")), } - }) - ) as Self::Future - } + } - // UpdateWebcapture - PUT /editgroup/{editgroup_id}/webcapture/{ident} - &hyper::Method::PUT - if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT) => - { + // UpdateWebcapture - PUT /editgroup/{editgroup_id}/webcapture/{ident} + &hyper::Method::PUT + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_webcapture_entity: Option<models::WebcaptureEntity> = if !body.is_empty() { @@ -14156,31 +14993,30 @@ where unused_elements.push(path.to_string()); }) { Ok(param_webcapture_entity) => param_webcapture_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter WebcaptureEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter WebcaptureEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter WebcaptureEntity due to schema")), } } else { None }; let param_webcapture_entity = match param_webcapture_entity { Some(param_webcapture_entity) => param_webcapture_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter WebcaptureEntity")) - .expect("Unable to create Bad Request response for missing body parameter WebcaptureEntity"))), + .expect("Unable to create Bad Request response for missing body parameter WebcaptureEntity")), }; - Box::new( - api_impl.update_webcapture( + let result = api_impl.update_webcapture( param_editgroup_id, param_ident, param_webcapture_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -14222,21 +15058,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -14286,78 +15124,75 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter WebcaptureEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter WebcaptureEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter WebcaptureEntity")), } - }) - ) as Self::Future - } + } - // UpdateWork - PUT /editgroup/{editgroup_id}/work/{ident} - &hyper::Method::PUT if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_IDENT) => { + // UpdateWork - PUT /editgroup/{editgroup_id}/work/{ident} + &hyper::Method::PUT + if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_IDENT) => { - let authorization = match (&context as &dyn Has<Option<Authorization>>).get() { - &Some(ref authorization) => authorization, - &None => { - return Box::new(future::ok( - Response::builder() + { + let authorization = match (&context as &dyn Has<Option<Authorization>>) + .get() + { + &Some(ref authorization) => authorization, + &None => { + return Ok(Response::builder() .status(StatusCode::FORBIDDEN) .body(Body::from("Unauthenticated")) - .expect("Unable to create Authentication Forbidden response"), - )) - } - }; - } + .expect("Unable to create Authentication Forbidden response")) + } + }; + } - // Path parameters - let path: &str = &uri.path().to_string(); - let path_params = + // Path parameters + let path: &str = &uri.path().to_string(); + let path_params = paths::REGEX_EDITGROUP_EDITGROUP_ID_WORK_IDENT .captures(&path) .unwrap_or_else(|| panic!("Path {} matched RE EDITGROUP_EDITGROUP_ID_WORK_IDENT in set but failed match against \"{}\"", path, paths::REGEX_EDITGROUP_EDITGROUP_ID_WORK_IDENT.as_str()) ); - let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { + let param_editgroup_id = match percent_encoding::percent_decode(path_params["editgroup_id"].as_bytes()).decode_utf8() { Ok(param_editgroup_id) => match param_editgroup_id.parse::<String>() { Ok(param_editgroup_id) => param_editgroup_id, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter editgroup_id: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["editgroup_id"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { + let param_ident = match percent_encoding::percent_decode(path_params["ident"].as_bytes()).decode_utf8() { Ok(param_ident) => match param_ident.parse::<String>() { Ok(param_ident) => param_ident, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse path parameter ident: {}", e))) - .expect("Unable to create Bad Request response for invalid path parameter"))), + .expect("Unable to create Bad Request response for invalid path parameter")), }, - Err(_) => return Box::new(future::ok(Response::builder() + Err(_) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["ident"]))) - .expect("Unable to create Bad Request response for invalid percent decode"))) + .expect("Unable to create Bad Request response for invalid percent decode")) }; - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - Box::new(body.concat2() - .then(move |result| -> Self::Future { - match result { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + let result = body.to_raw().await; + match result { Ok(body) => { let mut unused_elements = Vec::new(); let param_work_entity: Option<models::WorkEntity> = if !body.is_empty() { @@ -14367,31 +15202,30 @@ where unused_elements.push(path.to_string()); }) { Ok(param_work_entity) => param_work_entity, - Err(e) => return Box::new(future::ok(Response::builder() + Err(e) => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't parse body parameter WorkEntity - doesn't match schema: {}", e))) - .expect("Unable to create Bad Request response for invalid body parameter WorkEntity due to schema"))), + .expect("Unable to create Bad Request response for invalid body parameter WorkEntity due to schema")), } } else { None }; let param_work_entity = match param_work_entity { Some(param_work_entity) => param_work_entity, - None => return Box::new(future::ok(Response::builder() + None => return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from("Missing required body parameter WorkEntity")) - .expect("Unable to create Bad Request response for missing body parameter WorkEntity"))), + .expect("Unable to create Bad Request response for missing body parameter WorkEntity")), }; - Box::new( - api_impl.update_work( + let result = api_impl.update_work( param_editgroup_id, param_ident, param_work_entity, &context - ).then(move |result| { - let mut response = Response::new(Body::empty()); - response.headers_mut().insert( + ).await; + let mut response = Response::new(Body::empty()); + response.headers_mut().insert( HeaderName::from_static("x-span-id"), HeaderValue::from_str((&context as &dyn Has<XSpanIdString>).get().0.clone().to_string().as_str()) .expect("Unable to create X-Span-ID header value")); @@ -14433,21 +15267,23 @@ where www_authenticate } => { + if let Some(www_authenticate) = www_authenticate { let www_authenticate = match header::IntoHeaderValue(www_authenticate).try_into() { Ok(val) => val, Err(e) => { - return future::ok(Response::builder() + return Ok(Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(Body::from(format!("An internal server error occurred handling www_authenticate header - {}", e))) .expect("Unable to create Internal Server Error for invalid response header")) } }; - *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( HeaderName::from_static("www_authenticate"), www_authenticate ); + } + *response.status_mut() = StatusCode::from_u16(401).expect("Unable to turn 401 into a StatusCode"); response.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_str("application/json") @@ -14497,148 +15333,146 @@ where }, } - future::ok(response) - } - )) + Ok(response) }, - Err(e) => Box::new(future::ok(Response::builder() + Err(e) => Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(format!("Couldn't read body parameter WorkEntity: {}", e))) - .expect("Unable to create Bad Request response due to unable to read body parameter WorkEntity"))), + .expect("Unable to create Bad Request response due to unable to read body parameter WorkEntity")), } - }) - ) as Self::Future - } + } - _ if path.matched(paths::ID_AUTH_CHECK) => method_not_allowed(), - _ if path.matched(paths::ID_AUTH_OIDC) => method_not_allowed(), - _ if path.matched(paths::ID_AUTH_TOKEN_EDITOR_ID) => method_not_allowed(), - _ if path.matched(paths::ID_CHANGELOG) => method_not_allowed(), - _ if path.matched(paths::ID_CHANGELOG_INDEX) => method_not_allowed(), - _ if path.matched(paths::ID_CONTAINER_EDIT_EDIT_ID) => method_not_allowed(), - _ if path.matched(paths::ID_CONTAINER_LOOKUP) => method_not_allowed(), - _ if path.matched(paths::ID_CONTAINER_REV_REV_ID) => method_not_allowed(), - _ if path.matched(paths::ID_CONTAINER_IDENT) => method_not_allowed(), - _ if path.matched(paths::ID_CONTAINER_IDENT_HISTORY) => method_not_allowed(), - _ if path.matched(paths::ID_CONTAINER_IDENT_REDIRECTS) => method_not_allowed(), - _ if path.matched(paths::ID_CREATOR_EDIT_EDIT_ID) => method_not_allowed(), - _ if path.matched(paths::ID_CREATOR_LOOKUP) => method_not_allowed(), - _ if path.matched(paths::ID_CREATOR_REV_REV_ID) => method_not_allowed(), - _ if path.matched(paths::ID_CREATOR_IDENT) => method_not_allowed(), - _ if path.matched(paths::ID_CREATOR_IDENT_HISTORY) => method_not_allowed(), - _ if path.matched(paths::ID_CREATOR_IDENT_REDIRECTS) => method_not_allowed(), - _ if path.matched(paths::ID_CREATOR_IDENT_RELEASES) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_AUTO_CONTAINER_BATCH) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_AUTO_CREATOR_BATCH) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_AUTO_FILE_BATCH) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_AUTO_FILESET_BATCH) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_AUTO_RELEASE_BATCH) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_AUTO_WEBCAPTURE_BATCH) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_AUTO_WORK_BATCH) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_REVIEWABLE) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ACCEPT) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ANNOTATION) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ANNOTATIONS) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_EDIT_EDIT_ID) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_EDIT_EDIT_ID) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_EDIT_EDIT_ID) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_IDENT) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_EDIT_EDIT_ID) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_IDENT) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_EDIT_EDIT_ID) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_EDIT_EDIT_ID) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK) => method_not_allowed(), - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_EDIT_EDIT_ID) => { - method_not_allowed() - } - _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_IDENT) => method_not_allowed(), - _ if path.matched(paths::ID_EDITOR_EDITOR_ID) => method_not_allowed(), - _ if path.matched(paths::ID_EDITOR_EDITOR_ID_ANNOTATIONS) => method_not_allowed(), - _ if path.matched(paths::ID_EDITOR_EDITOR_ID_EDITGROUPS) => method_not_allowed(), - _ if path.matched(paths::ID_FILE_EDIT_EDIT_ID) => method_not_allowed(), - _ if path.matched(paths::ID_FILE_LOOKUP) => method_not_allowed(), - _ if path.matched(paths::ID_FILE_REV_REV_ID) => method_not_allowed(), - _ if path.matched(paths::ID_FILE_IDENT) => method_not_allowed(), - _ if path.matched(paths::ID_FILE_IDENT_HISTORY) => method_not_allowed(), - _ if path.matched(paths::ID_FILE_IDENT_REDIRECTS) => method_not_allowed(), - _ if path.matched(paths::ID_FILESET_EDIT_EDIT_ID) => method_not_allowed(), - _ if path.matched(paths::ID_FILESET_REV_REV_ID) => method_not_allowed(), - _ if path.matched(paths::ID_FILESET_IDENT) => method_not_allowed(), - _ if path.matched(paths::ID_FILESET_IDENT_HISTORY) => method_not_allowed(), - _ if path.matched(paths::ID_FILESET_IDENT_REDIRECTS) => method_not_allowed(), - _ if path.matched(paths::ID_RELEASE_EDIT_EDIT_ID) => method_not_allowed(), - _ if path.matched(paths::ID_RELEASE_LOOKUP) => method_not_allowed(), - _ if path.matched(paths::ID_RELEASE_REV_REV_ID) => method_not_allowed(), - _ if path.matched(paths::ID_RELEASE_IDENT) => method_not_allowed(), - _ if path.matched(paths::ID_RELEASE_IDENT_FILES) => method_not_allowed(), - _ if path.matched(paths::ID_RELEASE_IDENT_FILESETS) => method_not_allowed(), - _ if path.matched(paths::ID_RELEASE_IDENT_HISTORY) => method_not_allowed(), - _ if path.matched(paths::ID_RELEASE_IDENT_REDIRECTS) => method_not_allowed(), - _ if path.matched(paths::ID_RELEASE_IDENT_WEBCAPTURES) => method_not_allowed(), - _ if path.matched(paths::ID_WEBCAPTURE_EDIT_EDIT_ID) => method_not_allowed(), - _ if path.matched(paths::ID_WEBCAPTURE_REV_REV_ID) => method_not_allowed(), - _ if path.matched(paths::ID_WEBCAPTURE_IDENT) => method_not_allowed(), - _ if path.matched(paths::ID_WEBCAPTURE_IDENT_HISTORY) => method_not_allowed(), - _ if path.matched(paths::ID_WEBCAPTURE_IDENT_REDIRECTS) => method_not_allowed(), - _ if path.matched(paths::ID_WORK_EDIT_EDIT_ID) => method_not_allowed(), - _ if path.matched(paths::ID_WORK_REV_REV_ID) => method_not_allowed(), - _ if path.matched(paths::ID_WORK_IDENT) => method_not_allowed(), - _ if path.matched(paths::ID_WORK_IDENT_HISTORY) => method_not_allowed(), - _ if path.matched(paths::ID_WORK_IDENT_REDIRECTS) => method_not_allowed(), - _ if path.matched(paths::ID_WORK_IDENT_RELEASES) => method_not_allowed(), - _ => Box::new(future::ok( - Response::builder() + _ if path.matched(paths::ID_AUTH_CHECK) => method_not_allowed(), + _ if path.matched(paths::ID_AUTH_OIDC) => method_not_allowed(), + _ if path.matched(paths::ID_AUTH_TOKEN_EDITOR_ID) => method_not_allowed(), + _ if path.matched(paths::ID_CHANGELOG) => method_not_allowed(), + _ if path.matched(paths::ID_CHANGELOG_INDEX) => method_not_allowed(), + _ if path.matched(paths::ID_CONTAINER_EDIT_EDIT_ID) => method_not_allowed(), + _ if path.matched(paths::ID_CONTAINER_LOOKUP) => method_not_allowed(), + _ if path.matched(paths::ID_CONTAINER_REV_REV_ID) => method_not_allowed(), + _ if path.matched(paths::ID_CONTAINER_IDENT) => method_not_allowed(), + _ if path.matched(paths::ID_CONTAINER_IDENT_HISTORY) => method_not_allowed(), + _ if path.matched(paths::ID_CONTAINER_IDENT_REDIRECTS) => method_not_allowed(), + _ if path.matched(paths::ID_CREATOR_EDIT_EDIT_ID) => method_not_allowed(), + _ if path.matched(paths::ID_CREATOR_LOOKUP) => method_not_allowed(), + _ if path.matched(paths::ID_CREATOR_REV_REV_ID) => method_not_allowed(), + _ if path.matched(paths::ID_CREATOR_IDENT) => method_not_allowed(), + _ if path.matched(paths::ID_CREATOR_IDENT_HISTORY) => method_not_allowed(), + _ if path.matched(paths::ID_CREATOR_IDENT_REDIRECTS) => method_not_allowed(), + _ if path.matched(paths::ID_CREATOR_IDENT_RELEASES) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_AUTO_CONTAINER_BATCH) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_AUTO_CREATOR_BATCH) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_AUTO_FILE_BATCH) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_AUTO_FILESET_BATCH) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_AUTO_RELEASE_BATCH) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_AUTO_WEBCAPTURE_BATCH) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_AUTO_WORK_BATCH) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_REVIEWABLE) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ACCEPT) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ANNOTATION) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_ANNOTATIONS) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_EDIT_EDIT_ID) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CONTAINER_IDENT) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_EDIT_EDIT_ID) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_CREATOR_IDENT) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_EDIT_EDIT_ID) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILE_IDENT) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_EDIT_EDIT_ID) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_FILESET_IDENT) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_EDIT_EDIT_ID) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_RELEASE_IDENT) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_EDIT_EDIT_ID) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WEBCAPTURE_IDENT) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK) => method_not_allowed(), + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_EDIT_EDIT_ID) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITGROUP_EDITGROUP_ID_WORK_IDENT) => { + method_not_allowed() + } + _ if path.matched(paths::ID_EDITOR_EDITOR_ID) => method_not_allowed(), + _ if path.matched(paths::ID_EDITOR_EDITOR_ID_ANNOTATIONS) => method_not_allowed(), + _ if path.matched(paths::ID_EDITOR_EDITOR_ID_EDITGROUPS) => method_not_allowed(), + _ if path.matched(paths::ID_FILE_EDIT_EDIT_ID) => method_not_allowed(), + _ if path.matched(paths::ID_FILE_LOOKUP) => method_not_allowed(), + _ if path.matched(paths::ID_FILE_REV_REV_ID) => method_not_allowed(), + _ if path.matched(paths::ID_FILE_IDENT) => method_not_allowed(), + _ if path.matched(paths::ID_FILE_IDENT_HISTORY) => method_not_allowed(), + _ if path.matched(paths::ID_FILE_IDENT_REDIRECTS) => method_not_allowed(), + _ if path.matched(paths::ID_FILESET_EDIT_EDIT_ID) => method_not_allowed(), + _ if path.matched(paths::ID_FILESET_REV_REV_ID) => method_not_allowed(), + _ if path.matched(paths::ID_FILESET_IDENT) => method_not_allowed(), + _ if path.matched(paths::ID_FILESET_IDENT_HISTORY) => method_not_allowed(), + _ if path.matched(paths::ID_FILESET_IDENT_REDIRECTS) => method_not_allowed(), + _ if path.matched(paths::ID_RELEASE_EDIT_EDIT_ID) => method_not_allowed(), + _ if path.matched(paths::ID_RELEASE_LOOKUP) => method_not_allowed(), + _ if path.matched(paths::ID_RELEASE_REV_REV_ID) => method_not_allowed(), + _ if path.matched(paths::ID_RELEASE_IDENT) => method_not_allowed(), + _ if path.matched(paths::ID_RELEASE_IDENT_FILES) => method_not_allowed(), + _ if path.matched(paths::ID_RELEASE_IDENT_FILESETS) => method_not_allowed(), + _ if path.matched(paths::ID_RELEASE_IDENT_HISTORY) => method_not_allowed(), + _ if path.matched(paths::ID_RELEASE_IDENT_REDIRECTS) => method_not_allowed(), + _ if path.matched(paths::ID_RELEASE_IDENT_WEBCAPTURES) => method_not_allowed(), + _ if path.matched(paths::ID_WEBCAPTURE_EDIT_EDIT_ID) => method_not_allowed(), + _ if path.matched(paths::ID_WEBCAPTURE_REV_REV_ID) => method_not_allowed(), + _ if path.matched(paths::ID_WEBCAPTURE_IDENT) => method_not_allowed(), + _ if path.matched(paths::ID_WEBCAPTURE_IDENT_HISTORY) => method_not_allowed(), + _ if path.matched(paths::ID_WEBCAPTURE_IDENT_REDIRECTS) => method_not_allowed(), + _ if path.matched(paths::ID_WORK_EDIT_EDIT_ID) => method_not_allowed(), + _ if path.matched(paths::ID_WORK_REV_REV_ID) => method_not_allowed(), + _ if path.matched(paths::ID_WORK_IDENT) => method_not_allowed(), + _ if path.matched(paths::ID_WORK_IDENT_HISTORY) => method_not_allowed(), + _ if path.matched(paths::ID_WORK_IDENT_REDIRECTS) => method_not_allowed(), + _ if path.matched(paths::ID_WORK_IDENT_RELEASES) => method_not_allowed(), + _ => Ok(Response::builder() .status(StatusCode::NOT_FOUND) .body(Body::empty()) - .expect("Unable to create Not Found response"), - )) as Self::Future, - } - } -} - -impl<T, C> Clone for Service<T, C> -where - T: Clone, -{ - fn clone(&self) -> Self { - Service { - api_impl: self.api_impl.clone(), - marker: self.marker.clone(), + .expect("Unable to create Not Found response")), + } } + Box::pin(run(self.api_impl.clone(), req)) } } |