1
0
Fork 0
ruma/crates/ruma-common/tests/it/api/ui/api-single-path-check.rs
Kévin Commaille 7459fbb173 api: Run rustfmt on trybuild tests
Because they are not properly included in the module hierarchy,
`cargo fmt` doesn't check them by default so we use `rustfmt` directly
to check the files by path.
2025-11-21 11:31:45 +01:00

54 lines
1.3 KiB
Rust

#![allow(unexpected_cfgs)]
use ruma_common::{
api::{Metadata, auth_scheme::AccessToken, path_builder::PathBuilder, request, response},
metadata,
};
metadata! {
method: PUT,
rate_limited: true,
authentication: AccessToken,
path: "/_matrix/other/v1/endpoint/{baz}",
}
/// Request type for the `other_endpoint` endpoint.
#[request]
pub struct Request {
// This value will be inserted into the request's URL in place of the
// "{baz}" path component.
#[ruma_api(path)]
pub baz: String,
// This value represents the full query string of the request's URL.
#[ruma_api(query_all)]
pub bar: Query,
// This is a non-JSON body.
#[ruma_api(raw_body)]
pub body: Vec<u8>,
}
/// The query parameters of the `other_endpoint` endpoint.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Query {
pub foo: String,
}
/// Response type for the `other_endpoint` endpoint.
#[response]
pub struct Response {
// This is a non-JSON body.
#[ruma_api(raw_body)]
pub body: Vec<u8>,
}
fn main() {
assert_eq!(
Request::PATH_BUILDER.all_paths().collect::<Vec<_>>(),
&["/_matrix/other/v1/endpoint/{baz}"],
);
let path = Request::PATH_BUILDER.select_path(()).unwrap();
assert_eq!(path, "/_matrix/other/v1/endpoint/{baz}");
}