Skip to content

Commit

Permalink
fix: add api resource option to resourceDatabase (#211)
Browse files Browse the repository at this point in the history
* add api resource option to resourceDatabase

* lint

Co-authored-by: Alexander Fenster <github@fenster.name>
  • Loading branch information
xiaozhenliu-gg5 and alexander-fenster committed Jan 31, 2020
1 parent 90177c6 commit 7ea7034
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions typescript/src/schema/proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,21 @@ function augmentService(
const uniqueResources: { [name: string]: ResourceDescriptor } = {};
for (const property of Object.keys(messages)) {
const errorLocation = `service ${service.name} message ${property}`;
// take the option['.google.api.resource'] of the message as resource, add it to resourceDatabase id it's not there.
const descriptorProto = messages[property];
if (
descriptorProto.options &&
descriptorProto.options['.google.api.resource']
) {
const resource = descriptorProto.options['.google.api.resource'];
if (!resourceDatabase.getResourceByType(resource.type)) {
resourceDatabase.registerResource(resource);
const registeredResource = resourceDatabase.getResourceByType(
resource.type
)!;
uniqueResources[registeredResource.name] = registeredResource;
}
}
for (const fieldDescriptor of messages[property].field ?? []) {
// note: ResourceDatabase can accept `undefined` values, so we happily use optional chaining here.
const resourceReference =
Expand Down

0 comments on commit 7ea7034

Please sign in to comment.