Skip to content

Commit cfa8072

Browse files
authored
Merge pull request #2678 from murgatroid99/reflection_no_package_fix
reflection: Fix references to symbols with no package
2 parents c10d973 + 0207979 commit cfa8072

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

packages/grpc-reflection/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/reflection",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"author": {
55
"name": "Google Inc."
66
},

packages/grpc-reflection/proto/sample/sample.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'unscoped.proto';
88
service SampleService {
99
rpc Hello (HelloRequest) returns (HelloResponse) {}
1010
rpc Hello2 (HelloRequest) returns (CommonMessage) {}
11+
rpc Hello3 (ProcessRequest) returns (TopLevelMessage) {}
1112
}
1213

1314
service IgnoreService {

packages/grpc-reflection/src/implementations/reflection-v1.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@ export class ReflectionV1Implementation {
113113

114114
let referencedFile: IFileDescriptorProto | null = null;
115115
if (ref.startsWith('.')) {
116-
// absolute reference -- just remove the leading '.' and use the ref directly
117-
referencedFile = this.symbols[ref.slice(1)];
116+
/* absolute reference -- In files with no package, symbols are
117+
* populated in the symbols table with a leading period in the key.
118+
* If there is a package, the symbol does not have a leading period in
119+
* the key. For simplicity, we check without the period, then with it.
120+
*/
121+
referencedFile = this.symbols[ref.slice(1)] ?? this.symbols[ref];
118122
} else {
119123
// relative reference -- need to seek upwards up the current package scope until we find it
120124
let pkg = pkgScope;
@@ -315,7 +319,7 @@ export class ReflectionV1Implementation {
315319
private getFileDependencies(file: IFileDescriptorProto): IFileDescriptorProto[] {
316320
const visited: Set<IFileDescriptorProto> = new Set();
317321
const toVisit: IFileDescriptorProto[] = [...(this.fileDependencies.get(file) || [])];
318-
322+
319323
while (toVisit.length > 0) {
320324
const current = toVisit.pop();
321325

packages/grpc-reflection/test/test-reflection-v1-implementation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('GrpcReflectionService', () => {
5151
const names = descriptors.map((desc) => desc.name);
5252
assert.deepEqual(
5353
new Set(names),
54-
new Set(['sample.proto', 'vendor.proto', 'vendor_dependency.proto'])
54+
new Set(['root.proto', 'sample.proto', 'vendor.proto', 'vendor_dependency.proto'])
5555
);
5656
});
5757

@@ -99,7 +99,7 @@ describe('GrpcReflectionService', () => {
9999
const names = descriptors.map((desc) => desc.name);
100100
assert.deepEqual(
101101
new Set(names),
102-
new Set(['sample.proto', 'vendor.proto', 'vendor_dependency.proto']),
102+
new Set(['root.proto', 'sample.proto', 'vendor.proto', 'vendor_dependency.proto']),
103103
);
104104
});
105105

@@ -129,7 +129,7 @@ describe('GrpcReflectionService', () => {
129129
const names = descriptors.map((desc) => desc.name);
130130
assert.deepEqual(
131131
new Set(names),
132-
new Set(['sample.proto', 'vendor.proto', 'vendor_dependency.proto']),
132+
new Set(['root.proto', 'sample.proto', 'vendor.proto', 'vendor_dependency.proto']),
133133
);
134134
});
135135

@@ -169,7 +169,7 @@ describe('GrpcReflectionService', () => {
169169
const names = descriptors.map((desc) => desc.name);
170170
assert.deepEqual(
171171
new Set(names),
172-
new Set(['sample.proto', 'vendor.proto', 'vendor_dependency.proto']),
172+
new Set(['root.proto', 'sample.proto', 'vendor.proto', 'vendor_dependency.proto']),
173173
);
174174
});
175175
});

0 commit comments

Comments
 (0)