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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bin/configs/manual/rust-axum-array-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: rust-axum
outputDir: samples/server/petstore/rust-axum/output/rust-axum-array-params-test
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/rust-axum-array-params-test.yaml
templateDir: modules/openapi-generator/src/main/resources/rust-axum
generateAliasAsModel: true
additionalProperties:
hideGenerationTimestamp: "true"
packageName: rust-axum-array-params-test
globalProperties:
skipFormModel: false
enablePostProcessFile: true
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ conversion = [
[dependencies]
async-trait = "0.1"
axum = { version = "0.8", features = ["multipart"] }
axum-extra = { version = "0.10", features = ["cookie"] }
axum-extra = { version = "0.10", features = ["cookie", "query"] }
base64 = "0.22"
bytes = "1"
chrono = { version = "0.4", features = ["serde"] }
Expand All @@ -54,8 +54,8 @@ http = "1"
lazy_static = "1"
regex = "1"
serde = { version = "1", features = ["derive"] }
serde_html_form = "0.2"
serde_json = { version = "1", features = ["raw_value"] }
serde_urlencoded = "0.7"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please also explain why we need to replace serde_urlencoded with serde_html_form?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serde_urlencoded explicitly doesn't support array query params and will never do so. See nox/serde_urlencoded#52 for example. serde_html_form is a fork with that in mind. See item 2 in the PR description.

tokio = { version = "1", default-features = false, features = [
"signal",
"rt-multi-thread",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ use crate::{models, types::*};
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct {{{operationIdCamelCase}}}QueryParams {
{{#queryParams}}
{{#vendorExtensions}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tanadeau could you please explain why we need to remove vendorExtensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This created the wrong context, and within it, the template couldn't get the correct values for isArray, etc. It's now also consistent with the other blocks for header params, path params, etc. They would have had the same issue.

{{#description}}
/// {{{.}}}
{{/description}}
Expand Down Expand Up @@ -266,6 +265,16 @@ use crate::{models, types::*};
{{/maxItems}}
)]
{{/hasValidation}}
{{#isArray}}
{{#isNullable}}
// Nullable array query parameters are not fully supported.
{{/isNullable}}
{{^required}}
#[serde(default)]
{{/required}}
pub {{{paramName}}}: {{{dataType}}},
{{/isArray}}
{{^isArray}}
{{#required}}
pub {{{paramName}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}},
{{/required}}
Expand All @@ -277,7 +286,7 @@ use crate::{models, types::*};
#[serde(skip_serializing_if="Option::is_none")]
pub {{{paramName}}}: Option<{{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}>,
{{/required}}
{{/vendorExtensions}}
{{/isArray}}
{{/queryParams}}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use axum::{body::Body, extract::*, response::Response, routing::*};
use axum_extra::extract::{CookieJar, Host};
use axum_extra::extract::{CookieJar, Host, Query as QueryExtra};
use bytes::Bytes;
use http::{header::CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
use tracing::error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}<I, A, E{
Path(path_params): Path<models::{{{operationIdCamelCase}}}PathParams>,
{{/pathParams.size}}
{{#queryParams.size}}
Query(query_params): Query<models::{{{operationIdCamelCase}}}QueryParams>,
QueryExtra(query_params): QueryExtra<models::{{{operationIdCamelCase}}}QueryParams>,
{{/queryParams.size}}
State(api_impl): State<I>,
{{#vendorExtensions}}
Expand Down Expand Up @@ -334,7 +334,7 @@ where
{{#allowBlockingResponseSerialize}}
let body_content =
{{/allowBlockingResponseSerialize}}
serde_urlencoded::to_string(body).map_err(|e| {
serde_html_form::to_string(body).map_err(|e| {
error!(error = ?e);
StatusCode::INTERNAL_SERVER_ERROR
}){{^allowBlockingResponseSerialize}}).await.unwrap(){{/allowBlockingResponseSerialize}}?;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
openapi: 3.0.1
info:
title: Test to check that array query params are rendered correctly.
version: 0.0.1
paths:
/endpoint:
get:
description: Some endpoint.
parameters:
- name: numbers
in: query
description: Some numbers.
schema:
type: array
items:
type: number
- name: multiplier
in: query
description: Multipler for sum.
schema:
type: number
responses:
'200':
description: OK.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.12.0-SNAPSHOT
7.13.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ conversion = [
[dependencies]
async-trait = "0.1"
axum = { version = "0.8", features = ["multipart"] }
axum-extra = { version = "0.10", features = ["cookie"] }
axum-extra = { version = "0.10", features = ["cookie", "query"] }
base64 = "0.22"
bytes = "1"
chrono = { version = "0.4", features = ["serde"] }
Expand All @@ -32,8 +32,8 @@ http = "1"
lazy_static = "1"
regex = "1"
serde = { version = "1", features = ["derive"] }
serde_html_form = "0.2"
serde_json = { version = "1", features = ["raw_value"] }
serde_urlencoded = "0.7"
tokio = { version = "1", default-features = false, features = [
"signal",
"rt-multi-thread",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 1.0.0
- Generator version: 7.12.0-SNAPSHOT
- Generator version: 7.13.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use axum::{body::Body, extract::*, response::Response, routing::*};
use axum_extra::extract::{CookieJar, Host};
use axum_extra::extract::{CookieJar, Host, Query as QueryExtra};
use bytes::Bytes;
use http::{header::CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
use tracing::error;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.12.0-SNAPSHOT
7.13.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ conversion = [
[dependencies]
async-trait = "0.1"
axum = { version = "0.8", features = ["multipart"] }
axum-extra = { version = "0.10", features = ["cookie"] }
axum-extra = { version = "0.10", features = ["cookie", "query"] }
base64 = "0.22"
bytes = "1"
chrono = { version = "0.4", features = ["serde"] }
Expand All @@ -32,8 +32,8 @@ http = "1"
lazy_static = "1"
regex = "1"
serde = { version = "1", features = ["derive"] }
serde_html_form = "0.2"
serde_json = { version = "1", features = ["raw_value"] }
serde_urlencoded = "0.7"
tokio = { version = "1", default-features = false, features = [
"signal",
"rt-multi-thread",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 1.0.7
- Generator version: 7.12.0-SNAPSHOT
- Generator version: 7.13.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use axum::{body::Body, extract::*, response::Response, routing::*};
use axum_extra::extract::{CookieJar, Host};
use axum_extra::extract::{CookieJar, Host, Query as QueryExtra};
use bytes::Bytes;
use http::{header::CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
use tracing::error;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.12.0-SNAPSHOT
7.13.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ conversion = [
[dependencies]
async-trait = "0.1"
axum = { version = "0.8", features = ["multipart"] }
axum-extra = { version = "0.10", features = ["cookie"] }
axum-extra = { version = "0.10", features = ["cookie", "query"] }
base64 = "0.22"
bytes = "1"
chrono = { version = "0.4", features = ["serde"] }
Expand All @@ -32,8 +32,8 @@ http = "1"
lazy_static = "1"
regex = "1"
serde = { version = "1", features = ["derive"] }
serde_html_form = "0.2"
serde_json = { version = "1", features = ["raw_value"] }
serde_urlencoded = "0.7"
tokio = { version = "1", default-features = false, features = [
"signal",
"rt-multi-thread",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 1.0.7
- Generator version: 7.12.0-SNAPSHOT
- Generator version: 7.13.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct AnyOfGetQueryParams {
/// list of any of objects
#[serde(rename = "any-of")]
#[validate(length(min = 1))]
#[serde(skip_serializing_if = "Option::is_none")]
pub any_of: Option<Vec<models::AnyOfObject>>,
#[serde(default)]
pub any_of: Vec<models::AnyOfObject>,
}

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
Expand All @@ -28,8 +28,8 @@ pub struct CallbackWithHeaderPostQueryParams {
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct ComplexQueryParamGetQueryParams {
#[serde(rename = "list-of-strings")]
#[serde(skip_serializing_if = "Option::is_none")]
pub list_of_strings: Option<Vec<models::StringObject>>,
#[serde(default)]
pub list_of_strings: Vec<models::StringObject>,
}

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
Expand All @@ -50,8 +50,8 @@ pub struct GetWithBooleanParameterQueryParams {
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct JsonComplexQueryParamGetQueryParams {
#[serde(rename = "list-of-strings")]
#[serde(skip_serializing_if = "Option::is_none")]
pub list_of_strings: Option<Vec<models::StringObject>>,
#[serde(default)]
pub list_of_strings: Vec<models::StringObject>,
}

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
Expand Down Expand Up @@ -80,8 +80,8 @@ pub struct ParamgetGetQueryParams {
pub some_object: Option<crate::types::Object>,
/// Some list to pass as query parameter
#[serde(rename = "someList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub some_list: Option<Vec<models::MyId>>,
#[serde(default)]
pub some_list: Vec<models::MyId>,
}

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use axum::{body::Body, extract::*, response::Response, routing::*};
use axum_extra::extract::{CookieJar, Host};
use axum_extra::extract::{CookieJar, Host, Query as QueryExtra};
use bytes::Bytes;
use http::{header::CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
use tracing::error;
Expand Down Expand Up @@ -127,7 +127,7 @@ async fn any_of_get<I, A, E>(
method: Method,
host: Host,
cookies: CookieJar,
Query(query_params): Query<models::AnyOfGetQueryParams>,
QueryExtra(query_params): QueryExtra<models::AnyOfGetQueryParams>,
State(api_impl): State<I>,
) -> Result<Response, StatusCode>
where
Expand Down Expand Up @@ -253,7 +253,7 @@ async fn callback_with_header_post<I, A, E>(
method: Method,
host: Host,
cookies: CookieJar,
Query(query_params): Query<models::CallbackWithHeaderPostQueryParams>,
QueryExtra(query_params): QueryExtra<models::CallbackWithHeaderPostQueryParams>,
State(api_impl): State<I>,
) -> Result<Response, StatusCode>
where
Expand Down Expand Up @@ -314,7 +314,7 @@ async fn complex_query_param_get<I, A, E>(
method: Method,
host: Host,
cookies: CookieJar,
Query(query_params): Query<models::ComplexQueryParamGetQueryParams>,
QueryExtra(query_params): QueryExtra<models::ComplexQueryParamGetQueryParams>,
State(api_impl): State<I>,
) -> Result<Response, StatusCode>
where
Expand Down Expand Up @@ -505,7 +505,7 @@ async fn get_with_boolean_parameter<I, A, E>(
method: Method,
host: Host,
cookies: CookieJar,
Query(query_params): Query<models::GetWithBooleanParameterQueryParams>,
QueryExtra(query_params): QueryExtra<models::GetWithBooleanParameterQueryParams>,
State(api_impl): State<I>,
) -> Result<Response, StatusCode>
where
Expand Down Expand Up @@ -566,7 +566,7 @@ async fn json_complex_query_param_get<I, A, E>(
method: Method,
host: Host,
cookies: CookieJar,
Query(query_params): Query<models::JsonComplexQueryParamGetQueryParams>,
QueryExtra(query_params): QueryExtra<models::JsonComplexQueryParamGetQueryParams>,
State(api_impl): State<I>,
) -> Result<Response, StatusCode>
where
Expand Down Expand Up @@ -1247,7 +1247,7 @@ async fn paramget_get<I, A, E>(
method: Method,
host: Host,
cookies: CookieJar,
Query(query_params): Query<models::ParamgetGetQueryParams>,
QueryExtra(query_params): QueryExtra<models::ParamgetGetQueryParams>,
State(api_impl): State<I>,
) -> Result<Response, StatusCode>
where
Expand Down Expand Up @@ -1381,7 +1381,7 @@ async fn register_callback_post<I, A, E>(
method: Method,
host: Host,
cookies: CookieJar,
Query(query_params): Query<models::RegisterCallbackPostQueryParams>,
QueryExtra(query_params): QueryExtra<models::RegisterCallbackPostQueryParams>,
State(api_impl): State<I>,
) -> Result<Response, StatusCode>
where
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.12.0-SNAPSHOT
7.13.0-SNAPSHOT
4 changes: 2 additions & 2 deletions samples/server/petstore/rust-axum/output/ops-v3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ conversion = [
[dependencies]
async-trait = "0.1"
axum = { version = "0.8", features = ["multipart"] }
axum-extra = { version = "0.10", features = ["cookie"] }
axum-extra = { version = "0.10", features = ["cookie", "query"] }
base64 = "0.22"
bytes = "1"
chrono = { version = "0.4", features = ["serde"] }
Expand All @@ -32,8 +32,8 @@ http = "1"
lazy_static = "1"
regex = "1"
serde = { version = "1", features = ["derive"] }
serde_html_form = "0.2"
serde_json = { version = "1", features = ["raw_value"] }
serde_urlencoded = "0.7"
tokio = { version = "1", default-features = false, features = [
"signal",
"rt-multi-thread",
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/rust-axum/output/ops-v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server, you can easily generate a server stub.
To see how to make this your own, look here: [README]((https://openapi-generator.tech))

- API version: 0.0.1
- Generator version: 7.12.0-SNAPSHOT
- Generator version: 7.13.0-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use axum::{body::Body, extract::*, response::Response, routing::*};
use axum_extra::extract::{CookieJar, Host};
use axum_extra::extract::{CookieJar, Host, Query as QueryExtra};
use bytes::Bytes;
use http::{header::CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
use tracing::error;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.12.0-SNAPSHOT
7.13.0-SNAPSHOT
Loading
Loading