Skip to content

Commit a02ea74

Browse files
committed
Add impl responder async test for OAS 3.1
1 parent 177ef2b commit a02ea74

File tree

6 files changed

+67
-9
lines changed

6 files changed

+67
-9
lines changed

apistos-gen-test/src/tests/api_error_derive_oas_3_0.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::collections::{BTreeMap, HashSet};
77
#[test]
88
#[expect(dead_code)]
99
fn api_component_derive() {
10-
#[allow(clippy::duplicated_attributes)]
10+
#[expect(clippy::duplicated_attributes)]
1111
#[derive(ApiErrorComponent)]
1212
#[openapi_error(
1313
status(code = 403),
@@ -61,7 +61,7 @@ fn api_component_with_schema() {
6161
code: String,
6262
}
6363

64-
#[allow(clippy::duplicated_attributes)]
64+
#[expect(clippy::duplicated_attributes)]
6565
#[derive(ApiErrorComponent)]
6666
#[openapi_error(status(code = 403), status(code = 409, description = "Too many requests"))]
6767
enum ErrorResponse {

apistos-gen-test/src/tests/api_error_derive_oas_3_1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::collections::{BTreeMap, HashSet};
77
#[test]
88
#[expect(dead_code)]
99
fn api_component_derive() {
10-
#[allow(clippy::duplicated_attributes)]
10+
#[expect(clippy::duplicated_attributes)]
1111
#[derive(ApiErrorComponent)]
1212
#[openapi_error(
1313
status(code = 403),
@@ -61,7 +61,7 @@ fn api_component_with_schema() {
6161
code: String,
6262
}
6363

64-
#[allow(clippy::duplicated_attributes)]
64+
#[expect(clippy::duplicated_attributes)]
6565
#[derive(ApiErrorComponent)]
6666
#[openapi_error(status(code = 403), status(code = 409, description = "Too many requests"))]
6767
enum ErrorResponse {

apistos-gen-test/src/tests/api_operation_oas_3_0.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ mod test_models {
8080
}
8181
}
8282

83-
#[allow(clippy::duplicated_attributes)]
83+
#[expect(clippy::duplicated_attributes)]
8484
#[derive(Serialize, Deserialize, Debug, Clone, ApiErrorComponent)]
8585
#[openapi_error(status(code = 401), status(code = 403), status(code = 404), status(code = 405))]
8686
pub(crate) enum MultipleErrorResponse {
@@ -221,7 +221,7 @@ fn api_operation_impl_responder() {
221221
HttpResponse::Ok()
222222
}
223223

224-
#[allow(clippy::todo, clippy::unused_async)]
224+
#[expect(clippy::todo, clippy::unused_async, dead_code)]
225225
async fn plop() {
226226
todo!()
227227
}
@@ -287,12 +287,12 @@ fn api_operation_impl_responder() {
287287
})
288288
);
289289

290-
let components = __openapi_test_async::components();
290+
let components = __openapi_test_async::components(OpenApiVersion::OAS3_0);
291291
// only one component here because: error does not have schema and Test is used both for query and response
292292
assert_eq!(components.len(), 1);
293293
let components = serde_json::to_value(components).expect("Unable to serialize as Json");
294294

295-
let operation = __openapi_test_async::operation();
295+
let operation = __openapi_test_async::operation(OpenApiVersion::OAS3_0);
296296
let operation = serde_json::to_value(operation).expect("Unable to serialize as Json");
297297

298298
assert_json_eq!(

apistos-gen-test/src/tests/api_operation_oas_3_1.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ mod test_models {
8080
}
8181
}
8282

83-
#[allow(clippy::duplicated_attributes)]
83+
#[expect(clippy::duplicated_attributes)]
8484
#[derive(Serialize, Deserialize, Debug, Clone, ApiErrorComponent)]
8585
#[openapi_error(status(code = 401), status(code = 403), status(code = 404), status(code = 405))]
8686
pub(crate) enum MultipleErrorResponse {
@@ -209,6 +209,20 @@ fn api_operation_impl_responder() {
209209
HttpResponse::Ok()
210210
}
211211

212+
#[expect(clippy::todo, clippy::unused_async, dead_code)]
213+
async fn plop() {
214+
todo!()
215+
}
216+
217+
/// Add a new pet to the store
218+
/// Add a new pet to the store
219+
/// Plop
220+
#[api_operation(tag = "pet")]
221+
pub(crate) async fn test_async(_body: Json<test_models::Test>) -> impl Responder {
222+
plop().await;
223+
HttpResponse::Ok()
224+
}
225+
212226
let components = __openapi_test::components(OpenApiVersion::OAS3_1);
213227
// only one component here because: error does not have schema and Test is used both for query and response
214228
assert_eq!(components.len(), 1);
@@ -250,6 +264,48 @@ fn api_operation_impl_responder() {
250264
"deprecated": false
251265
})
252266
);
267+
268+
let components = __openapi_test_async::components(OpenApiVersion::OAS3_1);
269+
// only one component here because: error does not have schema and Test is used both for query and response
270+
assert_eq!(components.len(), 1);
271+
let components = serde_json::to_value(components).expect("Unable to serialize as Json");
272+
273+
let operation = __openapi_test_async::operation(OpenApiVersion::OAS3_1);
274+
let operation = serde_json::to_value(operation).expect("Unable to serialize as Json");
275+
276+
assert_json_eq!(components, json!([{}]));
277+
assert_json_eq!(
278+
operation,
279+
json!({
280+
"tags": [
281+
"pet"
282+
],
283+
"summary": "Add a new pet to the store",
284+
"description": "Add a new pet to the store\\\nPlop",
285+
"requestBody": {
286+
"content": {
287+
"application/json": {
288+
"schema": {
289+
"$schema": "https://json-schema.org/draft/2020-12/schema",
290+
"title": "Test",
291+
"type": "object",
292+
"properties": {
293+
"test": {
294+
"type": "string"
295+
}
296+
},
297+
"required": [
298+
"test"
299+
]
300+
}
301+
}
302+
},
303+
"required": true
304+
},
305+
"responses": {},
306+
"deprecated": false
307+
})
308+
);
253309
}
254310

255311
#[test]

apistos/tests/default_parameters_oas_3_1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ use apistos_rapidoc as _;
182182
use apistos_redoc as _;
183183
use apistos_scalar as _;
184184
use apistos_swagger_ui as _;
185+
use futures_util as _;
185186
use garde_actix_web as _;
186187
use indexmap as _;
187188
use log as _;

apistos/tests/query_parameters_oas_3_1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ use apistos_rapidoc as _;
278278
use apistos_redoc as _;
279279
use apistos_scalar as _;
280280
use apistos_swagger_ui as _;
281+
use futures_util as _;
281282
use indexmap as _;
282283
use log as _;
283284
use md5 as _;

0 commit comments

Comments
 (0)