From 2356554031d71ddae8a6f807da28546ffb8564a3 Mon Sep 17 00:00:00 2001 From: xiaozhenliugg Date: Fri, 24 Jan 2020 11:25:42 -0800 Subject: [PATCH 1/2] add api resource option to resourceDatabase --- typescript/src/schema/proto.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/typescript/src/schema/proto.ts b/typescript/src/schema/proto.ts index 4aef9bd79..61d567114 100644 --- a/typescript/src/schema/proto.ts +++ b/typescript/src/schema/proto.ts @@ -528,6 +528,16 @@ 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 = From 0fac7c6ff957cfc4e14898fb1394642a575f4350 Mon Sep 17 00:00:00 2001 From: xiaozhenliugg Date: Fri, 24 Jan 2020 11:30:21 -0800 Subject: [PATCH 2/2] lint --- typescript/src/schema/proto.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/typescript/src/schema/proto.ts b/typescript/src/schema/proto.ts index 61d567114..e69c3ba51 100644 --- a/typescript/src/schema/proto.ts +++ b/typescript/src/schema/proto.ts @@ -530,11 +530,16 @@ function augmentService( 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)){ + 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)!; + const registeredResource = resourceDatabase.getResourceByType( + resource.type + )!; uniqueResources[registeredResource.name] = registeredResource; } }