diff --git a/Cargo.lock b/Cargo.lock index 8e3e97c..8e16eea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.101" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "arc-swap" @@ -3163,6 +3163,7 @@ dependencies = [ "rcgen", "reqwest", "rustapi-openapi", + "rustapi-testing", "rustapi-validate", "rustls", "rustls-pemfile", diff --git a/crates/rustapi-core/tests/snapshot_test.rs b/crates/rustapi-core/tests/snapshot_test.rs index b5dbc3a..6bc99be 100644 --- a/crates/rustapi-core/tests/snapshot_test.rs +++ b/crates/rustapi-core/tests/snapshot_test.rs @@ -1,4 +1,4 @@ -use rustapi_core::{post, Created, Json, RustApi, get}; +use rustapi_core::{get, post, Created, Json, RustApi}; use rustapi_openapi::Schema; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -211,34 +211,34 @@ async fn test_openapi_snapshot() { assert_eq!(output, output2, "Nondeterministic output detected!"); } - #[derive(Debug, Deserialize, Schema)] - struct CreatePin { +#[derive(Debug, Deserialize, Schema)] +struct CreatePin { title: String, - } +} - #[derive(Debug, Serialize, Schema)] - struct PinResponse { +#[derive(Debug, Serialize, Schema)] +struct PinResponse { id: i64, title: String, - } +} - async fn create_pin(Json(body): Json) -> Created { +async fn create_pin(Json(body): Json) -> Created { Created(PinResponse { - id: 1, - title: body.title, + id: 1, + title: body.title, }) - } +} - #[test] - fn test_manual_route_registers_openapi_components_for_body_refs() { +#[test] +fn test_manual_route_registers_openapi_components_for_body_refs() { use rustapi_openapi::schema::RustApiSchema; let app = RustApi::new().route("/pins", post(create_pin)); let spec = app.openapi_spec(); assert!( - spec.validate_integrity().is_ok(), - "manual route OpenAPI spec should not contain dangling $ref values" + spec.validate_integrity().is_ok(), + "manual route OpenAPI spec should not contain dangling $ref values" ); let components = spec.components.as_ref().expect("components should exist"); @@ -251,15 +251,15 @@ async fn test_openapi_snapshot() { let path_item = spec.paths.get("/pins").expect("/pins path should exist"); let op = path_item.post.as_ref().expect("POST /pins should exist"); let media_type = op - .request_body - .as_ref() - .and_then(|body| body.content.get("application/json")) - .expect("request body media type should exist"); + .request_body + .as_ref() + .and_then(|body| body.content.get("application/json")) + .expect("request body media type should exist"); match media_type.schema.as_ref().expect("schema should exist") { - rustapi_openapi::SchemaRef::Ref { reference } => { - assert_eq!(reference, "#/components/schemas/CreatePin"); - } - other => panic!("expected request body schema ref, got {other:?}"), + rustapi_openapi::SchemaRef::Ref { reference } => { + assert_eq!(reference, "#/components/schemas/CreatePin"); + } + other => panic!("expected request body schema ref, got {other:?}"), } - } +} diff --git a/crates/rustapi-openapi/src/spec.rs b/crates/rustapi-openapi/src/spec.rs index f1c5b4b..d2dd17b 100644 --- a/crates/rustapi-openapi/src/spec.rs +++ b/crates/rustapi-openapi/src/spec.rs @@ -58,9 +58,7 @@ impl OpenApiSpec { version: version.into(), ..Default::default() }, - json_schema_dialect: Some( - "https://spec.openapis.org/oas/3.1/dialect/base".to_string(), - ), + json_schema_dialect: Some("https://spec.openapis.org/oas/3.1/dialect/base".to_string()), servers: Vec::new(), paths: BTreeMap::new(), webhooks: BTreeMap::new(),