1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-05-10 00:20:43 +00:00

Custom Endpoints

This commit is contained in:
msrd0 2021-01-18 16:56:16 +00:00
parent 002cfb1b4d
commit 5261aa9931
28 changed files with 524 additions and 46 deletions

View file

@ -83,10 +83,14 @@ macro_rules! implOpenapiRouter {
}
static URI_PLACEHOLDER_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"(^|/):(?P<name>[^/]+)(/|$)"#).unwrap());
Lazy::new(|| Regex::new(r#"(?P<prefix>^|/):(?P<name>[^/]+)(?P<suffix>/|$)"#).unwrap());
let uri: &str = &E::uri();
let uri =
URI_PLACEHOLDER_REGEX.replace_all(uri, |captures: &Captures<'_>| format!("{{{}}}", &captures["name"]));
let uri = URI_PLACEHOLDER_REGEX.replace_all(uri, |captures: &Captures<'_>| {
format!(
"{}{{{}}}{}",
&captures["prefix"], &captures["name"], &captures["suffix"]
)
});
let path = if uri.is_empty() {
format!("{}/{}", self.0.scope.unwrap_or_default(), self.1)
} else {