diff --git a/typescript/src/schema/api.ts b/typescript/src/schema/api.ts index 73c722226..6ab68f24f 100644 --- a/typescript/src/schema/api.ts +++ b/typescript/src/schema/api.ts @@ -118,9 +118,11 @@ export class API { get protoFilesToGenerateJSON() { return JSON.stringify( - this.filesToGenerate.map(file => { - return `../../protos/${file}`; - }), + this.filesToGenerate + .map(file => { + return `../../protos/${file}`; + }) + .sort(), null, ' ' ); diff --git a/typescript/test/testdata/dlp/src/v2/dlp_service_proto_list.json.baseline b/typescript/test/testdata/dlp/src/v2/dlp_service_proto_list.json.baseline index 8e267f82e..482924bde 100644 --- a/typescript/test/testdata/dlp/src/v2/dlp_service_proto_list.json.baseline +++ b/typescript/test/testdata/dlp/src/v2/dlp_service_proto_list.json.baseline @@ -1,4 +1,4 @@ [ - "../../protos/google/privacy/dlp/v2/storage.proto", - "../../protos/google/privacy/dlp/v2/dlp.proto" + "../../protos/google/privacy/dlp/v2/dlp.proto", + "../../protos/google/privacy/dlp/v2/storage.proto" ] diff --git a/typescript/test/unit/api.ts b/typescript/test/unit/api.ts index 6954172e1..cdd2e53be 100644 --- a/typescript/test/unit/api.ts +++ b/typescript/test/unit/api.ts @@ -109,4 +109,27 @@ describe('schema/api.ts', () => { }); assert.deepStrictEqual(api.mainServiceName, 'OverriddenName'); }); + + it('should return list of protos in lexicographical order', () => { + const fd1 = new plugin.google.protobuf.FileDescriptorProto(); + fd1.name = 'google/cloud/example/v1/test.proto'; + fd1.package = 'google.cloud.example.v1'; + + fd1.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; + fd1.service[0].name = 'Service'; + fd1.service[0].options = { + '.google.api.defaultHost': 'hostname.example.com:443', + }; + const fd2 = new plugin.google.protobuf.FileDescriptorProto(); + fd2.name = 'google/cloud/example/v1/example.proto'; + fd2.package = 'google.cloud.example.v1'; + fd2.service = []; + const api = new API([fd1, fd2], 'google.cloud.example.v1', { + grpcServiceConfig: new plugin.grpc.service_config.ServiceConfig(), + }); + assert.deepStrictEqual(JSON.parse(api.protoFilesToGenerateJSON), [ + '../../protos/google/cloud/example/v1/example.proto', + '../../protos/google/cloud/example/v1/test.proto', + ]); + }); });