pub fn assert_openapi_snapshot<S>(source: &S, path: impl AsRef<Path>)where
S: OpenApiSource + ?Sized,Expand description
Compare an OpenAPI document with the snapshot at path (see the module
docs for normalization and RWS_UPDATE_SNAPSHOTS). source is the
document’s text (app.openapi_spec(&config)), a TestResponse of it, or
a TestClient whose app serves /openapi.json.
Panics with a diff on a mismatch, and when the document isn’t JSON or
has no openapi version field (a 404 page is no snapshot).
use rust_web_server::app::App;
use rust_web_server::openapi::OpenApiConfig;
use rust_web_server::response::{Response, STATUS_CODE_REASON_PHRASE};
use rust_web_server::test_client::{assert_openapi_snapshot, TestClient};
let app = App::with_state(())
.get("/users/:id", |_req, _params, _conn, _state| {
Response::get_response(STATUS_CODE_REASON_PHRASE.n200_ok, None, None)
})
.openapi(OpenApiConfig::new("Users", "1.0.0"));
assert_openapi_snapshot(&TestClient::new(app), "tests/snapshots/openapi.json");