From 4c78ac850862e818a308222689d1dc6857063066 Mon Sep 17 00:00:00 2001 From: winrid Date: Tue, 4 Nov 2025 09:24:06 -0800 Subject: [PATCH 1/2] [Rust Reqwest] Fixes Enums in Query Parameters via Causing Compilation Failure --- .../rust-reqwest-enum-query-params.yaml | 8 ++ .../main/resources/rust/reqwest/api.mustache | 19 +++ .../resources/3_0/rust/enum-query-params.yaml | 123 ++++++++++++++++++ samples/client/others/rust/Cargo.lock | 11 ++ .../rust/reqwest/enum-query-params/.gitignore | 3 + .../.openapi-generator-ignore | 23 ++++ .../.openapi-generator/FILES | 24 ++++ .../.openapi-generator/VERSION | 1 + .../reqwest/enum-query-params/.travis.yml | 1 + .../rust/reqwest/enum-query-params/Cargo.toml | 20 +++ .../rust/reqwest/enum-query-params/README.md | 52 ++++++++ .../docs/AggregateResponse.md | 12 ++ .../enum-query-params/docs/DefaultApi.md | 71 ++++++++++ .../reqwest/enum-query-params/docs/Item.md | 13 ++ .../enum-query-params/docs/Priority.md | 15 +++ .../enum-query-params/docs/SortDirection.md | 13 ++ .../reqwest/enum-query-params/docs/Status.md | 15 +++ .../enum-query-params/docs/TimeBucket.md | 16 +++ .../reqwest/enum-query-params/git_push.sh | 57 ++++++++ .../src/apis/configuration.rs | 51 ++++++++ .../enum-query-params/src/apis/default_api.rs | 122 +++++++++++++++++ .../reqwest/enum-query-params/src/apis/mod.rs | 116 +++++++++++++++++ .../rust/reqwest/enum-query-params/src/lib.rs | 11 ++ .../src/models/aggregate_response.rs | 30 +++++ .../enum-query-params/src/models/item.rs | 33 +++++ .../enum-query-params/src/models/mod.rs | 12 ++ .../enum-query-params/src/models/priority.rs | 45 +++++++ .../src/models/sort_direction.rs | 39 ++++++ .../enum-query-params/src/models/status.rs | 45 +++++++ .../src/models/time_bucket.rs | 48 +++++++ 30 files changed, 1049 insertions(+) create mode 100644 bin/configs/rust-reqwest-enum-query-params.yaml create mode 100644 modules/openapi-generator/src/test/resources/3_0/rust/enum-query-params.yaml create mode 100644 samples/client/others/rust/reqwest/enum-query-params/.gitignore create mode 100644 samples/client/others/rust/reqwest/enum-query-params/.openapi-generator-ignore create mode 100644 samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/FILES create mode 100644 samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/VERSION create mode 100644 samples/client/others/rust/reqwest/enum-query-params/.travis.yml create mode 100644 samples/client/others/rust/reqwest/enum-query-params/Cargo.toml create mode 100644 samples/client/others/rust/reqwest/enum-query-params/README.md create mode 100644 samples/client/others/rust/reqwest/enum-query-params/docs/AggregateResponse.md create mode 100644 samples/client/others/rust/reqwest/enum-query-params/docs/DefaultApi.md create mode 100644 samples/client/others/rust/reqwest/enum-query-params/docs/Item.md create mode 100644 samples/client/others/rust/reqwest/enum-query-params/docs/Priority.md create mode 100644 samples/client/others/rust/reqwest/enum-query-params/docs/SortDirection.md create mode 100644 samples/client/others/rust/reqwest/enum-query-params/docs/Status.md create mode 100644 samples/client/others/rust/reqwest/enum-query-params/docs/TimeBucket.md create mode 100644 samples/client/others/rust/reqwest/enum-query-params/git_push.sh create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/apis/configuration.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/apis/default_api.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/apis/mod.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/lib.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/models/aggregate_response.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/models/item.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/models/mod.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/models/priority.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/models/sort_direction.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/models/status.rs create mode 100644 samples/client/others/rust/reqwest/enum-query-params/src/models/time_bucket.rs diff --git a/bin/configs/rust-reqwest-enum-query-params.yaml b/bin/configs/rust-reqwest-enum-query-params.yaml new file mode 100644 index 000000000000..db7adb03233f --- /dev/null +++ b/bin/configs/rust-reqwest-enum-query-params.yaml @@ -0,0 +1,8 @@ +generatorName: rust +outputDir: samples/client/others/rust/reqwest/enum-query-params +library: reqwest +inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/enum-query-params.yaml +templateDir: modules/openapi-generator/src/main/resources/rust +additionalProperties: + supportAsync: true + packageName: enum-query-params-reqwest diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index 60337d143ef0..29b84ed1bb6f 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -203,9 +203,18 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{/isDeepObject}} {{^isObject}} {{^isModel}} + {{^isEnum}} + {{#isPrimitiveType}} if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]); }; + {{/isPrimitiveType}} + {{^isPrimitiveType}} + if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { + req_builder = req_builder.query(&[("{{{baseName}}}", &serde_json::to_string(param_value)?)]); + }; + {{/isPrimitiveType}} + {{/isEnum}} {{/isModel}} {{/isObject}} {{/isNullable}} @@ -245,9 +254,19 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{#isModel}} req_builder = req_builder.query(&[("{{{baseName}}}", &serde_json::to_string(param_value)?)]); {{/isModel}} + {{#isEnum}} + req_builder = req_builder.query(&[("{{{baseName}}}", &serde_json::to_string(param_value)?)]); + {{/isEnum}} {{^isObject}} {{^isModel}} + {{^isEnum}} + {{#isPrimitiveType}} req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]); + {{/isPrimitiveType}} + {{^isPrimitiveType}} + req_builder = req_builder.query(&[("{{{baseName}}}", &serde_json::to_string(param_value)?)]); + {{/isPrimitiveType}} + {{/isEnum}} {{/isModel}} {{/isObject}} {{/isDeepObject}} diff --git a/modules/openapi-generator/src/test/resources/3_0/rust/enum-query-params.yaml b/modules/openapi-generator/src/test/resources/3_0/rust/enum-query-params.yaml new file mode 100644 index 000000000000..99a200a8e7ab --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/rust/enum-query-params.yaml @@ -0,0 +1,123 @@ +openapi: 3.0.3 +info: + title: Enum Query Parameter Test + description: Test spec for enum and non-primitive query parameters + version: 1.0.0 +paths: + /aggregate: + get: + operationId: getAggregateData + summary: Get aggregated data + description: Test endpoint with enum query parameters referenced via $ref + parameters: + - name: timeBucket + in: query + description: Time aggregation bucket + required: false + schema: + $ref: '#/components/schemas/TimeBucket' + - name: sortDirection + in: query + description: Sort direction + required: false + schema: + $ref: '#/components/schemas/SortDirection' + - name: status + in: query + description: Status filter + required: true + schema: + $ref: '#/components/schemas/Status' + responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/AggregateResponse' + '400': + description: Bad request + /items: + get: + operationId: getItems + summary: Get items with filters + parameters: + - name: category + in: query + description: Item category (inline enum) + required: false + schema: + type: string + enum: + - electronics + - clothing + - food + - name: priority + in: query + description: Priority level (enum via ref) + required: false + schema: + $ref: '#/components/schemas/Priority' + responses: + '200': + description: Successful response + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Item' +components: + schemas: + TimeBucket: + type: string + description: Time aggregation bucket options + enum: + - hour + - day + - week + - month + - year + SortDirection: + type: string + description: Sort direction options + enum: + - asc + - desc + default: asc + Status: + type: string + description: Status filter options + enum: + - active + - inactive + - pending + - completed + Priority: + type: string + description: Priority level + enum: + - low + - medium + - high + - critical + AggregateResponse: + type: object + properties: + count: + type: integer + format: int64 + data: + type: array + items: + type: object + additionalProperties: true + Item: + type: object + properties: + id: + type: string + name: + type: string + category: + type: string diff --git a/samples/client/others/rust/Cargo.lock b/samples/client/others/rust/Cargo.lock index 53d5d67000bd..5c3649805991 100644 --- a/samples/client/others/rust/Cargo.lock +++ b/samples/client/others/rust/Cargo.lock @@ -193,6 +193,17 @@ dependencies = [ "url", ] +[[package]] +name = "enum-query-params-reqwest" +version = "1.0.0" +dependencies = [ + "reqwest", + "serde", + "serde_json", + "serde_repr", + "url", +] + [[package]] name = "equivalent" version = "1.0.1" diff --git a/samples/client/others/rust/reqwest/enum-query-params/.gitignore b/samples/client/others/rust/reqwest/enum-query-params/.gitignore new file mode 100644 index 000000000000..6aa106405a4b --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/.gitignore @@ -0,0 +1,3 @@ +/target/ +**/*.rs.bk +Cargo.lock diff --git a/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator-ignore b/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/FILES b/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/FILES new file mode 100644 index 000000000000..54f39172dfc7 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/FILES @@ -0,0 +1,24 @@ +.gitignore +.openapi-generator-ignore +.travis.yml +Cargo.toml +README.md +docs/AggregateResponse.md +docs/DefaultApi.md +docs/Item.md +docs/Priority.md +docs/SortDirection.md +docs/Status.md +docs/TimeBucket.md +git_push.sh +src/apis/configuration.rs +src/apis/default_api.rs +src/apis/mod.rs +src/lib.rs +src/models/aggregate_response.rs +src/models/item.rs +src/models/mod.rs +src/models/priority.rs +src/models/sort_direction.rs +src/models/status.rs +src/models/time_bucket.rs diff --git a/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/VERSION b/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/VERSION new file mode 100644 index 000000000000..2fb556b60635 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.18.0-SNAPSHOT diff --git a/samples/client/others/rust/reqwest/enum-query-params/.travis.yml b/samples/client/others/rust/reqwest/enum-query-params/.travis.yml new file mode 100644 index 000000000000..22761ba7ee19 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/samples/client/others/rust/reqwest/enum-query-params/Cargo.toml b/samples/client/others/rust/reqwest/enum-query-params/Cargo.toml new file mode 100644 index 000000000000..208987355122 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "enum-query-params-reqwest" +version = "1.0.0" +authors = ["OpenAPI Generator team and contributors"] +description = "Test spec for enum and non-primitive query parameters" +# Override this license by providing a License Object in the OpenAPI. +license = "Unlicense" +edition = "2021" + +[dependencies] +serde = { version = "^1.0", features = ["derive"] } +serde_json = "^1.0" +serde_repr = "^0.1" +url = "^2.5" +reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] } + +[features] +default = ["native-tls"] +native-tls = ["reqwest/native-tls"] +rustls-tls = ["reqwest/rustls-tls"] diff --git a/samples/client/others/rust/reqwest/enum-query-params/README.md b/samples/client/others/rust/reqwest/enum-query-params/README.md new file mode 100644 index 000000000000..d09199cc3b57 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/README.md @@ -0,0 +1,52 @@ +# Rust API client for enum-query-params-reqwest + +Test spec for enum and non-primitive query parameters + + +## Overview + +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: 1.0.0 +- Generator version: 7.18.0-SNAPSHOT +- Build package: `org.openapitools.codegen.languages.RustClientCodegen` + +## Installation + +Put the package under your project folder in a directory named `enum-query-params-reqwest` and add the following to `Cargo.toml` under `[dependencies]`: + +``` +enum-query-params-reqwest = { path = "./enum-query-params-reqwest" } +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**get_aggregate_data**](docs/DefaultApi.md#get_aggregate_data) | **GET** /aggregate | Get aggregated data +*DefaultApi* | [**get_items**](docs/DefaultApi.md#get_items) | **GET** /items | Get items with filters + + +## Documentation For Models + + - [AggregateResponse](docs/AggregateResponse.md) + - [Item](docs/Item.md) + - [Priority](docs/Priority.md) + - [SortDirection](docs/SortDirection.md) + - [Status](docs/Status.md) + - [TimeBucket](docs/TimeBucket.md) + + +To get access to the crate's generated documentation, use: + +``` +cargo doc --open +``` + +## Author + + + diff --git a/samples/client/others/rust/reqwest/enum-query-params/docs/AggregateResponse.md b/samples/client/others/rust/reqwest/enum-query-params/docs/AggregateResponse.md new file mode 100644 index 000000000000..16e7ca603059 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/docs/AggregateResponse.md @@ -0,0 +1,12 @@ +# AggregateResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**count** | Option<**i64**> | | [optional] +**data** | Option<[**Vec>**](std::collections::HashMap.md)> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/enum-query-params/docs/DefaultApi.md b/samples/client/others/rust/reqwest/enum-query-params/docs/DefaultApi.md new file mode 100644 index 000000000000..22b7e090107a --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/docs/DefaultApi.md @@ -0,0 +1,71 @@ +# \DefaultApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**get_aggregate_data**](DefaultApi.md#get_aggregate_data) | **GET** /aggregate | Get aggregated data +[**get_items**](DefaultApi.md#get_items) | **GET** /items | Get items with filters + + + +## get_aggregate_data + +> models::AggregateResponse get_aggregate_data(status, time_bucket, sort_direction) +Get aggregated data + +Test endpoint with enum query parameters referenced via $ref + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**status** | [**Status**](.md) | Status filter | [required] | +**time_bucket** | Option<[**TimeBucket**](.md)> | Time aggregation bucket | | +**sort_direction** | Option<[**SortDirection**](.md)> | Sort direction | | + +### Return type + +[**models::AggregateResponse**](AggregateResponse.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **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) + + +## get_items + +> Vec get_items(category, priority) +Get items with filters + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**category** | Option<**String**> | Item category (inline enum) | | +**priority** | Option<[**Priority**](.md)> | Priority level (enum via ref) | | + +### Return type + +[**Vec**](Item.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **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/samples/client/others/rust/reqwest/enum-query-params/docs/Item.md b/samples/client/others/rust/reqwest/enum-query-params/docs/Item.md new file mode 100644 index 000000000000..828518a30b4e --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/docs/Item.md @@ -0,0 +1,13 @@ +# Item + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | Option<**String**> | | [optional] +**name** | Option<**String**> | | [optional] +**category** | Option<**String**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/enum-query-params/docs/Priority.md b/samples/client/others/rust/reqwest/enum-query-params/docs/Priority.md new file mode 100644 index 000000000000..ff7d650804a4 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/docs/Priority.md @@ -0,0 +1,15 @@ +# Priority + +## Enum Variants + +| Name | Value | +|---- | -----| +| Low | low | +| Medium | medium | +| High | high | +| Critical | critical | + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/enum-query-params/docs/SortDirection.md b/samples/client/others/rust/reqwest/enum-query-params/docs/SortDirection.md new file mode 100644 index 000000000000..a889d395b025 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/docs/SortDirection.md @@ -0,0 +1,13 @@ +# SortDirection + +## Enum Variants + +| Name | Value | +|---- | -----| +| Asc | asc | +| Desc | desc | + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/enum-query-params/docs/Status.md b/samples/client/others/rust/reqwest/enum-query-params/docs/Status.md new file mode 100644 index 000000000000..2d48a7522933 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/docs/Status.md @@ -0,0 +1,15 @@ +# Status + +## Enum Variants + +| Name | Value | +|---- | -----| +| Active | active | +| Inactive | inactive | +| Pending | pending | +| Completed | completed | + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/enum-query-params/docs/TimeBucket.md b/samples/client/others/rust/reqwest/enum-query-params/docs/TimeBucket.md new file mode 100644 index 000000000000..166382990395 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/docs/TimeBucket.md @@ -0,0 +1,16 @@ +# TimeBucket + +## Enum Variants + +| Name | Value | +|---- | -----| +| Hour | hour | +| Day | day | +| Week | week | +| Month | month | +| Year | year | + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/enum-query-params/git_push.sh b/samples/client/others/rust/reqwest/enum-query-params/git_push.sh new file mode 100644 index 000000000000..f53a75d4fabe --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/git_push.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=$(git remote) +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/apis/configuration.rs b/samples/client/others/rust/reqwest/enum-query-params/src/apis/configuration.rs new file mode 100644 index 000000000000..07a25a3e5d33 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/apis/configuration.rs @@ -0,0 +1,51 @@ +/* + * Enum Query Parameter Test + * + * Test spec for enum and non-primitive query parameters + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + + +#[derive(Debug, Clone)] +pub struct Configuration { + pub base_path: String, + pub user_agent: Option, + pub client: reqwest::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub bearer_access_token: Option, + pub api_key: Option, +} + +pub type BasicAuth = (String, Option); + +#[derive(Debug, Clone)] +pub struct ApiKey { + pub prefix: Option, + pub key: String, +} + + +impl Configuration { + pub fn new() -> Configuration { + Configuration::default() + } +} + +impl Default for Configuration { + fn default() -> Self { + Configuration { + base_path: "http://localhost".to_owned(), + user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()), + client: reqwest::Client::new(), + basic_auth: None, + oauth_access_token: None, + bearer_access_token: None, + api_key: None, + } + } +} diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/apis/default_api.rs b/samples/client/others/rust/reqwest/enum-query-params/src/apis/default_api.rs new file mode 100644 index 000000000000..a342b2503e8e --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/apis/default_api.rs @@ -0,0 +1,122 @@ +/* + * Enum Query Parameter Test + * + * Test spec for enum and non-primitive query parameters + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + +use reqwest; +use serde::{Deserialize, Serialize, de::Error as _}; +use crate::{apis::ResponseContent, models}; +use super::{Error, configuration, ContentType}; + + +/// struct for typed errors of method [`get_aggregate_data`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetAggregateDataError { + Status400(), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`get_items`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetItemsError { + UnknownValue(serde_json::Value), +} + + +/// Test endpoint with enum query parameters referenced via $ref +pub async fn get_aggregate_data(configuration: &configuration::Configuration, status: models::Status, time_bucket: Option, sort_direction: Option) -> Result> { + // add a prefix to parameters to efficiently prevent name collisions + let p_query_status = status; + let p_query_time_bucket = time_bucket; + let p_query_sort_direction = sort_direction; + + let uri_str = format!("{}/aggregate", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); + + if let Some(ref param_value) = p_query_time_bucket { + req_builder = req_builder.query(&[("timeBucket", &serde_json::to_string(param_value)?)]); + } + if let Some(ref param_value) = p_query_sort_direction { + req_builder = req_builder.query(&[("sortDirection", &serde_json::to_string(param_value)?)]); + } + req_builder = req_builder.query(&[("status", &p_query_status.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); + } + + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; + + let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); + + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AggregateResponse`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AggregateResponse`")))), + } + } else { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + +pub async fn get_items(configuration: &configuration::Configuration, category: Option<&str>, priority: Option) -> Result, Error> { + // add a prefix to parameters to efficiently prevent name collisions + let p_query_category = category; + let p_query_priority = priority; + + let uri_str = format!("{}/items", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); + + if let Some(ref param_value) = p_query_category { + req_builder = req_builder.query(&[("category", &serde_json::to_string(param_value)?)]); + } + if let Some(ref param_value) = p_query_priority { + req_builder = req_builder.query(&[("priority", &serde_json::to_string(param_value)?)]); + } + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); + } + + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; + + let status = resp.status(); + let content_type = resp + .headers() + .get("content-type") + .and_then(|v| v.to_str().ok()) + .unwrap_or("application/octet-stream"); + let content_type = super::ContentType::from(content_type); + + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + match content_type { + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Item>`"))), + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Item>`")))), + } + } else { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/apis/mod.rs b/samples/client/others/rust/reqwest/enum-query-params/src/apis/mod.rs new file mode 100644 index 000000000000..fdcc89b36066 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/apis/mod.rs @@ -0,0 +1,116 @@ +use std::error; +use std::fmt; + +#[derive(Debug, Clone)] +pub struct ResponseContent { + pub status: reqwest::StatusCode, + pub content: String, + pub entity: Option, +} + +#[derive(Debug)] +pub enum Error { + Reqwest(reqwest::Error), + Serde(serde_json::Error), + Io(std::io::Error), + ResponseError(ResponseContent), +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let (module, e) = match self { + Error::Reqwest(e) => ("reqwest", e.to_string()), + Error::Serde(e) => ("serde", e.to_string()), + Error::Io(e) => ("IO", e.to_string()), + Error::ResponseError(e) => ("response", format!("status code {}", e.status)), + }; + write!(f, "error in {}: {}", module, e) + } +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + Some(match self { + Error::Reqwest(e) => e, + Error::Serde(e) => e, + Error::Io(e) => e, + Error::ResponseError(_) => return None, + }) + } +} + +impl From for Error { + fn from(e: reqwest::Error) -> Self { + Error::Reqwest(e) + } +} + +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Serde(e) + } +} + +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) + } +} + +pub fn urlencode>(s: T) -> String { + ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() +} + +pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { + if let serde_json::Value::Object(object) = value { + let mut params = vec![]; + + for (key, value) in object { + match value { + serde_json::Value::Object(_) => params.append(&mut parse_deep_object( + &format!("{}[{}]", prefix, key), + value, + )), + serde_json::Value::Array(array) => { + for (i, value) in array.iter().enumerate() { + params.append(&mut parse_deep_object( + &format!("{}[{}][{}]", prefix, key, i), + value, + )); + } + }, + serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), + _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), + } + } + + return params; + } + + unimplemented!("Only objects are supported with style=deepObject") +} + +/// Internal use only +/// A content type supported by this client. +#[allow(dead_code)] +enum ContentType { + Json, + Text, + Unsupported(String) +} + +impl From<&str> for ContentType { + fn from(content_type: &str) -> Self { + if content_type.starts_with("application") && content_type.contains("json") { + return Self::Json; + } else if content_type.starts_with("text/plain") { + return Self::Text; + } else { + return Self::Unsupported(content_type.to_string()); + } + } +} + +pub mod default_api; + +pub mod configuration; diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/lib.rs b/samples/client/others/rust/reqwest/enum-query-params/src/lib.rs new file mode 100644 index 000000000000..e1520628d762 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/lib.rs @@ -0,0 +1,11 @@ +#![allow(unused_imports)] +#![allow(clippy::too_many_arguments)] + +extern crate serde_repr; +extern crate serde; +extern crate serde_json; +extern crate url; +extern crate reqwest; + +pub mod apis; +pub mod models; diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/models/aggregate_response.rs b/samples/client/others/rust/reqwest/enum-query-params/src/models/aggregate_response.rs new file mode 100644 index 000000000000..c0173271ee74 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/models/aggregate_response.rs @@ -0,0 +1,30 @@ +/* + * Enum Query Parameter Test + * + * Test spec for enum and non-primitive query parameters + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct AggregateResponse { + #[serde(rename = "count", skip_serializing_if = "Option::is_none")] + pub count: Option, + #[serde(rename = "data", skip_serializing_if = "Option::is_none")] + pub data: Option>>, +} + +impl AggregateResponse { + pub fn new() -> AggregateResponse { + AggregateResponse { + count: None, + data: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/models/item.rs b/samples/client/others/rust/reqwest/enum-query-params/src/models/item.rs new file mode 100644 index 000000000000..02982744bd78 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/models/item.rs @@ -0,0 +1,33 @@ +/* + * Enum Query Parameter Test + * + * Test spec for enum and non-primitive query parameters + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Item { + #[serde(rename = "id", skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "category", skip_serializing_if = "Option::is_none")] + pub category: Option, +} + +impl Item { + pub fn new() -> Item { + Item { + id: None, + name: None, + category: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/models/mod.rs b/samples/client/others/rust/reqwest/enum-query-params/src/models/mod.rs new file mode 100644 index 000000000000..507258ab8f15 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/models/mod.rs @@ -0,0 +1,12 @@ +pub mod aggregate_response; +pub use self::aggregate_response::AggregateResponse; +pub mod item; +pub use self::item::Item; +pub mod priority; +pub use self::priority::Priority; +pub mod sort_direction; +pub use self::sort_direction::SortDirection; +pub mod status; +pub use self::status::Status; +pub mod time_bucket; +pub use self::time_bucket::TimeBucket; diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/models/priority.rs b/samples/client/others/rust/reqwest/enum-query-params/src/models/priority.rs new file mode 100644 index 000000000000..476152a0220b --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/models/priority.rs @@ -0,0 +1,45 @@ +/* + * Enum Query Parameter Test + * + * Test spec for enum and non-primitive query parameters + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +/// Priority : Priority level +/// Priority level +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum Priority { + #[serde(rename = "low")] + Low, + #[serde(rename = "medium")] + Medium, + #[serde(rename = "high")] + High, + #[serde(rename = "critical")] + Critical, + +} + +impl std::fmt::Display for Priority { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::Low => write!(f, "low"), + Self::Medium => write!(f, "medium"), + Self::High => write!(f, "high"), + Self::Critical => write!(f, "critical"), + } + } +} + +impl Default for Priority { + fn default() -> Priority { + Self::Low + } +} + diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/models/sort_direction.rs b/samples/client/others/rust/reqwest/enum-query-params/src/models/sort_direction.rs new file mode 100644 index 000000000000..087d7628ea13 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/models/sort_direction.rs @@ -0,0 +1,39 @@ +/* + * Enum Query Parameter Test + * + * Test spec for enum and non-primitive query parameters + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +/// SortDirection : Sort direction options +/// Sort direction options +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum SortDirection { + #[serde(rename = "asc")] + Asc, + #[serde(rename = "desc")] + Desc, + +} + +impl std::fmt::Display for SortDirection { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::Asc => write!(f, "asc"), + Self::Desc => write!(f, "desc"), + } + } +} + +impl Default for SortDirection { + fn default() -> SortDirection { + Self::Asc + } +} + diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/models/status.rs b/samples/client/others/rust/reqwest/enum-query-params/src/models/status.rs new file mode 100644 index 000000000000..a68cea6c6dc4 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/models/status.rs @@ -0,0 +1,45 @@ +/* + * Enum Query Parameter Test + * + * Test spec for enum and non-primitive query parameters + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +/// Status : Status filter options +/// Status filter options +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum Status { + #[serde(rename = "active")] + Active, + #[serde(rename = "inactive")] + Inactive, + #[serde(rename = "pending")] + Pending, + #[serde(rename = "completed")] + Completed, + +} + +impl std::fmt::Display for Status { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::Active => write!(f, "active"), + Self::Inactive => write!(f, "inactive"), + Self::Pending => write!(f, "pending"), + Self::Completed => write!(f, "completed"), + } + } +} + +impl Default for Status { + fn default() -> Status { + Self::Active + } +} + diff --git a/samples/client/others/rust/reqwest/enum-query-params/src/models/time_bucket.rs b/samples/client/others/rust/reqwest/enum-query-params/src/models/time_bucket.rs new file mode 100644 index 000000000000..e1dd4ef87434 --- /dev/null +++ b/samples/client/others/rust/reqwest/enum-query-params/src/models/time_bucket.rs @@ -0,0 +1,48 @@ +/* + * Enum Query Parameter Test + * + * Test spec for enum and non-primitive query parameters + * + * The version of the OpenAPI document: 1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +/// TimeBucket : Time aggregation bucket options +/// Time aggregation bucket options +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum TimeBucket { + #[serde(rename = "hour")] + Hour, + #[serde(rename = "day")] + Day, + #[serde(rename = "week")] + Week, + #[serde(rename = "month")] + Month, + #[serde(rename = "year")] + Year, + +} + +impl std::fmt::Display for TimeBucket { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::Hour => write!(f, "hour"), + Self::Day => write!(f, "day"), + Self::Week => write!(f, "week"), + Self::Month => write!(f, "month"), + Self::Year => write!(f, "year"), + } + } +} + +impl Default for TimeBucket { + fn default() -> TimeBucket { + Self::Hour + } +} + From e6776e438087af36b0e654ba310632bda35dc2a0 Mon Sep 17 00:00:00 2001 From: winrid Date: Tue, 4 Nov 2025 09:42:44 -0800 Subject: [PATCH 2/2] regen --- .../rust/reqwest/enum-query-params/.openapi-generator/FILES | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/FILES b/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/FILES index 54f39172dfc7..1d2a707dcb81 100644 --- a/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/FILES +++ b/samples/client/others/rust/reqwest/enum-query-params/.openapi-generator/FILES @@ -1,5 +1,4 @@ .gitignore -.openapi-generator-ignore .travis.yml Cargo.toml README.md