Skip to content

Commit 56dd635

Browse files
authored
[Rust-Axum] Allow use of array query params (#20861)
* [Rust-Axum] Allow use of array query params * Add sample per PR request
1 parent 3b0bb0a commit 56dd635

File tree

65 files changed

+1484
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1484
-87
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
generatorName: rust-axum
2+
outputDir: samples/server/petstore/rust-axum/output/rust-axum-array-params-test
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/rust-axum-array-params-test.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-axum
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: rust-axum-array-params-test
9+
globalProperties:
10+
skipFormModel: false
11+
enablePostProcessFile: true

modules/openapi-generator/src/main/resources/rust-axum/Cargo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ conversion = [
4141
[dependencies]
4242
async-trait = "0.1"
4343
axum = { version = "0.8", features = ["multipart"] }
44-
axum-extra = { version = "0.10", features = ["cookie"] }
44+
axum-extra = { version = "0.10", features = ["cookie", "query"] }
4545
base64 = "0.22"
4646
bytes = "1"
4747
chrono = { version = "0.4", features = ["serde"] }
@@ -54,8 +54,8 @@ http = "1"
5454
lazy_static = "1"
5555
regex = "1"
5656
serde = { version = "1", features = ["derive"] }
57+
serde_html_form = "0.2"
5758
serde_json = { version = "1", features = ["raw_value"] }
58-
serde_urlencoded = "0.7"
5959
tokio = { version = "1", default-features = false, features = [
6060
"signal",
6161
"rt-multi-thread",

modules/openapi-generator/src/main/resources/rust-axum/models.mustache

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ use crate::{models, types::*};
207207
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
208208
pub struct {{{operationIdCamelCase}}}QueryParams {
209209
{{#queryParams}}
210-
{{#vendorExtensions}}
211210
{{#description}}
212211
/// {{{.}}}
213212
{{/description}}
@@ -266,6 +265,16 @@ use crate::{models, types::*};
266265
{{/maxItems}}
267266
)]
268267
{{/hasValidation}}
268+
{{#isArray}}
269+
{{#isNullable}}
270+
// Nullable array query parameters are not fully supported.
271+
{{/isNullable}}
272+
{{^required}}
273+
#[serde(default)]
274+
{{/required}}
275+
pub {{{paramName}}}: {{{dataType}}},
276+
{{/isArray}}
277+
{{^isArray}}
269278
{{#required}}
270279
pub {{{paramName}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}},
271280
{{/required}}
@@ -277,7 +286,7 @@ use crate::{models, types::*};
277286
#[serde(skip_serializing_if="Option::is_none")]
278287
pub {{{paramName}}}: Option<{{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}>,
279288
{{/required}}
280-
{{/vendorExtensions}}
289+
{{/isArray}}
281290
{{/queryParams}}
282291
}
283292

modules/openapi-generator/src/main/resources/rust-axum/server-imports.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22

33
use axum::{body::Body, extract::*, response::Response, routing::*};
4-
use axum_extra::extract::{CookieJar, Host};
4+
use axum_extra::extract::{CookieJar, Host, Query as QueryExtra};
55
use bytes::Bytes;
66
use http::{header::CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
77
use tracing::error;

modules/openapi-generator/src/main/resources/rust-axum/server-operation.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}<I, A, E{
2323
Path(path_params): Path<models::{{{operationIdCamelCase}}}PathParams>,
2424
{{/pathParams.size}}
2525
{{#queryParams.size}}
26-
Query(query_params): Query<models::{{{operationIdCamelCase}}}QueryParams>,
26+
QueryExtra(query_params): QueryExtra<models::{{{operationIdCamelCase}}}QueryParams>,
2727
{{/queryParams.size}}
2828
State(api_impl): State<I>,
2929
{{#vendorExtensions}}
@@ -334,7 +334,7 @@ where
334334
{{#allowBlockingResponseSerialize}}
335335
let body_content =
336336
{{/allowBlockingResponseSerialize}}
337-
serde_urlencoded::to_string(body).map_err(|e| {
337+
serde_html_form::to_string(body).map_err(|e| {
338338
error!(error = ?e);
339339
StatusCode::INTERNAL_SERVER_ERROR
340340
}){{^allowBlockingResponseSerialize}}).await.unwrap(){{/allowBlockingResponseSerialize}}?;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Test to check that array query params are rendered correctly.
4+
version: 0.0.1
5+
paths:
6+
/endpoint:
7+
get:
8+
description: Some endpoint.
9+
parameters:
10+
- name: numbers
11+
in: query
12+
description: Some numbers.
13+
schema:
14+
type: array
15+
items:
16+
type: number
17+
- name: multiplier
18+
in: query
19+
description: Multipler for sum.
20+
schema:
21+
type: number
22+
responses:
23+
'200':
24+
description: OK.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.12.0-SNAPSHOT
1+
7.13.0-SNAPSHOT

samples/server/petstore/rust-axum/output/apikey-auths/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ conversion = [
1919
[dependencies]
2020
async-trait = "0.1"
2121
axum = { version = "0.8", features = ["multipart"] }
22-
axum-extra = { version = "0.10", features = ["cookie"] }
22+
axum-extra = { version = "0.10", features = ["cookie", "query"] }
2323
base64 = "0.22"
2424
bytes = "1"
2525
chrono = { version = "0.4", features = ["serde"] }
@@ -32,8 +32,8 @@ http = "1"
3232
lazy_static = "1"
3333
regex = "1"
3434
serde = { version = "1", features = ["derive"] }
35+
serde_html_form = "0.2"
3536
serde_json = { version = "1", features = ["raw_value"] }
36-
serde_urlencoded = "0.7"
3737
tokio = { version = "1", default-features = false, features = [
3838
"signal",
3939
"rt-multi-thread",

samples/server/petstore/rust-axum/output/apikey-auths/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ server, you can easily generate a server stub.
1212
To see how to make this your own, look here: [README]((https://openapi-generator.tech))
1313

1414
- API version: 1.0.0
15-
- Generator version: 7.12.0-SNAPSHOT
15+
- Generator version: 7.13.0-SNAPSHOT
1616

1717

1818

samples/server/petstore/rust-axum/output/apikey-auths/src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22

33
use axum::{body::Body, extract::*, response::Response, routing::*};
4-
use axum_extra::extract::{CookieJar, Host};
4+
use axum_extra::extract::{CookieJar, Host, Query as QueryExtra};
55
use bytes::Bytes;
66
use http::{header::CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
77
use tracing::error;

0 commit comments

Comments
 (0)