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

feat: support non-slash resource for Ads #461

Merged
merged 29 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
10aad2c
unit test case for non-slash resource
xiaozhenliu-gg5 May 5, 2020
33b28c5
logic for non-slash resource
xiaozhenliu-gg5 May 5, 2020
ce8eca5
Merge branch 'master' into non-slash-resource
xiaozhenliu-gg5 May 5, 2020
afa8379
add one more test
xiaozhenliu-gg5 May 5, 2020
132f3d0
clean up
xiaozhenliu-gg5 May 5, 2020
1a3f023
feedback
xiaozhenliu-gg5 May 5, 2020
18b7cef
Merge branch 'master' into non-slash-resource
xiaozhenliu-gg5 May 5, 2020
e1c4a57
Merge branch 'master' into non-slash-resource
xiaozhenliu-gg5 May 5, 2020
6d1d310
Merge branch 'master' into non-slash-resource
xiaozhenliu-gg5 May 6, 2020
3847fb9
Merge branch 'master' into non-slash-resource
xiaozhenliu-gg5 May 7, 2020
ef0979d
Merge branch 'master' into non-slash-resource
xiaozhenliu-gg5 May 8, 2020
9e6caa5
Merge branch 'master' of github.com:googleapis/gapic-generator-typesc…
xiaozhenliu-gg5 May 18, 2020
2fd44a4
Merge branch 'non-slash-resource' of github.com:googleapis/gapic-gene…
xiaozhenliu-gg5 May 18, 2020
e1aa440
test
xiaozhenliu-gg5 May 18, 2020
fdca0cf
fix
xiaozhenliu-gg5 May 18, 2020
12442dd
update showcase proto
xiaozhenliu-gg5 May 19, 2020
2ae5822
disable optional fields
xiaozhenliu-gg5 May 19, 2020
529f411
Merge branch 'master' of github.com:googleapis/gapic-generator-typesc…
xiaozhenliu-gg5 May 19, 2020
da1d768
update baseline
xiaozhenliu-gg5 May 19, 2020
6437849
Merge branch 'master' into non-slash-resource
xiaozhenliu-gg5 May 21, 2020
82956f2
depend on gax develop branch
xiaozhenliu-gg5 May 21, 2020
ad3e408
update baseline
xiaozhenliu-gg5 May 21, 2020
5470e58
Merge branch 'non-slash-resource' of github.com:googleapis/gapic-gene…
xiaozhenliu-gg5 May 21, 2020
f8c4c86
use master branch
xiaozhenliu-gg5 May 21, 2020
214aba2
update baseline
xiaozhenliu-gg5 May 21, 2020
c9f7613
Merge branch 'master' into non-slash-resource
xiaozhenliu-gg5 May 21, 2020
0e4fecc
update gax dependency
xiaozhenliu-gg5 May 21, 2020
40a853b
Merge branch 'master' into non-slash-resource
xiaozhenliu-gg5 May 21, 2020
b8d3cf5
Merge branch 'master' into non-slash-resource
alexander-fenster May 21, 2020
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
22 changes: 16 additions & 6 deletions typescript/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,15 @@ export function getResourceNameByPattern(pattern: string): string {
const nextEle = elements[0];
if (nextEle.match(/{[a-zA-Z_]+(?:=.*?)?}/g)) {
elements.shift();
name.push(
nextEle.substring(
1,
nextEle.includes('=') ? nextEle.indexOf('=') : nextEle.length - 1
)
);
const params = nextEle.match(/{[a-zA-Z_]+(?:=.*?)?}/g);
if (params!.length === 1) {
name.push(getChuckName(nextEle));
} else {
// For non-slash resource 'organization/{organization}/tasks/{task_id}{task_name}/result'
// Take parameters that match pattern [{task_id}, {task_name}] and combine them as part of the name.
const params = nextEle.match(/{[a-zA-Z_]+(?:=.*?)?}/g);
name.push(params?.map(p => getChuckName(p))?.join('_'));
xiaozhenliu-gg5 marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
if (eleName!.match(/{[a-zA-Z_]+(?:=.*?)?}/g)) {
continue;
Expand All @@ -176,3 +179,10 @@ export function getResourceNameByPattern(pattern: string): string {
}
return name.join('_');
}

function getChuckName(chuck: string): string {
return chuck.substring(
1,
chuck.includes('=') ? chuck.indexOf('=') : chuck.length - 1
);
}
47 changes: 47 additions & 0 deletions typescript/test/unit/resource-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ describe('src/schema/resource-database.ts', () => {
const resourcePatternSpecial1 = 'location/{location}/profile/case/{case_id}';
const resourcePatternSpecial2 = 'organization/{organization=**}/case';
const resourcePatternSpecial3 = '{organization=**}/tasks/{task}/result';
const nonSlashPatternSpecial =
'organization/{organization}/tasks/{taskId}{taskName}/result';
const nonSlashPatternSpecial2 =
'organization/{organization}/tasks/{taskId=*}{taskName}/result';
const resourceParameters = ['location', 'example'];
const parentResourceName = 'Location';
const parentResourceType = 'locations.googleapis.com/Location';
Expand Down Expand Up @@ -108,6 +112,8 @@ describe('src/schema/resource-database.ts', () => {
resourcePatternSpecial1,
resourcePatternSpecial2,
resourcePatternSpecial3,
nonSlashPatternSpecial,
nonSlashPatternSpecial2,
],
};
rdb.registerResource(resource, errorLocation);
Expand Down Expand Up @@ -138,6 +144,47 @@ describe('src/schema/resource-database.ts', () => {
);
assert(registeredResourceByPattern3);
assert.strictEqual(registeredResourceByPattern3!.name, 'task_result');

const registeredNonSlashResource = rdb.getResourceByPattern(
nonSlashPatternSpecial
);
assert(registeredNonSlashResource);
assert.strictEqual(
registeredNonSlashResource!.name,
'organization_taskId_taskName_result'
);

const registeredNonSlashResource2 = rdb.getResourceByPattern(
nonSlashPatternSpecial2
);
assert(registeredNonSlashResource2);
assert.strictEqual(
registeredNonSlashResource2!.name,
'organization_taskId_taskName_result'
);
});

it('get correct resource name for single non-slash pattern resource', () => {
const rdb = new ResourceDatabase();
const resource: plugin.google.api.IResourceDescriptor = {
type: 'examples.googleapis.com/Case',
pattern: [nonSlashPatternSpecial],
};
rdb.registerResource(resource, errorLocation);
const registeredResource = rdb.getResourceByType(
'examples.googleapis.com/Case'
);
assert(registeredResource);
assert.strictEqual(
registeredResource!.type,
'examples.googleapis.com/Case'
);

const registeredNonSlashResource = rdb.getResourceByPattern(
nonSlashPatternSpecial
);
assert(registeredNonSlashResource);
assert.strictEqual(registeredNonSlashResource!.name, 'Case');
});

it('can get registered resource by type', () => {
Expand Down