Skip to content

Commit 2107686

Browse files
authored
[Rust Reqwest] Fixes Enums in Query Parameters via Causing Compilation Failure (#22281)
* [Rust Reqwest] Fixes Enums in Query Parameters via Causing Compilation Failure * regen
1 parent 7486f12 commit 2107686

File tree

30 files changed

+1048
-0
lines changed

30 files changed

+1048
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: rust
2+
outputDir: samples/client/others/rust/reqwest/enum-query-params
3+
library: reqwest
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/enum-query-params.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/rust
6+
additionalProperties:
7+
supportAsync: true
8+
packageName: enum-query-params-reqwest

modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,18 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
203203
{{/isDeepObject}}
204204
{{^isObject}}
205205
{{^isModel}}
206+
{{^isEnum}}
207+
{{#isPrimitiveType}}
206208
if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} {
207209
req_builder = req_builder.query(&[("{{{baseName}}}", &param_value.to_string())]);
208210
};
211+
{{/isPrimitiveType}}
212+
{{^isPrimitiveType}}
213+
if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} {
214+
req_builder = req_builder.query(&[("{{{baseName}}}", &serde_json::to_string(param_value)?)]);
215+
};
216+
{{/isPrimitiveType}}
217+
{{/isEnum}}
209218
{{/isModel}}
210219
{{/isObject}}
211220
{{/isNullable}}
@@ -245,9 +254,19 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
245254
{{#isModel}}
246255
req_builder = req_builder.query(&[("{{{baseName}}}", &serde_json::to_string(param_value)?)]);
247256
{{/isModel}}
257+
{{#isEnum}}
258+
req_builder = req_builder.query(&[("{{{baseName}}}", &serde_json::to_string(param_value)?)]);
259+
{{/isEnum}}
248260
{{^isObject}}
249261
{{^isModel}}
262+
{{^isEnum}}
263+
{{#isPrimitiveType}}
250264
req_builder = req_builder.query(&[("{{{baseName}}}", &param_value.to_string())]);
265+
{{/isPrimitiveType}}
266+
{{^isPrimitiveType}}
267+
req_builder = req_builder.query(&[("{{{baseName}}}", &serde_json::to_string(param_value)?)]);
268+
{{/isPrimitiveType}}
269+
{{/isEnum}}
251270
{{/isModel}}
252271
{{/isObject}}
253272
{{/isDeepObject}}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Enum Query Parameter Test
4+
description: Test spec for enum and non-primitive query parameters
5+
version: 1.0.0
6+
paths:
7+
/aggregate:
8+
get:
9+
operationId: getAggregateData
10+
summary: Get aggregated data
11+
description: Test endpoint with enum query parameters referenced via $ref
12+
parameters:
13+
- name: timeBucket
14+
in: query
15+
description: Time aggregation bucket
16+
required: false
17+
schema:
18+
$ref: '#/components/schemas/TimeBucket'
19+
- name: sortDirection
20+
in: query
21+
description: Sort direction
22+
required: false
23+
schema:
24+
$ref: '#/components/schemas/SortDirection'
25+
- name: status
26+
in: query
27+
description: Status filter
28+
required: true
29+
schema:
30+
$ref: '#/components/schemas/Status'
31+
responses:
32+
'200':
33+
description: Successful response
34+
content:
35+
application/json:
36+
schema:
37+
$ref: '#/components/schemas/AggregateResponse'
38+
'400':
39+
description: Bad request
40+
/items:
41+
get:
42+
operationId: getItems
43+
summary: Get items with filters
44+
parameters:
45+
- name: category
46+
in: query
47+
description: Item category (inline enum)
48+
required: false
49+
schema:
50+
type: string
51+
enum:
52+
- electronics
53+
- clothing
54+
- food
55+
- name: priority
56+
in: query
57+
description: Priority level (enum via ref)
58+
required: false
59+
schema:
60+
$ref: '#/components/schemas/Priority'
61+
responses:
62+
'200':
63+
description: Successful response
64+
content:
65+
application/json:
66+
schema:
67+
type: array
68+
items:
69+
$ref: '#/components/schemas/Item'
70+
components:
71+
schemas:
72+
TimeBucket:
73+
type: string
74+
description: Time aggregation bucket options
75+
enum:
76+
- hour
77+
- day
78+
- week
79+
- month
80+
- year
81+
SortDirection:
82+
type: string
83+
description: Sort direction options
84+
enum:
85+
- asc
86+
- desc
87+
default: asc
88+
Status:
89+
type: string
90+
description: Status filter options
91+
enum:
92+
- active
93+
- inactive
94+
- pending
95+
- completed
96+
Priority:
97+
type: string
98+
description: Priority level
99+
enum:
100+
- low
101+
- medium
102+
- high
103+
- critical
104+
AggregateResponse:
105+
type: object
106+
properties:
107+
count:
108+
type: integer
109+
format: int64
110+
data:
111+
type: array
112+
items:
113+
type: object
114+
additionalProperties: true
115+
Item:
116+
type: object
117+
properties:
118+
id:
119+
type: string
120+
name:
121+
type: string
122+
category:
123+
type: string

samples/client/others/rust/Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target/
2+
**/*.rs.bk
3+
Cargo.lock
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.gitignore
2+
.travis.yml
3+
Cargo.toml
4+
README.md
5+
docs/AggregateResponse.md
6+
docs/DefaultApi.md
7+
docs/Item.md
8+
docs/Priority.md
9+
docs/SortDirection.md
10+
docs/Status.md
11+
docs/TimeBucket.md
12+
git_push.sh
13+
src/apis/configuration.rs
14+
src/apis/default_api.rs
15+
src/apis/mod.rs
16+
src/lib.rs
17+
src/models/aggregate_response.rs
18+
src/models/item.rs
19+
src/models/mod.rs
20+
src/models/priority.rs
21+
src/models/sort_direction.rs
22+
src/models/status.rs
23+
src/models/time_bucket.rs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.18.0-SNAPSHOT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: rust
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "enum-query-params-reqwest"
3+
version = "1.0.0"
4+
authors = ["OpenAPI Generator team and contributors"]
5+
description = "Test spec for enum and non-primitive query parameters"
6+
# Override this license by providing a License Object in the OpenAPI.
7+
license = "Unlicense"
8+
edition = "2021"
9+
10+
[dependencies]
11+
serde = { version = "^1.0", features = ["derive"] }
12+
serde_json = "^1.0"
13+
serde_repr = "^0.1"
14+
url = "^2.5"
15+
reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] }
16+
17+
[features]
18+
default = ["native-tls"]
19+
native-tls = ["reqwest/native-tls"]
20+
rustls-tls = ["reqwest/rustls-tls"]

0 commit comments

Comments
 (0)