@@ -159,12 +159,18 @@ pub struct VerifierClient {
159159#[ derive( Debug ) ]
160160pub struct VerifierClientBuilder < ' a > {
161161 config : Option < & ' a Config > ,
162+ api_version : Option < String > ,
163+ skip_version_detection : bool ,
162164}
163165
164166impl < ' a > VerifierClientBuilder < ' a > {
165167 /// Create a new builder instance
166168 pub fn new ( ) -> Self {
167- Self { config : None }
169+ Self {
170+ config : None ,
171+ api_version : None ,
172+ skip_version_detection : false ,
173+ }
168174 }
169175
170176 /// Set the configuration for the client
@@ -173,18 +179,55 @@ impl<'a> VerifierClientBuilder<'a> {
173179 self
174180 }
175181
182+ /// Set a specific API version to use
183+ ///
184+ /// When set, this version will be used instead of automatic detection.
185+ /// Typically used with `skip_version_detection()` for cases where the
186+ /// API version is known in advance (e.g., push-model requires v3.0).
187+ pub fn api_version ( mut self , version : & str ) -> Self {
188+ self . api_version = Some ( version. to_string ( ) ) ;
189+ self
190+ }
191+
192+ /// Skip automatic API version detection
193+ ///
194+ /// When set, the client will not attempt to detect the API version
195+ /// from the server. Use with `api_version()` to specify the version
196+ /// explicitly, or the default version (2.1) will be used.
197+ pub fn skip_version_detection ( mut self ) -> Self {
198+ self . skip_version_detection = true ;
199+ self
200+ }
201+
176202 /// Build the VerifierClient with automatic API version detection
177203 ///
178204 /// This is the recommended way to create a client for production use,
179205 /// as it will automatically detect the optimal API version supported
180206 /// by the verifier service.
207+ ///
208+ /// If `skip_version_detection()` was called, version detection is skipped.
209+ /// If `api_version()` was called, that version is used instead of detection.
181210 pub async fn build ( self ) -> Result < VerifierClient , KeylimectlError > {
182211 let config = self . config . ok_or_else ( || {
183212 KeylimectlError :: validation (
184213 "Configuration is required for VerifierClient" ,
185214 )
186215 } ) ?;
187216
217+ // If version detection is skipped, create client without detection
218+ if self . skip_version_detection {
219+ let mut client =
220+ VerifierClient :: new_without_version_detection ( config) ?;
221+
222+ // If specific API version was requested, set it
223+ if let Some ( version) = self . api_version {
224+ client. api_version = version;
225+ }
226+
227+ return Ok ( client) ;
228+ }
229+
230+ // Otherwise, use normal version detection
188231 VerifierClient :: new ( config) . await
189232 }
190233}
@@ -274,7 +317,8 @@ impl VerifierClient {
274317 ///
275318 /// Initializes a new `VerifierClient` with the provided configuration
276319 /// using the default API version without attempting to detect the
277- /// server's supported version. This is mainly useful for testing.
320+ /// server's supported version. This is mainly useful for testing and
321+ /// when the API version is known in advance (e.g., push-model).
278322 ///
279323 /// # Arguments
280324 ///
@@ -290,7 +334,7 @@ impl VerifierClient {
290334 /// - TLS certificate files cannot be read
291335 /// - Certificate/key files are invalid
292336 /// - HTTP client initialization fails
293- pub ( crate ) fn new_without_version_detection (
337+ pub fn new_without_version_detection (
294338 config : & Config ,
295339 ) -> Result < Self , KeylimectlError > {
296340 let base_url = config. verifier_base_url ( ) ;
@@ -1948,6 +1992,52 @@ mod tests {
19481992 }
19491993 }
19501994
1995+ #[ tokio:: test]
1996+ async fn test_builder_with_explicit_api_version ( ) {
1997+ let config = create_test_config ( ) ;
1998+ let client = VerifierClient :: builder ( )
1999+ . config ( & config)
2000+ . api_version ( "3.0" )
2001+ . skip_version_detection ( )
2002+ . build ( )
2003+ . await ;
2004+
2005+ assert ! ( client. is_ok( ) ) ;
2006+ let client = client. unwrap ( ) ;
2007+ assert_eq ! ( client. api_version, "3.0" ) ;
2008+ }
2009+
2010+ #[ tokio:: test]
2011+ async fn test_builder_skip_version_detection ( ) {
2012+ let config = create_test_config ( ) ;
2013+ let client = VerifierClient :: builder ( )
2014+ . config ( & config)
2015+ . skip_version_detection ( )
2016+ . build ( )
2017+ . await ;
2018+
2019+ assert ! ( client. is_ok( ) ) ;
2020+ let client = client. unwrap ( ) ;
2021+ // Should use default version when skipping detection
2022+ assert_eq ! ( client. api_version, "2.1" ) ;
2023+ }
2024+
2025+ #[ tokio:: test]
2026+ async fn test_builder_with_custom_version ( ) {
2027+ let config = create_test_config ( ) ;
2028+ let client = VerifierClient :: builder ( )
2029+ . config ( & config)
2030+ . api_version ( "3.0" )
2031+ . skip_version_detection ( )
2032+ . build ( )
2033+ . await ;
2034+
2035+ assert ! ( client. is_ok( ) ) ;
2036+ let client = client. unwrap ( ) ;
2037+ // Should use the specified version
2038+ assert_eq ! ( client. api_version, "3.0" ) ;
2039+ }
2040+
19512041 #[ test]
19522042 fn test_client_struct_fields ( ) {
19532043 let config = create_test_config ( ) ;
0 commit comments