api: Make metadata path field optional

This commit is contained in:
Jonas Platte 2022-02-13 10:55:11 +01:00
parent 4ccf79cb67
commit 457726017b
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
5 changed files with 7 additions and 7 deletions

View File

@ -47,7 +47,6 @@ impl Api {
let description = &metadata.description;
let method = &metadata.method;
let name = &metadata.name;
let path = &metadata.path;
let unstable_path = util::map_option_literal(&metadata.unstable_path);
let r0_path = util::map_option_literal(&metadata.r0_path);
let stable_path = util::map_option_literal(&metadata.stable_path);
@ -75,6 +74,7 @@ impl Api {
}
})
.collect();
let path = util::map_option_literal(&metadata.path);
let added = util::map_option_literal(&metadata.added);
let deprecated = util::map_option_literal(&metadata.deprecated);
let removed = util::map_option_literal(&metadata.removed);

View File

@ -46,7 +46,7 @@ pub struct Metadata {
pub name: LitStr,
/// The path field. (deprecated)
pub path: EndpointPath,
pub path: Option<EndpointPath>,
/// The unstable path field.
pub unstable_path: Option<EndpointPath>,
@ -179,7 +179,7 @@ impl Parse for Metadata {
description: description.ok_or_else(|| missing_field("description"))?,
method: method.ok_or_else(|| missing_field("method"))?,
name: name.ok_or_else(|| missing_field("name"))?,
path: path.ok_or_else(|| missing_field("path"))?,
path,
unstable_path,
r0_path,
stable_path,

View File

@ -22,7 +22,7 @@ pub struct Metadata {
pub name: &'static str,
/// (DEPRECATED)
pub path: &'static str,
pub path: Option<&'static str>,
/// The unstable path of this endpoint's URL, often `None`, used for developmental
/// purposes.

View File

@ -28,7 +28,7 @@ const METADATA: Metadata = Metadata {
description: "Add an alias to a room.",
method: Method::PUT,
name: "create_alias",
path: "/_matrix/client/r0/directory/room/:room_alias",
path: Some("/_matrix/client/r0/directory/room/:room_alias"),
unstable_path: None,
r0_path: None,
stable_path: None,
@ -52,7 +52,7 @@ impl OutgoingRequest for Request {
// FIXME: properly integrate
_considering_versions: &'_ [MatrixVersion],
) -> Result<http::Request<T>, IntoHttpError> {
let url = (base_url.to_owned() + METADATA.path)
let url = (base_url.to_owned() + METADATA.path.unwrap())
.replace(":room_alias", &self.room_alias.to_string());
let request_body = RequestBody { room_id: self.room_id };

View File

@ -11,7 +11,7 @@ const BASE: Metadata = Metadata {
description: "",
method: Method::GET,
name: "test_endpoint",
path: "/depr/path",
path: Some("/depr/path"),
unstable_path: Some("/unstable/path"),
r0_path: Some("/r0/path"),
stable_path: Some("/stable/path"),