Skip to content

Commit 1ce95ff

Browse files
authored
Map type date to correct rust type NaiveDate (#17095)
* Fix clippy errors (rustc 1.73.0) * Add feature docker-in-docker * Fix mapping of "date" See issue #9769 The type type: string format: date was mapped to DateTime<Utc> which violates the OpenAPI spec see https://swagger.io/docs/specification/data-models/data-types/
1 parent 5c69284 commit 1ce95ff

19 files changed

Lines changed: 207 additions & 202 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
"ghcr.io/devcontainers/features/node:1": {
1010
"version": "lts"
1111
},
12-
"ghcr.io/snebjorn/devcontainer-feature/chromium:latest": {}
12+
"ghcr.io/snebjorn/devcontainer-feature/chromium:latest": {},
13+
"docker-in-docker": {
14+
"version": "latest",
15+
"moby": true,
16+
"dockerDashComposeVersion": "v1"
17+
}
1318
},
1419
// Configure tool-specific properties.
1520
"customizations": {
@@ -44,4 +49,4 @@
4449
// "postCreateCommand": "mvn clean package -DskipTests",
4550
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
4651
"remoteUser": "vscode"
47-
}
52+
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public RustServerCodegen() {
193193
typeMapping.put("ByteArray", bytesType);
194194
typeMapping.put("binary", bytesType);
195195
typeMapping.put("boolean", "bool");
196-
typeMapping.put("date", "chrono::DateTime::<chrono::Utc>");
196+
typeMapping.put("date", "chrono::naive::NaiveDate");
197197
typeMapping.put("DateTime", "chrono::DateTime::<chrono::Utc>");
198198
typeMapping.put("password", "String");
199199
typeMapping.put("File", bytesType);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@
310310
match auth_data {
311311
{{#authMethods}}
312312
{{#isBasicBasic}}
313-
&AuthData::Basic(ref basic_header) => {
313+
AuthData::Basic(basic_header) => {
314314
let auth = swagger::auth::Header(basic_header.clone());
315315
let header = match HeaderValue::from_str(&format!("{}", auth)) {
316316
Ok(h) => h,
@@ -322,7 +322,7 @@
322322
},
323323
{{/isBasicBasic}}
324324
{{#isBasicBearer}}
325-
&AuthData::Bearer(ref bearer_header) => {
325+
AuthData::Bearer(bearer_header) => {
326326
let auth = swagger::auth::Header(bearer_header.clone());
327327
let header = match HeaderValue::from_str(&format!("{}", auth)) {
328328
Ok(h) => h,
@@ -335,7 +335,7 @@
335335
{{/isBasicBearer}}
336336
{{#isOAuth}}
337337
{{^isBasicBearer}}
338-
&AuthData::Bearer(ref bearer_header) => {
338+
AuthData::Bearer(bearer_header) => {
339339
let auth = swagger::auth::Header(bearer_header.clone());
340340
let header = match HeaderValue::from_str(&format!("{}", auth)) {
341341
Ok(h) => h,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl std::string::ToString for {{{classname}}} {
389389
{{/required}}
390390
{{^required}}
391391
self.{{{name}}}.as_ref().map(|{{{name}}}| {
392-
vec![
392+
[
393393
"{{{baseName}}}".to_string(),
394394
{{^isArray}}
395395
{{#isNullable}}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,27 +574,27 @@
574574
{{#vendorExtensions}}
575575
{{#x-produces-xml}}
576576
{{^x-has-namespace}}
577-
let body = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
577+
let body_content = serde_xml_rs::to_string(&body).expect("impossible to fail to serialize");
578578
{{/x-has-namespace}}
579579
{{#x-has-namespace}}
580580
let mut namespaces = std::collections::BTreeMap::new();
581581

582582
// An empty string is used to indicate a global namespace in xmltree.
583583
namespaces.insert("".to_string(), {{{dataType}}}::NAMESPACE.to_string());
584-
let body = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize");
584+
let body_content = serde_xml_rs::to_string_with_namespaces(&body, namespaces).expect("impossible to fail to serialize");
585585
{{/x-has-namespace}}
586586
{{/x-produces-xml}}
587587
{{#x-produces-json}}
588-
let body = serde_json::to_string(&body).expect("impossible to fail to serialize");
588+
let body_content = serde_json::to_string(&body).expect("impossible to fail to serialize");
589589
{{/x-produces-json}}
590590
{{#x-produces-bytes}}
591-
let body = body.0;
591+
let body_content = body.0;
592592
{{/x-produces-bytes}}
593593
{{#x-produces-plain-text}}
594-
let body = body;
594+
let body_content = body;
595595
{{/x-produces-plain-text}}
596596
{{/vendorExtensions}}
597-
*response.body_mut() = Body::from(body);
597+
*response.body_mut() = Body::from(body_content);
598598
{{/dataType}}
599599
},
600600
{{/responses}}

samples/server/petstore/rust-server/output/multipart-v3/src/models.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl std::string::ToString for MultipartRequestObjectField {
180180

181181

182182
self.field_b.as_ref().map(|field_b| {
183-
vec![
183+
[
184184
"field_b".to_string(),
185185
field_b.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","),
186186
].join(",")

samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ impl<S, C> Api<C> for Client<S, C> where
11651165
// Currently only authentication with Basic and Bearer are supported
11661166
#[allow(clippy::single_match, clippy::match_single_binding)]
11671167
match auth_data {
1168-
&AuthData::Bearer(ref bearer_header) => {
1168+
AuthData::Bearer(bearer_header) => {
11691169
let auth = swagger::auth::Header(bearer_header.clone());
11701170
let header = match HeaderValue::from_str(&format!("{}", auth)) {
11711171
Ok(h) => h,
@@ -1489,7 +1489,7 @@ impl<S, C> Api<C> for Client<S, C> where
14891489
// Currently only authentication with Basic and Bearer are supported
14901490
#[allow(clippy::single_match, clippy::match_single_binding)]
14911491
match auth_data {
1492-
&AuthData::Bearer(ref bearer_header) => {
1492+
AuthData::Bearer(bearer_header) => {
14931493
let auth = swagger::auth::Header(bearer_header.clone());
14941494
let header = match HeaderValue::from_str(&format!("{}", auth)) {
14951495
Ok(h) => h,

samples/server/petstore/rust-server/output/openapi-v3/src/models.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl std::string::ToString for AnotherXmlObject {
295295
let params: Vec<Option<String>> = vec![
296296

297297
self.inner_string.as_ref().map(|inner_string| {
298-
vec![
298+
[
299299
"inner_string".to_string(),
300300
inner_string.to_string(),
301301
].join(",")
@@ -815,7 +815,7 @@ impl std::string::ToString for DuplicateXmlObject {
815815
let params: Vec<Option<String>> = vec![
816816

817817
self.inner_string.as_ref().map(|inner_string| {
818-
vec![
818+
[
819819
"inner_string".to_string(),
820820
inner_string.to_string(),
821821
].join(",")
@@ -1233,7 +1233,7 @@ impl std::string::ToString for MultigetGet201Response {
12331233
let params: Vec<Option<String>> = vec![
12341234

12351235
self.foo.as_ref().map(|foo| {
1236-
vec![
1236+
[
12371237
"foo".to_string(),
12381238
foo.to_string(),
12391239
].join(",")
@@ -1574,31 +1574,31 @@ impl std::string::ToString for NullableTest {
15741574

15751575

15761576
self.nullable_with_null_default.as_ref().map(|nullable_with_null_default| {
1577-
vec![
1577+
[
15781578
"nullableWithNullDefault".to_string(),
15791579
nullable_with_null_default.as_ref().map_or("null".to_string(), |x| x.to_string()),
15801580
].join(",")
15811581
}),
15821582

15831583

15841584
self.nullable_with_present_default.as_ref().map(|nullable_with_present_default| {
1585-
vec![
1585+
[
15861586
"nullableWithPresentDefault".to_string(),
15871587
nullable_with_present_default.as_ref().map_or("null".to_string(), |x| x.to_string()),
15881588
].join(",")
15891589
}),
15901590

15911591

15921592
self.nullable_with_no_default.as_ref().map(|nullable_with_no_default| {
1593-
vec![
1593+
[
15941594
"nullableWithNoDefault".to_string(),
15951595
nullable_with_no_default.as_ref().map_or("null".to_string(), |x| x.to_string()),
15961596
].join(",")
15971597
}),
15981598

15991599

16001600
self.nullable_array.as_ref().map(|nullable_array| {
1601-
vec![
1601+
[
16021602
"nullableArray".to_string(),
16031603
nullable_array.as_ref().map_or("null".to_string(), |x| x.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(",")),
16041604
].join(",")
@@ -1750,7 +1750,7 @@ impl std::string::ToString for ObjectHeader {
17501750

17511751

17521752
self.optional_object_header.as_ref().map(|optional_object_header| {
1753-
vec![
1753+
[
17541754
"optionalObjectHeader".to_string(),
17551755
optional_object_header.to_string(),
17561756
].join(",")
@@ -1895,7 +1895,7 @@ impl std::string::ToString for ObjectParam {
18951895

18961896

18971897
self.optional_param.as_ref().map(|optional_param| {
1898-
vec![
1898+
[
18991899
"optionalParam".to_string(),
19001900
optional_param.to_string(),
19011901
].join(",")
@@ -2189,7 +2189,7 @@ impl std::string::ToString for ObjectWithArrayOfObjects {
21892189
let params: Vec<Option<String>> = vec![
21902190

21912191
self.object_array.as_ref().map(|object_array| {
2192-
vec![
2192+
[
21932193
"objectArray".to_string(),
21942194
object_array.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","),
21952195
].join(",")
@@ -2963,15 +2963,15 @@ impl std::string::ToString for XmlObject {
29632963
let params: Vec<Option<String>> = vec![
29642964

29652965
self.inner_string.as_ref().map(|inner_string| {
2966-
vec![
2966+
[
29672967
"innerString".to_string(),
29682968
inner_string.to_string(),
29692969
].join(",")
29702970
}),
29712971

29722972

29732973
self.other_inner_rename.as_ref().map(|other_inner_rename| {
2974-
vec![
2974+
[
29752975
"other_inner_rename".to_string(),
29762976
other_inner_rename.to_string(),
29772977
].join(",")

0 commit comments

Comments
 (0)