Skip to content

Commit ae9e2d9

Browse files
committed
feat(common): impl Default to APIVersionProvider
This is useful for context when the `APIVersionProvider` don't need to return response that may evolve at runtime, such as with the aggregator-client in the mithril-client. This also enable the new shared aggregator-client to have a default api version provider, that will always use the base `openapi.yml`, but provide a way to use another provider in its builder (for the aggregator and the client that will fetch the version discriminant based on the chain).
1 parent c891308 commit ae9e2d9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

mithril-common/src/api_version.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ impl APIVersionProvider {
7373
}
7474
}
7575

76+
impl Default for APIVersionProvider {
77+
fn default() -> Self {
78+
struct DiscriminantSourceDefault;
79+
impl ApiVersionDiscriminantSource for DiscriminantSourceDefault {
80+
fn get_discriminant(&self) -> String {
81+
// Return nonexistent discriminant to ensure the default 'openapi.yml' file is used
82+
"nonexistent-discriminant".to_string()
83+
}
84+
}
85+
86+
Self::new(Arc::new(DiscriminantSourceDefault))
87+
}
88+
}
89+
7690
#[cfg(test)]
7791
mod test {
7892
use crate::test::double::DummyApiVersionDiscriminantSource;
@@ -152,4 +166,15 @@ mod test {
152166

153167
assert!(!all_versions_sorted.is_empty());
154168
}
169+
170+
#[test]
171+
fn default_provider_returns_default_version() {
172+
let provider = APIVersionProvider::default();
173+
let version = provider.compute_current_version().unwrap();
174+
175+
assert_eq!(
176+
get_open_api_versions_mapping().get("openapi.yaml").unwrap(),
177+
&version
178+
);
179+
}
155180
}

0 commit comments

Comments
 (0)