@@ -50,6 +50,17 @@ const GOOGLE_DISCOVERY_SERVICE_OVERRIDES: Record<string, GoogleDiscoveryServiceO
5050 } ,
5151} ;
5252
53+ const googleDiscoveryUrlForService = (
54+ service : string ,
55+ version : string ,
56+ host = `${ service } .googleapis.com` ,
57+ ) : string => {
58+ const override = GOOGLE_DISCOVERY_SERVICE_OVERRIDES [ service ] ;
59+ return override ?. preserveServiceHostedUrl === true
60+ ? `https://${ host } /$discovery/rest?version=${ version } `
61+ : `${ DISCOVERY_SERVICE_HOST } /${ service } /${ version } /rest` ;
62+ } ;
63+
5364type JsonPrimitive = string | number | boolean | null ;
5465type JsonValue = JsonPrimitive | readonly JsonValue [ ] | { readonly [ key : string ] : JsonValue } ;
5566
@@ -288,7 +299,7 @@ export const normalizeGoogleDiscoveryUrl = (discoveryUrl: string): string | null
288299 const match = parsed . pathname . match ( DISCOVERY_SERVICE_PATH_RE ) ;
289300 const service = match ?. [ 1 ] ;
290301 const version = match ?. [ 2 ] ;
291- return service && version ? ` ${ DISCOVERY_SERVICE_HOST } / ${ service } / ${ version } /rest` : null ;
302+ return service && version ? googleDiscoveryUrlForService ( service , version ) : null ;
292303 }
293304
294305 const service = serviceFromGoogleApisHost ( host ) ;
@@ -305,10 +316,7 @@ export const normalizeGoogleDiscoveryUrl = (discoveryUrl: string): string | null
305316 ) {
306317 return null ;
307318 }
308- const override = GOOGLE_DISCOVERY_SERVICE_OVERRIDES [ service ] ;
309- return override ?. preserveServiceHostedUrl === true
310- ? `https://${ host } /$discovery/rest?version=${ version } `
311- : `${ DISCOVERY_SERVICE_HOST } /${ service } /${ version } /rest` ;
319+ return googleDiscoveryUrlForService ( service , version , host ) ;
312320} ;
313321
314322const normalizeDiscoveryUrl = ( discoveryUrl : string ) : string => {
0 commit comments