@@ -283,7 +283,9 @@ export const normalizeGoogleDiscoveryUrl = (discoveryUrl: string): string | null
283283 ) {
284284 return null ;
285285 }
286- return `${ DISCOVERY_SERVICE_HOST } /${ service } /${ version } /rest` ;
286+ return service === "photospicker"
287+ ? `https://${ host } /$discovery/rest?version=${ version } `
288+ : `${ DISCOVERY_SERVICE_HOST } /${ service } /${ version } /rest` ;
287289} ;
288290
289291const normalizeDiscoveryUrl = ( discoveryUrl : string ) : string => {
@@ -679,12 +681,39 @@ const GOOGLE_OAUTH_SECURITY_SCHEME = "googleOAuth2";
679681const GOOGLE_PHOTOS_LIBRARY_SERVICE = "photoslibrary" ;
680682const GOOGLE_PHOTOS_PICKER_SERVICE = "photospicker" ;
681683const GOOGLE_PHOTOS_APPENDONLY_SCOPE = "https://www.googleapis.com/auth/photoslibrary.appendonly" ;
684+ const GOOGLE_PHOTOS_PICKER_SCOPE =
685+ "https://www.googleapis.com/auth/photospicker.mediaitems.readonly" ;
686+ const GOOGLE_PHOTOS_PICKER_SCOPE_DESCRIPTION = "Read selected Google Photos media" ;
682687const GOOGLE_PHOTOS_UPLOAD_TOOL_PATH = "photoslibrary.mediaItems.upload" ;
683688const GOOGLE_PHOTOS_UPLOAD_PATH = "/uploads" ;
684689
685690const isGooglePhotosService = ( service : string ) : boolean =>
686691 service === GOOGLE_PHOTOS_LIBRARY_SERVICE || service === GOOGLE_PHOTOS_PICKER_SERVICE ;
687692
693+ const discoveryScopesForService = (
694+ service : string ,
695+ document : DiscoveryDocument ,
696+ ) : Record < string , string > => {
697+ const scopes = discoveryScopes ( document ) ;
698+ if ( service !== GOOGLE_PHOTOS_PICKER_SERVICE || scopes [ GOOGLE_PHOTOS_PICKER_SCOPE ] !== undefined ) {
699+ return scopes ;
700+ }
701+ return {
702+ ...scopes ,
703+ [ GOOGLE_PHOTOS_PICKER_SCOPE ] : GOOGLE_PHOTOS_PICKER_SCOPE_DESCRIPTION ,
704+ } ;
705+ } ;
706+
707+ const discoveryMethodScopesForService = (
708+ service : string ,
709+ method : DiscoveryMethod ,
710+ ) : readonly string [ ] => {
711+ const scopes = method . scopes ?? [ ] ;
712+ return service === GOOGLE_PHOTOS_PICKER_SERVICE && scopes . length === 0
713+ ? [ GOOGLE_PHOTOS_PICKER_SCOPE ]
714+ : scopes ;
715+ } ;
716+
688717/** The v2 oauth auth template for a Google-discovery integration. The spec
689718 * itself carries the matching `securitySchemes.googleOAuth2` entry; this is the
690719 * catalog-level template a connection's access token renders through. */
@@ -811,6 +840,7 @@ export const convertGoogleDiscoveryToOpenApi = Effect.fn("OpenApi.convertGoogleD
811840 method,
812841 toolPath,
813842 pathTemplate : pathTemplate . startsWith ( "/" ) ? pathTemplate : `/${ pathTemplate } ` ,
843+ oauthScopes : discoveryMethodScopesForService ( service , method ) ,
814844 } ) ;
815845 }
816846
@@ -826,7 +856,7 @@ export const convertGoogleDiscoveryToOpenApi = Effect.fn("OpenApi.convertGoogleD
826856 } ) ;
827857 }
828858
829- const scopes = compactDiscoveryScopeMap ( discoveryScopes ( document ) ) ;
859+ const scopes = compactDiscoveryScopeMap ( discoveryScopesForService ( service , document ) ) ;
830860 const authenticationTemplate = googleOauthTemplate ( scopes ) ;
831861
832862 const spec : OpenApiDocument = {
@@ -923,7 +953,7 @@ export const convertGoogleDiscoveryBundleToOpenApi = Effect.fn(
923953 for ( const info of infos ) {
924954 const schemaPrefix = schemaComponentPart ( `${ info . service } _${ info . version } ` ) ;
925955 const schemaNameForRef = ( name : string ) => `${ schemaPrefix } _${ schemaComponentPart ( name ) } ` ;
926- const scopeDescriptions = discoveryScopes ( info . document ) ;
956+ const scopeDescriptions = discoveryScopesForService ( info . service , info . document ) ;
927957 const filterPhotosScopes = consentScopeSet !== null && isGooglePhotosService ( info . service ) ;
928958
929959 for ( const [ scope , description ] of Object . entries ( scopeDescriptions ) ) {
@@ -939,7 +969,7 @@ export const convertGoogleDiscoveryBundleToOpenApi = Effect.fn(
939969 const methodId = Option . getOrUndefined ( method . id ) ;
940970 const rawPathTemplate = Option . getOrUndefined ( method . path ) ;
941971 if ( ! methodId || ! rawPathTemplate || ! method . httpMethod ) continue ;
942- const methodScopes = method . scopes ?? [ ] ;
972+ const methodScopes = discoveryMethodScopesForService ( info . service , method ) ;
943973 const oauthScopes = filterPhotosScopes
944974 ? methodScopes . filter ( ( scope ) => consentScopeSet . has ( scope ) )
945975 : methodScopes ;
0 commit comments