Skip to content

Commit

Permalink
fix: resource ids can contain underscores and trailing characters (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster committed Jan 23, 2020
1 parent 5094bb9 commit b5460e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions typescript/src/schema/resourceDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export class ResourceDatabase {
}
return;
}
const params = pattern[0].match(/{[a-zA-Z]+}/g) || [];
const params = pattern[0].match(/{[a-zA-Z_]+(?:=.*?)?}/g) || [];
for (let i = 0; i < params.length; i++) {
params[i] = params[i].replace('{', '').replace('}', '');
params[i] = params[i].replace(/{([a-zA-Z_]+).*/, '$1');
}

const resourceDescriptor: ResourceDescriptor = Object.assign(
Expand Down
19 changes: 19 additions & 0 deletions typescript/test/unit/resourceDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,23 @@ describe('ResourceDatabase', () => {
assert.strictEqual(parentResources[1].name, resourceName);
assert.strictEqual(warnings.length, 0);
});

it('can parse different patterns into parameters', () => {
const rdb = new ResourceDatabase();
const resource: plugin.google.api.IResourceDescriptor = {
type: resourceType,
pattern: [
'lettersdigits/{abc123}/underscores/{snake_case}/trailing/{trailing=**}',
],
};

rdb.registerResource(resource, errorLocation);
const registeredResource = rdb.getResourceByType(resourceType);
assert(registeredResource);
assert.deepStrictEqual(registeredResource!.params, [
'snake_case',
'trailing',
]);
assert.strictEqual(warnings.length, 0);
});
});

0 comments on commit b5460e4

Please sign in to comment.