Skip to content

Commit

Permalink
Add impl responder async test for OAS 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rlebran committed Sep 20, 2024
1 parent 177ef2b commit a02ea74
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apistos-gen-test/src/tests/api_error_derive_oas_3_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::collections::{BTreeMap, HashSet};
#[test]
#[expect(dead_code)]
fn api_component_derive() {
#[allow(clippy::duplicated_attributes)]
#[expect(clippy::duplicated_attributes)]
#[derive(ApiErrorComponent)]
#[openapi_error(
status(code = 403),
Expand Down Expand Up @@ -61,7 +61,7 @@ fn api_component_with_schema() {
code: String,
}

#[allow(clippy::duplicated_attributes)]
#[expect(clippy::duplicated_attributes)]
#[derive(ApiErrorComponent)]
#[openapi_error(status(code = 403), status(code = 409, description = "Too many requests"))]
enum ErrorResponse {
Expand Down
4 changes: 2 additions & 2 deletions apistos-gen-test/src/tests/api_error_derive_oas_3_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::collections::{BTreeMap, HashSet};
#[test]
#[expect(dead_code)]
fn api_component_derive() {
#[allow(clippy::duplicated_attributes)]
#[expect(clippy::duplicated_attributes)]
#[derive(ApiErrorComponent)]
#[openapi_error(
status(code = 403),
Expand Down Expand Up @@ -61,7 +61,7 @@ fn api_component_with_schema() {
code: String,
}

#[allow(clippy::duplicated_attributes)]
#[expect(clippy::duplicated_attributes)]
#[derive(ApiErrorComponent)]
#[openapi_error(status(code = 403), status(code = 409, description = "Too many requests"))]
enum ErrorResponse {
Expand Down
8 changes: 4 additions & 4 deletions apistos-gen-test/src/tests/api_operation_oas_3_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod test_models {
}
}

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

#[allow(clippy::todo, clippy::unused_async)]
#[expect(clippy::todo, clippy::unused_async, dead_code)]
async fn plop() {
todo!()
}
Expand Down Expand Up @@ -287,12 +287,12 @@ fn api_operation_impl_responder() {
})
);

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

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

assert_json_eq!(
Expand Down
58 changes: 57 additions & 1 deletion apistos-gen-test/src/tests/api_operation_oas_3_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod test_models {
}
}

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

#[expect(clippy::todo, clippy::unused_async, dead_code)]
async fn plop() {
todo!()
}

/// Add a new pet to the store
/// Add a new pet to the store
/// Plop
#[api_operation(tag = "pet")]
pub(crate) async fn test_async(_body: Json<test_models::Test>) -> impl Responder {
plop().await;
HttpResponse::Ok()
}

let components = __openapi_test::components(OpenApiVersion::OAS3_1);
// only one component here because: error does not have schema and Test is used both for query and response
assert_eq!(components.len(), 1);
Expand Down Expand Up @@ -250,6 +264,48 @@ fn api_operation_impl_responder() {
"deprecated": false
})
);

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

let operation = __openapi_test_async::operation(OpenApiVersion::OAS3_1);
let operation = serde_json::to_value(operation).expect("Unable to serialize as Json");

assert_json_eq!(components, json!([{}]));
assert_json_eq!(
operation,
json!({
"tags": [
"pet"
],
"summary": "Add a new pet to the store",
"description": "Add a new pet to the store\\\nPlop",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Test",
"type": "object",
"properties": {
"test": {
"type": "string"
}
},
"required": [
"test"
]
}
}
},
"required": true
},
"responses": {},
"deprecated": false
})
);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions apistos/tests/default_parameters_oas_3_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ use apistos_rapidoc as _;
use apistos_redoc as _;
use apistos_scalar as _;
use apistos_swagger_ui as _;
use futures_util as _;
use garde_actix_web as _;
use indexmap as _;
use log as _;
Expand Down
1 change: 1 addition & 0 deletions apistos/tests/query_parameters_oas_3_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ use apistos_rapidoc as _;
use apistos_redoc as _;
use apistos_scalar as _;
use apistos_swagger_ui as _;
use futures_util as _;
use indexmap as _;
use log as _;
use md5 as _;
Expand Down

0 comments on commit a02ea74

Please sign in to comment.