diff --git a/baselines/disable-packing-test/src/v1beta1/echo_client.ts.baseline b/baselines/disable-packing-test/src/v1beta1/echo_client.ts.baseline index 120b081d1..7c9f1cc0b 100644 --- a/baselines/disable-packing-test/src/v1beta1/echo_client.ts.baseline +++ b/baselines/disable-packing-test/src/v1beta1/echo_client.ts.baseline @@ -160,7 +160,7 @@ export class EchoClient { userPathTemplate: new this._gaxModule.PathTemplate( 'users/{user_id}' ), - userIdBlurbIdPathTemplate: new this._gaxModule.PathTemplate( + userIdProfileBlurbIdPathTemplate: new this._gaxModule.PathTemplate( 'user/{user_id}/profile/blurbs/{blurb_id}' ), }; @@ -893,39 +893,39 @@ export class EchoClient { } /** - * Return a fully-qualified userIdBlurbId resource name string. + * Return a fully-qualified userIdProfileBlurbId resource name string. * * @param {string} user_id * @param {string} blurb_id * @returns {string} Resource name string. */ - userIdBlurbIdPath(userId:string,blurbId:string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.render({ + userIdProfileBlurbIdPath(userId:string,blurbId:string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.render({ user_id: userId, blurb_id: blurbId, }); } /** - * Parse the user_id from UserIdBlurbId resource. + * Parse the user_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the user_id. */ - matchUserIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).user_id; + matchUserIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).user_id; } /** - * Parse the blurb_id from UserIdBlurbId resource. + * Parse the blurb_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the blurb_id. */ - matchBlurbIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).blurb_id; + matchBlurbIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).blurb_id; } /** diff --git a/baselines/disable-packing-test/src/v1beta1/identity_client.ts.baseline b/baselines/disable-packing-test/src/v1beta1/identity_client.ts.baseline index 286023774..b3edf3441 100644 --- a/baselines/disable-packing-test/src/v1beta1/identity_client.ts.baseline +++ b/baselines/disable-packing-test/src/v1beta1/identity_client.ts.baseline @@ -155,7 +155,7 @@ export class IdentityClient { userPathTemplate: new this._gaxModule.PathTemplate( 'users/{user_id}' ), - userIdBlurbIdPathTemplate: new this._gaxModule.PathTemplate( + userIdProfileBlurbIdPathTemplate: new this._gaxModule.PathTemplate( 'user/{user_id}/profile/blurbs/{blurb_id}' ), }; @@ -838,39 +838,39 @@ export class IdentityClient { } /** - * Return a fully-qualified userIdBlurbId resource name string. + * Return a fully-qualified userIdProfileBlurbId resource name string. * * @param {string} user_id * @param {string} blurb_id * @returns {string} Resource name string. */ - userIdBlurbIdPath(userId:string,blurbId:string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.render({ + userIdProfileBlurbIdPath(userId:string,blurbId:string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.render({ user_id: userId, blurb_id: blurbId, }); } /** - * Parse the user_id from UserIdBlurbId resource. + * Parse the user_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the user_id. */ - matchUserIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).user_id; + matchUserIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).user_id; } /** - * Parse the blurb_id from UserIdBlurbId resource. + * Parse the blurb_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the blurb_id. */ - matchBlurbIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).blurb_id; + matchBlurbIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).blurb_id; } /** diff --git a/baselines/disable-packing-test/src/v1beta1/messaging_client.ts.baseline b/baselines/disable-packing-test/src/v1beta1/messaging_client.ts.baseline index 4480342b1..7c21f8e28 100644 --- a/baselines/disable-packing-test/src/v1beta1/messaging_client.ts.baseline +++ b/baselines/disable-packing-test/src/v1beta1/messaging_client.ts.baseline @@ -159,7 +159,7 @@ export class MessagingClient { userPathTemplate: new this._gaxModule.PathTemplate( 'users/{user_id}' ), - userIdBlurbIdPathTemplate: new this._gaxModule.PathTemplate( + userIdProfileBlurbIdPathTemplate: new this._gaxModule.PathTemplate( 'user/{user_id}/profile/blurbs/{blurb_id}' ), }; @@ -1423,39 +1423,39 @@ export class MessagingClient { } /** - * Return a fully-qualified userIdBlurbId resource name string. + * Return a fully-qualified userIdProfileBlurbId resource name string. * * @param {string} user_id * @param {string} blurb_id * @returns {string} Resource name string. */ - userIdBlurbIdPath(userId:string,blurbId:string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.render({ + userIdProfileBlurbIdPath(userId:string,blurbId:string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.render({ user_id: userId, blurb_id: blurbId, }); } /** - * Parse the user_id from UserIdBlurbId resource. + * Parse the user_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the user_id. */ - matchUserIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).user_id; + matchUserIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).user_id; } /** - * Parse the blurb_id from UserIdBlurbId resource. + * Parse the blurb_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the blurb_id. */ - matchBlurbIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).blurb_id; + matchBlurbIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).blurb_id; } /** diff --git a/baselines/disable-packing-test/src/v1beta1/testing_client.ts.baseline b/baselines/disable-packing-test/src/v1beta1/testing_client.ts.baseline index 5b12a6e47..c0adac96b 100644 --- a/baselines/disable-packing-test/src/v1beta1/testing_client.ts.baseline +++ b/baselines/disable-packing-test/src/v1beta1/testing_client.ts.baseline @@ -156,7 +156,7 @@ export class TestingClient { userPathTemplate: new this._gaxModule.PathTemplate( 'users/{user_id}' ), - userIdBlurbIdPathTemplate: new this._gaxModule.PathTemplate( + userIdProfileBlurbIdPathTemplate: new this._gaxModule.PathTemplate( 'user/{user_id}/profile/blurbs/{blurb_id}' ), }; @@ -1095,39 +1095,39 @@ export class TestingClient { } /** - * Return a fully-qualified userIdBlurbId resource name string. + * Return a fully-qualified userIdProfileBlurbId resource name string. * * @param {string} user_id * @param {string} blurb_id * @returns {string} Resource name string. */ - userIdBlurbIdPath(userId:string,blurbId:string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.render({ + userIdProfileBlurbIdPath(userId:string,blurbId:string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.render({ user_id: userId, blurb_id: blurbId, }); } /** - * Parse the user_id from UserIdBlurbId resource. + * Parse the user_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the user_id. */ - matchUserIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).user_id; + matchUserIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).user_id; } /** - * Parse the blurb_id from UserIdBlurbId resource. + * Parse the blurb_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the blurb_id. */ - matchBlurbIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).blurb_id; + matchBlurbIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).blurb_id; } /** diff --git a/baselines/showcase/src/v1beta1/echo_client.ts.baseline b/baselines/showcase/src/v1beta1/echo_client.ts.baseline index 120b081d1..7c9f1cc0b 100644 --- a/baselines/showcase/src/v1beta1/echo_client.ts.baseline +++ b/baselines/showcase/src/v1beta1/echo_client.ts.baseline @@ -160,7 +160,7 @@ export class EchoClient { userPathTemplate: new this._gaxModule.PathTemplate( 'users/{user_id}' ), - userIdBlurbIdPathTemplate: new this._gaxModule.PathTemplate( + userIdProfileBlurbIdPathTemplate: new this._gaxModule.PathTemplate( 'user/{user_id}/profile/blurbs/{blurb_id}' ), }; @@ -893,39 +893,39 @@ export class EchoClient { } /** - * Return a fully-qualified userIdBlurbId resource name string. + * Return a fully-qualified userIdProfileBlurbId resource name string. * * @param {string} user_id * @param {string} blurb_id * @returns {string} Resource name string. */ - userIdBlurbIdPath(userId:string,blurbId:string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.render({ + userIdProfileBlurbIdPath(userId:string,blurbId:string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.render({ user_id: userId, blurb_id: blurbId, }); } /** - * Parse the user_id from UserIdBlurbId resource. + * Parse the user_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the user_id. */ - matchUserIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).user_id; + matchUserIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).user_id; } /** - * Parse the blurb_id from UserIdBlurbId resource. + * Parse the blurb_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the blurb_id. */ - matchBlurbIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).blurb_id; + matchBlurbIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).blurb_id; } /** diff --git a/baselines/showcase/src/v1beta1/identity_client.ts.baseline b/baselines/showcase/src/v1beta1/identity_client.ts.baseline index 286023774..b3edf3441 100644 --- a/baselines/showcase/src/v1beta1/identity_client.ts.baseline +++ b/baselines/showcase/src/v1beta1/identity_client.ts.baseline @@ -155,7 +155,7 @@ export class IdentityClient { userPathTemplate: new this._gaxModule.PathTemplate( 'users/{user_id}' ), - userIdBlurbIdPathTemplate: new this._gaxModule.PathTemplate( + userIdProfileBlurbIdPathTemplate: new this._gaxModule.PathTemplate( 'user/{user_id}/profile/blurbs/{blurb_id}' ), }; @@ -838,39 +838,39 @@ export class IdentityClient { } /** - * Return a fully-qualified userIdBlurbId resource name string. + * Return a fully-qualified userIdProfileBlurbId resource name string. * * @param {string} user_id * @param {string} blurb_id * @returns {string} Resource name string. */ - userIdBlurbIdPath(userId:string,blurbId:string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.render({ + userIdProfileBlurbIdPath(userId:string,blurbId:string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.render({ user_id: userId, blurb_id: blurbId, }); } /** - * Parse the user_id from UserIdBlurbId resource. + * Parse the user_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the user_id. */ - matchUserIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).user_id; + matchUserIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).user_id; } /** - * Parse the blurb_id from UserIdBlurbId resource. + * Parse the blurb_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the blurb_id. */ - matchBlurbIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).blurb_id; + matchBlurbIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).blurb_id; } /** diff --git a/baselines/showcase/src/v1beta1/messaging_client.ts.baseline b/baselines/showcase/src/v1beta1/messaging_client.ts.baseline index 4480342b1..7c21f8e28 100644 --- a/baselines/showcase/src/v1beta1/messaging_client.ts.baseline +++ b/baselines/showcase/src/v1beta1/messaging_client.ts.baseline @@ -159,7 +159,7 @@ export class MessagingClient { userPathTemplate: new this._gaxModule.PathTemplate( 'users/{user_id}' ), - userIdBlurbIdPathTemplate: new this._gaxModule.PathTemplate( + userIdProfileBlurbIdPathTemplate: new this._gaxModule.PathTemplate( 'user/{user_id}/profile/blurbs/{blurb_id}' ), }; @@ -1423,39 +1423,39 @@ export class MessagingClient { } /** - * Return a fully-qualified userIdBlurbId resource name string. + * Return a fully-qualified userIdProfileBlurbId resource name string. * * @param {string} user_id * @param {string} blurb_id * @returns {string} Resource name string. */ - userIdBlurbIdPath(userId:string,blurbId:string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.render({ + userIdProfileBlurbIdPath(userId:string,blurbId:string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.render({ user_id: userId, blurb_id: blurbId, }); } /** - * Parse the user_id from UserIdBlurbId resource. + * Parse the user_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the user_id. */ - matchUserIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).user_id; + matchUserIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).user_id; } /** - * Parse the blurb_id from UserIdBlurbId resource. + * Parse the blurb_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the blurb_id. */ - matchBlurbIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).blurb_id; + matchBlurbIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).blurb_id; } /** diff --git a/baselines/showcase/src/v1beta1/testing_client.ts.baseline b/baselines/showcase/src/v1beta1/testing_client.ts.baseline index 5b12a6e47..c0adac96b 100644 --- a/baselines/showcase/src/v1beta1/testing_client.ts.baseline +++ b/baselines/showcase/src/v1beta1/testing_client.ts.baseline @@ -156,7 +156,7 @@ export class TestingClient { userPathTemplate: new this._gaxModule.PathTemplate( 'users/{user_id}' ), - userIdBlurbIdPathTemplate: new this._gaxModule.PathTemplate( + userIdProfileBlurbIdPathTemplate: new this._gaxModule.PathTemplate( 'user/{user_id}/profile/blurbs/{blurb_id}' ), }; @@ -1095,39 +1095,39 @@ export class TestingClient { } /** - * Return a fully-qualified userIdBlurbId resource name string. + * Return a fully-qualified userIdProfileBlurbId resource name string. * * @param {string} user_id * @param {string} blurb_id * @returns {string} Resource name string. */ - userIdBlurbIdPath(userId:string,blurbId:string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.render({ + userIdProfileBlurbIdPath(userId:string,blurbId:string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.render({ user_id: userId, blurb_id: blurbId, }); } /** - * Parse the user_id from UserIdBlurbId resource. + * Parse the user_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the user_id. */ - matchUserIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).user_id; + matchUserIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).user_id; } /** - * Parse the blurb_id from UserIdBlurbId resource. + * Parse the blurb_id from UserIdProfileBlurbId resource. * - * @param {string} userIdBlurbIdName - * A fully-qualified path representing user_id_blurb_id resource. + * @param {string} userIdProfileBlurbIdName + * A fully-qualified path representing user_id_profile_blurb_id resource. * @returns {string} A string representing the blurb_id. */ - matchBlurbIdFromUserIdBlurbIdName(userIdBlurbIdName: string) { - return this._pathTemplates.userIdBlurbIdPathTemplate.match(userIdBlurbIdName).blurb_id; + matchBlurbIdFromUserIdProfileBlurbIdName(userIdProfileBlurbIdName: string) { + return this._pathTemplates.userIdProfileBlurbIdPathTemplate.match(userIdProfileBlurbIdName).blurb_id; } /** diff --git a/typescript/src/schema/resource-database.ts b/typescript/src/schema/resource-database.ts index 97a906a55..08f7943e8 100644 --- a/typescript/src/schema/resource-database.ts +++ b/typescript/src/schema/resource-database.ts @@ -13,6 +13,7 @@ // limitations under the License. import * as plugin from '../../../pbjs-genfiles/plugin'; +import { getResourceNameByPattern } from '../util'; export interface ResourceDescriptor extends plugin.google.api.IResourceDescriptor { @@ -90,7 +91,7 @@ export class ResourceDatabase { if (params.length === 0) { continue; } - const name = params.join('_'); + const name = getResourceNameByPattern(pattern); let resourceDescriptor: ResourceDescriptor = { name, params, diff --git a/typescript/src/util.ts b/typescript/src/util.ts index 230b79a1a..ec547afb4 100644 --- a/typescript/src/util.ts +++ b/typescript/src/util.ts @@ -141,3 +141,38 @@ Array.prototype.toSnakeCaseString = function( ): string { return this.map(part => part.toSnakeCase()).join(joiner); }; + +export function getResourceNameByPattern(pattern: string): string { + const elements = pattern.split('/'); + const name = []; + // Multi pattern like: `projects/{project}/cmekSettings`, we need to append `cmekSettings` to the name. + // Or it will be duplicate with `project/{project}` + // Iterate the elements, if it comes in pairs: user/{userId}, we take `userId` as part of the name. + // if it comes as `profile` with no following `/{profile_id}`, we take `profile` as part of the name. + // So for pattern: `user/{user_id}/profile/blurbs/{blurb_id}`, name will be `userId_profile_blurbId` + while (elements.length > 0) { + const eleName = elements.shift(); + if (elements.length === 0) { + name.push(eleName); + break; + } else { + 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 + ) + ); + } else { + if (eleName!.match(/{[a-zA-Z_]+(?:=.*?)?}/g)) { + continue; + } else { + name.push(eleName); + } + } + } + } + return name.join('_'); +} diff --git a/typescript/test/unit/resource-database.ts b/typescript/test/unit/resource-database.ts index a817cf07f..07ee70a62 100644 --- a/typescript/test/unit/resource-database.ts +++ b/typescript/test/unit/resource-database.ts @@ -25,6 +25,9 @@ describe('src/schema/resource-database.ts', () => { const resourceType = 'examples.googleapis.com/Example'; const resourcePattern = 'locations/{location}/examples/{example}'; const resourcePattern2 = 'project/{project}/examples/{example}'; + const resourcePatternSpecial1 = 'location/{location}/profile/case/{case_id}'; + const resourcePatternSpecial2 = 'organization/{organization=**}/case'; + const resourcePatternSpecial3 = '{organization=**}/tasks/{task}/result'; const resourceParameters = ['location', 'example']; const parentResourceName = 'Location'; const parentResourceType = 'locations.googleapis.com/Location'; @@ -80,7 +83,6 @@ describe('src/schema/resource-database.ts', () => { type: resourceType, pattern: [resourcePattern, resourcePattern2], }; - rdb.registerResource(resource, errorLocation); const resourceByType = rdb.getResourceByType(resourceType); assert.deepStrictEqual(resourceByType!.pattern, [ @@ -98,6 +100,46 @@ describe('src/schema/resource-database.ts', () => { assert.strictEqual(warnings.length, 0); }); + it('get correct resource name for special patterns', () => { + const rdb = new ResourceDatabase(); + const resource: plugin.google.api.IResourceDescriptor = { + type: 'examples.googleapis.com/Case', + pattern: [ + resourcePatternSpecial1, + resourcePatternSpecial2, + resourcePatternSpecial3, + ], + }; + rdb.registerResource(resource, errorLocation); + const registeredResource = rdb.getResourceByType( + 'examples.googleapis.com/Case' + ); + assert(registeredResource); + assert.strictEqual( + registeredResource!.type, + 'examples.googleapis.com/Case' + ); + const registeredResourceByPattern = rdb.getResourceByPattern( + resourcePatternSpecial1 + ); + assert(registeredResourceByPattern); + assert.strictEqual( + registeredResourceByPattern!.name, + 'location_profile_case_id' + ); + const registeredResourceByPattern2 = rdb.getResourceByPattern( + resourcePatternSpecial2 + ); + assert(registeredResourceByPattern2); + assert.strictEqual(registeredResourceByPattern2!.name, 'organization_case'); + + const registeredResourceByPattern3 = rdb.getResourceByPattern( + resourcePatternSpecial3 + ); + assert(registeredResourceByPattern3); + assert.strictEqual(registeredResourceByPattern3!.name, 'task_result'); + }); + it('can get registered resource by type', () => { const rdb = new ResourceDatabase(); const resource: plugin.google.api.IResourceDescriptor = {