Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add api resource option to resourceDatabase #211

Merged
merged 3 commits into from
Jan 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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