Skip to content

Commit a809c18

Browse files
wing328SidWagz
andauthored
[JavaSpring] Fix when openapi spec file has array of files (#21524)
* [JavaSpring] Fix when openapi spec file has array of files The isArray is not checked for non-reactive isFile condition. This is remediated. * update samples --------- Co-authored-by: Siddharth Wagle <SidWagz@users.noreply.github.com>
1 parent d966f12 commit a809c18

File tree

32 files changed

+1
-905
lines changed

32 files changed

+1
-905
lines changed

modules/openapi-generator/src/main/resources/JavaSpring/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public interface {{classname}} {
274274
}
275275

276276
// Override this method
277-
{{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{>responseType}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#reactive}}Flux<Part>{{/reactive}}{{^reactive}}MultipartFile{{/reactive}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}} {
277+
{{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{>responseType}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#reactive}}Flux<Part>{{/reactive}}{{^reactive}}{{#isArray}}List<MultipartFile>{{/isArray}}{{^isArray}}MultipartFile{{/isArray}}{{/reactive}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}} {
278278
{{/delegate-method}}
279279
{{^isDelegate}}
280280
{{>methodBody}}{{! prevent indent}}

samples/server/petstore/rust-server-deprecated/output/multipart-v3/examples/server/server.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
123123
info!("multipart_related_request_post({:?}, {:?}, {:?}) - X-Span-ID: {:?}", required_binary_field, object_field, optional_binary_field, context.get().0.clone());
124124
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
125125
}
126-
127126
async fn multipart_request_post(
128127
&self,
129128
string_field: String,
@@ -135,7 +134,6 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
135134
info!("multipart_request_post(\"{}\", {:?}, {:?}, {:?}) - X-Span-ID: {:?}", string_field, binary_field, optional_string_field, object_field, context.get().0.clone());
136135
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
137136
}
138-
139137
async fn multiple_identical_mime_types_post(
140138
&self,
141139
binary1: Option<swagger::ByteArray>,
@@ -145,5 +143,4 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
145143
info!("multiple_identical_mime_types_post({:?}, {:?}) - X-Span-ID: {:?}", binary1, binary2, context.get().0.clone());
146144
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
147145
}
148-
149146
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ impl<S, C> Api<C> for Client<S, C> where
444444
});
445445
body_parts.push(part);
446446
}
447-
448447
if let Some(optional_binary_field) = param_optional_binary_field {
449448
let part = Node::Part(Part {
450449
headers: {
@@ -457,7 +456,6 @@ impl<S, C> Api<C> for Client<S, C> where
457456
});
458457
body_parts.push(part);
459458
}
460-
461459
{
462460
let part = Node::Part(Part {
463461
headers: {
@@ -479,7 +477,6 @@ impl<S, C> Api<C> for Client<S, C> where
479477
write_multipart(&mut body, &boundary, &body_parts)
480478
.expect("Failed to write multipart body");
481479

482-
483480
let header = "multipart/related";
484481
request.headers_mut().insert(CONTENT_TYPE,
485482
match HeaderValue::from_bytes(
@@ -491,7 +488,6 @@ impl<S, C> Api<C> for Client<S, C> where
491488

492489
// Add the message body to the request object.
493490
*request.body_mut() = Body::from(body);
494-
495491
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
496492
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
497493
Ok(h) => h,
@@ -524,7 +520,6 @@ impl<S, C> Api<C> for Client<S, C> where
524520
}
525521
}
526522
}
527-
528523
async fn multipart_request_post(
529524
&self,
530525
param_string_field: String,
@@ -643,8 +638,6 @@ impl<S, C> Api<C> for Client<S, C> where
643638
Ok(h) => h,
644639
Err(e) => return Err(ApiError(format!("Unable to create header: {multipart_header} - {e}")))
645640
});
646-
647-
648641
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
649642
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
650643
Ok(h) => h,
@@ -677,7 +670,6 @@ impl<S, C> Api<C> for Client<S, C> where
677670
}
678671
}
679672
}
680-
681673
async fn multiple_identical_mime_types_post(
682674
&self,
683675
param_binary1: Option<swagger::ByteArray>,
@@ -730,7 +722,6 @@ impl<S, C> Api<C> for Client<S, C> where
730722
});
731723
body_parts.push(part);
732724
}
733-
734725
if let Some(binary2) = param_binary2 {
735726
let part = Node::Part(Part {
736727
headers: {
@@ -752,7 +743,6 @@ impl<S, C> Api<C> for Client<S, C> where
752743
write_multipart(&mut body, &boundary, &body_parts)
753744
.expect("Failed to write multipart body");
754745

755-
756746
let header = "multipart/related";
757747
request.headers_mut().insert(CONTENT_TYPE,
758748
match HeaderValue::from_bytes(
@@ -764,7 +754,6 @@ impl<S, C> Api<C> for Client<S, C> where
764754

765755
// Add the message body to the request object.
766756
*request.body_mut() = Body::from(body);
767-
768757
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
769758
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
770759
Ok(h) => h,
@@ -797,5 +786,4 @@ impl<S, C> Api<C> for Client<S, C> where
797786
}
798787
}
799788
}
800-
801789
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ pub enum MultipartRelatedRequestPostResponse {
2525
/// OK
2626
OK
2727
}
28-
2928
#[derive(Debug, PartialEq, Serialize, Deserialize)]
3029
pub enum MultipartRequestPostResponse {
3130
/// OK
3231
OK
3332
}
34-
3533
#[derive(Debug, PartialEq, Serialize, Deserialize)]
3634
pub enum MultipleIdenticalMimeTypesPostResponse {
3735
/// OK
3836
OK
3937
}
40-
4138
/// API
4239
#[async_trait]
4340
#[allow(clippy::too_many_arguments, clippy::ptr_arg)]

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ mod paths {
5252
pub(crate) static ID_MULTIPLE_IDENTICAL_MIME_TYPES: usize = 2;
5353
}
5454

55-
5655
pub struct MakeService<T, C> where
5756
T: Api<C> + Clone + Send + 'static,
5857
C: Has<XSpanIdString> + Send + Sync + 'static
@@ -104,7 +103,6 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
104103
future::ok(service)
105104
}
106105
}
107-
108106
fn method_not_allowed() -> Result<Response<Body>, crate::ServiceError> {
109107
Ok(
110108
Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
@@ -185,7 +183,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
185183
let path = paths::GLOBAL_REGEX_SET.matches(uri.path());
186184

187185
match method {
188-
189186
// MultipartRelatedRequestPost - POST /multipart_related_request
190187
hyper::Method::POST if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => {
191188
// Handle body parameters (note that non-required body parameters will ignore garbage
@@ -272,8 +269,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
272269
.body(Body::from("Missing required multipart/related parameter required_binary_field".to_string()))
273270
.expect("Unable to create Bad Request response for missing multipart/related parameter required_binary_field due to schema"))
274271
};
275-
276-
277272
let result = api_impl.multipart_related_request_post(
278273
param_required_binary_field,
279274
param_object_field,
@@ -297,7 +292,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
297292
MultipartRelatedRequestPostResponse::OK
298293
=> {
299294
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
300-
301295
},
302296
},
303297
Err(_) => {
@@ -316,7 +310,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
316310
.expect("Unable to create Bad Request response due to unable to read body")),
317311
}
318312
},
319-
320313
// MultipartRequestPost - POST /multipart_request
321314
hyper::Method::POST if path.matched(paths::ID_MULTIPART_REQUEST) => {
322315
// Handle body parameters (note that non-required body parameters will ignore garbage
@@ -465,8 +458,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
465458
.expect("Unable to create Bad Request due to missing required form parameter binary_field"))
466459
}
467460
};
468-
469-
470461
let result = api_impl.multipart_request_post(
471462
param_string_field,
472463
param_binary_field,
@@ -485,7 +476,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
485476
MultipartRequestPostResponse::OK
486477
=> {
487478
*response.status_mut() = StatusCode::from_u16(201).expect("Unable to turn 201 into a StatusCode");
488-
489479
},
490480
},
491481
Err(_) => {
@@ -504,7 +494,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
504494
.expect("Unable to create Bad Request response due to unable to read body")),
505495
}
506496
},
507-
508497
// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types
509498
hyper::Method::POST if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => {
510499
// Handle body parameters (note that non-required body parameters will ignore garbage
@@ -567,8 +556,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
567556
}
568557

569558
// Check that the required multipart chunks are present.
570-
571-
572559
let result = api_impl.multiple_identical_mime_types_post(
573560
param_binary1,
574561
param_binary2,
@@ -591,7 +578,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
591578
MultipleIdenticalMimeTypesPostResponse::OK
592579
=> {
593580
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
594-
595581
},
596582
},
597583
Err(_) => {
@@ -610,7 +596,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
610596
.expect("Unable to create Bad Request response due to unable to read body")),
611597
}
612598
},
613-
614599
_ if path.matched(paths::ID_MULTIPART_RELATED_REQUEST) => method_not_allowed(),
615600
_ if path.matched(paths::ID_MULTIPART_REQUEST) => method_not_allowed(),
616601
_ if path.matched(paths::ID_MULTIPLE_IDENTICAL_MIME_TYPES) => method_not_allowed(),
@@ -626,7 +611,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
626611
))
627612
}
628613
}
629-
630614
/// Request parser for `Api`.
631615
pub struct ApiRequestParser;
632616
impl<T> RequestParser<T> for ApiRequestParser {

samples/server/petstore/rust-server-deprecated/output/no-example-v3/examples/server/server.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,4 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
119119
info!("op_get({:?}) - X-Span-ID: {:?}", op_get_request, context.get().0.clone());
120120
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
121121
}
122-
123122
}

samples/server/petstore/rust-server-deprecated/output/no-example-v3/src/client/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ impl<S, C> Api<C> for Client<S, C> where
427427
Ok(h) => h,
428428
Err(e) => return Err(ApiError(format!("Unable to create header: {header} - {e}")))
429429
});
430-
431430
let header = HeaderValue::from_str(Has::<XSpanIdString>::get(context).0.as_str());
432431
request.headers_mut().insert(HeaderName::from_static("x-span-id"), match header {
433432
Ok(h) => h,
@@ -460,5 +459,4 @@ impl<S, C> Api<C> for Client<S, C> where
460459
}
461460
}
462461
}
463-
464462
}

samples/server/petstore/rust-server-deprecated/output/no-example-v3/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub enum OpGetResponse {
2525
/// OK
2626
OK
2727
}
28-
2928
/// API
3029
#[async_trait]
3130
#[allow(clippy::too_many_arguments, clippy::ptr_arg)]

samples/server/petstore/rust-server-deprecated/output/no-example-v3/src/server/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ mod paths {
4141
pub(crate) static ID_OP: usize = 0;
4242
}
4343

44-
4544
pub struct MakeService<T, C> where
4645
T: Api<C> + Clone + Send + 'static,
4746
C: Has<XSpanIdString> + Send + Sync + 'static
@@ -80,7 +79,6 @@ impl<T, C, Target> hyper::service::Service<Target> for MakeService<T, C> where
8079
future::ok(service)
8180
}
8281
}
83-
8482
fn method_not_allowed() -> Result<Response<Body>, crate::ServiceError> {
8583
Ok(
8684
Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
@@ -147,7 +145,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
147145
let path = paths::GLOBAL_REGEX_SET.matches(uri.path());
148146

149147
match method {
150-
151148
// OpGet - GET /op
152149
hyper::Method::GET if path.matched(paths::ID_OP) => {
153150
// Handle body parameters (note that non-required body parameters will ignore garbage
@@ -179,8 +176,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
179176
.body(Body::from("Missing required body parameter OpGetRequest"))
180177
.expect("Unable to create Bad Request response for missing body parameter OpGetRequest")),
181178
};
182-
183-
184179
let result = api_impl.op_get(
185180
param_op_get_request,
186181
&context
@@ -202,7 +197,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
202197
OpGetResponse::OK
203198
=> {
204199
*response.status_mut() = StatusCode::from_u16(200).expect("Unable to turn 200 into a StatusCode");
205-
206200
},
207201
},
208202
Err(_) => {
@@ -221,7 +215,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
221215
.expect("Unable to create Bad Request response due to unable to read body")),
222216
}
223217
},
224-
225218
_ if path.matched(paths::ID_OP) => method_not_allowed(),
226219
_ => Ok(Response::builder().status(StatusCode::NOT_FOUND)
227220
.body(Body::empty())
@@ -234,7 +227,6 @@ impl<T, C> hyper::service::Service<(Request<Body>, C)> for Service<T, C> where
234227
))
235228
}
236229
}
237-
238230
/// Request parser for `Api`.
239231
pub struct ApiRequestParser;
240232
impl<T> RequestParser<T> for ApiRequestParser {

samples/server/petstore/rust-server-deprecated/output/openapi-v3/examples/client/server.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ impl<C> CallbackApi<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
112112
info!("callback_callback_with_header_post({:?}) - X-Span-ID: {:?}", information, context.get().0.clone());
113113
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
114114
}
115-
116115
async fn callback_callback_post(
117116
&self,
118117
callback_request_query_url: String,
@@ -121,5 +120,4 @@ impl<C> CallbackApi<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
121120
info!("callback_callback_post() - X-Span-ID: {:?}", context.get().0.clone());
122121
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
123122
}
124-
125123
}

0 commit comments

Comments
 (0)