Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions crates/rustapi-core/tests/snapshot_test.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<CreatePin>) -> Created<PinResponse> {
async fn create_pin(Json(body): Json<CreatePin>) -> Created<PinResponse> {
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");
Expand All @@ -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:?}"),
}
}
}
4 changes: 1 addition & 3 deletions crates/rustapi-openapi/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading