File tree 3 files changed +28
-4
lines changed
3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,6 @@ export class API {
50
50
return (
51
51
fd . package === 'google.longrunning' ||
52
52
fd . package === 'google.cloud' ||
53
- fd . package === 'google.cloud.location' ||
54
53
fd . package === 'google.protobuf' ||
55
54
fd . package === 'google.type' ||
56
55
fd . package === 'google.rpc' ||
@@ -63,7 +62,8 @@ export class API {
63
62
fds : protos . google . protobuf . IFileDescriptorProto [ ]
64
63
) {
65
64
let filteredProtos = fds . filter ( fd => ! API . isIgnoredService ( fd ) ) ;
66
- // Special case: google.iam.v1 can be either a separate service to generate,
65
+ // Special cases: google.iam.v1 or google.cloud.location
66
+ // can be either a separate service to generate,
67
67
// or a dependency that should be ignored here
68
68
const packages = filteredProtos . reduce ( ( set , fd ) => {
69
69
set . add ( fd . package ! ) ;
@@ -74,6 +74,11 @@ export class API {
74
74
p => p . package !== 'google.iam.v1'
75
75
) ;
76
76
}
77
+ if ( packages . size > 1 && packages . has ( 'google.cloud.location' ) ) {
78
+ filteredProtos = filteredProtos . filter (
79
+ p => p . package !== 'google.cloud.location'
80
+ ) ;
81
+ }
77
82
return filteredProtos ;
78
83
}
79
84
Original file line number Diff line number Diff line change @@ -75,7 +75,8 @@ export class Naming {
75
75
const versionIndex = segments . findIndex ( segment =>
76
76
segment . match ( versionPattern )
77
77
) ;
78
- if ( versionIndex === - 1 ) {
78
+ // Special exception for location, which does not have a version
79
+ if ( versionIndex === - 1 && rootPackage !== 'google.cloud.location' ) {
79
80
throw new Error (
80
81
`ERROR: Cannot parse package name ${ rootPackage } : version does not match ${ versionPattern } .`
81
82
) ;
@@ -88,7 +89,8 @@ export class Naming {
88
89
`ERROR: Cannot parse package name ${ rootPackage } : version ${ version } is the first segment in the name.`
89
90
) ;
90
91
}
91
- const name = segments [ versionIndex - 1 ] ;
92
+ // If there is no version (in the case of location), just grab the last segment
93
+ const name = segments [ versionIndex - 1 ] || segments [ segments . length - 1 ] ;
92
94
93
95
// everything before the name is namespace
94
96
const namespaces = segments . slice ( 0 , versionIndex - 1 ) . join ( '.' ) ;
Original file line number Diff line number Diff line change @@ -91,6 +91,23 @@ describe('src/schema/api.ts', () => {
91
91
] ) ;
92
92
} ) ;
93
93
94
+ it ( 'should be able to generate google.cloud.location alone' , ( ) => {
95
+ const fd = { } as protos . google . protobuf . FileDescriptorProto ;
96
+ fd . name = 'google/cloud/location/location.proto' ;
97
+ fd . package = 'google.cloud.location' ;
98
+ fd . service = [ { } as protos . google . protobuf . ServiceDescriptorProto ] ;
99
+ fd . service [ 0 ] . name = 'IAMPolicy' ;
100
+ fd . service [ 0 ] . options = {
101
+ '.google.api.defaultHost' : 'cloud.googleapis.com' ,
102
+ } ;
103
+ const api = new API ( [ fd ] , 'google.cloud.location' , {
104
+ grpcServiceConfig : { } as protos . grpc . service_config . ServiceConfig ,
105
+ } ) ;
106
+ assert . deepStrictEqual ( api . filesToGenerate , [
107
+ 'google/cloud/location/location.proto' ,
108
+ ] ) ;
109
+ } ) ;
110
+
94
111
it ( 'should not return common protos in the proto list' , ( ) => {
95
112
const fd1 = { } as protos . google . protobuf . FileDescriptorProto ;
96
113
fd1 . name = 'google/cloud/test/v1/test.proto' ;
You can’t perform that action at this time.
0 commit comments