diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-22 17:04:30 +0000 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-22 17:04:30 +0000 |
| commit | 5eb207b0c5989d886e671372023bdb66abb679db (patch) | |
| tree | bc5efe7b528b7537fd76f48309f7633635ddd39c /src | |
| parent | 1dab76d396a008d92dcdf43a61ca6877ba3f1780 (diff) | |
| download | genenetwork4-5eb207b0c5989d886e671372023bdb66abb679db.tar.gz | |
next: say which links are templates, instead of leaving braces to guess
A scan reply carried "/groups/BXD/genotypes/%7Bversion%7D/markers/.../classes?
trait={trait_id}" and "/groups/unlisted/genotypes/{name}/frequencies" in `next`,
where the documented rule is that following a `next` link is a GET that answers
200. Those two are shapes, not addresses: the trait id a scan cannot know, a
file name no group lists. The test suite skipped hrefs with braces, so the rule
held only by exemption.
NextAction gains `template: true` for exactly those, set wherever a link is
added (so no call site has to remember), and absent otherwise -- a caller can
now tell "follow this" from "fill this in" without pattern-matching on
punctuation.
Diffstat (limited to 'src')
| -rw-r--r-- | src/response.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/response.rs b/src/response.rs index 46db64a..c2a6cc9 100644 --- a/src/response.rs +++ b/src/response.rs @@ -186,10 +186,24 @@ pub struct Envelope<T: Serialize + utoipa::ToSchema> { pub struct NextAction { /// Endpoint to call, relative to the API root, e.g. "/species/mouse". pub href: String, + /// True when `href` is a *shape* rather than an address: it still contains + /// a `{placeholder}` the caller substitutes (a trait id the scan does not + /// know, a genotype file name no group lists). Every other link is a `GET` + /// that answers 200 as it stands -- that is the promise `next` makes, and + /// a caller has to be able to tell the two apart without pattern-matching + /// on braces, or it follows a template and gets a 404 (measured: a scan + /// reply carried "/groups/BXD/genotypes/%7Bversion%7D/markers/..."). + #[serde(skip_serializing_if = "std::ops::Not::not")] + pub template: bool, /// What this call gives you, e.g. "Drill down into one species". pub description: String, } +/// Whether a `next` href still holds a placeholder. +fn is_template(href: &str) -> bool { + href.contains('{') || href.contains("%7B") +} + /// A suggested call that is not a plain `GET`, so it cannot live in /// `next`: following a `next` link is a `GET` that returns 200, which is /// what makes those links safe to follow blindly (and what the test @@ -215,6 +229,7 @@ impl<T: Serialize + utoipa::ToSchema> Envelope<T> { pub fn with_next(mut self, href: &str, description: &str) -> Self { self.next.push(NextAction { href: href.to_string(), + template: is_template(href), description: description.to_string(), }); self @@ -256,6 +271,7 @@ impl<T: Serialize + utoipa::ToSchema> Envelope<T> { continue; } self.next.push(NextAction { + template: is_template(&href), href, description: description.to_string(), }); |
