From d98ae9b371988f12da5ccf42f210be34f89abb3f Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Tue, 12 Sep 2017 14:31:13 -0700 Subject: [PATCH 1/2] code changes --- Chagelog.md | 4 ++++ package.json | 2 +- src/vanilla/ClientModelExtensions.cs | 8 +------- src/vanilla/Model/MethodJs.cs | 1 + test/vanilla/AcceptanceTests/acceptanceTests.ts | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Chagelog.md b/Chagelog.md index 28073b6..d223121 100644 --- a/Chagelog.md +++ b/Chagelog.md @@ -1,2 +1,6 @@ +### 9/12/2017 - 1.9.4 +- For `"collectionFormat": "multi"` in `query` parameters, if the item type is null or undefined then we treat it as an empty string +- Removing the check that primaryType in the formatted reference value should only be a string. It can be any other primary type apart from "string". + ### 9/5/2017 - 1.9.3 - Added support for `"collectionFormat": "multi"` in `query` parameters https://github.com/Azure/autorest/issues/717. \ No newline at end of file diff --git a/package.json b/package.json index a06f1be..e8ceed9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@microsoft.azure/autorest.nodejs", - "version": "1.9.3", + "version": "1.9.4", "description": "The NodeJS extension for classic generators in AutoRest.", "scripts": { "start": "dotnet src/bin/netcoreapp2.0/autorest.nodejs.dll --server", diff --git a/src/vanilla/ClientModelExtensions.cs b/src/vanilla/ClientModelExtensions.cs index da39474..c207d23 100644 --- a/src/vanilla/ClientModelExtensions.cs +++ b/src/vanilla/ClientModelExtensions.cs @@ -28,7 +28,7 @@ public static string GetHttpMethod(this HttpMethod method) } /// - /// Format the value of a sequence given the modeled element format. Note that only sequences of strings are supported + /// Format the value of a sequence given the modeled element format. /// /// The parameter to format /// A reference to the formatted parameter value @@ -52,12 +52,6 @@ public static string GetFormattedReferenceValue(this Parameter parameter) primaryType = New(KnownPrimaryType.String); } - if (primaryType == null || primaryType.KnownPrimaryType != KnownPrimaryType.String) - { - throw new InvalidOperationException( - $"Cannot generate a formatted sequence from a non-string array parameter {parameter}"); - } - return $"{parameter.Name}.join('{parameter.CollectionFormat.GetSeparator()}')"; } diff --git a/src/vanilla/Model/MethodJs.cs b/src/vanilla/Model/MethodJs.cs index 648bb31..cd388d8 100644 --- a/src/vanilla/Model/MethodJs.cs +++ b/src/vanilla/Model/MethodJs.cs @@ -666,6 +666,7 @@ protected virtual void BuildQueryParameterArray(IndentedStringBuilder builder) .AppendLine(queryAddFormat, queryParameter.SerializedName, "''").Outdent() .AppendLine("} else {").Indent() .AppendLine("for (let item of {0}) {{", queryParameter.Name).Indent() + .AppendLine("item = (item === null || item === undefined) ? '' : item;") .AppendLine(queryAddFormat, queryParameter.SerializedName, "'' + item").Outdent() .AppendLine("}").Outdent() .AppendLine("}").Outdent(); diff --git a/test/vanilla/AcceptanceTests/acceptanceTests.ts b/test/vanilla/AcceptanceTests/acceptanceTests.ts index 5258430..2d9ef66 100644 --- a/test/vanilla/AcceptanceTests/acceptanceTests.ts +++ b/test/vanilla/AcceptanceTests/acceptanceTests.ts @@ -2611,7 +2611,7 @@ describe('nodejs', function () { describe('Url MultiFormatCollection Client', function () { var testClient = new urlMultiCollectionClient(baseUri, clientOptions); - it('should work when query parameter with collection format multi is an empty array', function (done) { + it('should work when query parameter with collection format multi is null', function (done) { testClient.queries.arrayStringMultiNull((err, result, request, response) => { should.not.exist(err); done(); From e0ee8712725a412040fe6aae9ab0eb87e4e6333d Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Tue, 12 Sep 2017 14:51:40 -0700 Subject: [PATCH 2/2] code generation changes --- .../AcceptanceTests/CustomBaseUri/operations/paths.js | 6 +++--- test/vanilla/AcceptanceTests/acceptanceTests.js | 2 +- .../UrlMultiCollectionFormat/operations/queries.js | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test/azure/Expected/AcceptanceTests/CustomBaseUri/operations/paths.js b/test/azure/Expected/AcceptanceTests/CustomBaseUri/operations/paths.js index 0a959b5..78f8f06 100644 --- a/test/azure/Expected/AcceptanceTests/CustomBaseUri/operations/paths.js +++ b/test/azure/Expected/AcceptanceTests/CustomBaseUri/operations/paths.js @@ -48,15 +48,15 @@ function _getEmpty(accountName, options, callback) { } // Validate try { - if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { - throw new Error('this.client.acceptLanguage must be of type string.'); - } if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') { throw new Error('accountName cannot be null or undefined and it must be of type string.'); } if (this.client.host === null || this.client.host === undefined || typeof this.client.host.valueOf() !== 'string') { throw new Error('this.client.host cannot be null or undefined and it must be of type string.'); } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } } catch (error) { return callback(error); } diff --git a/test/vanilla/AcceptanceTests/acceptanceTests.js b/test/vanilla/AcceptanceTests/acceptanceTests.js index afefe1d..b7a2050 100644 --- a/test/vanilla/AcceptanceTests/acceptanceTests.js +++ b/test/vanilla/AcceptanceTests/acceptanceTests.js @@ -2433,7 +2433,7 @@ describe('nodejs', function () { }); describe('Url MultiFormatCollection Client', function () { var testClient = new urlMultiCollectionClient(baseUri, clientOptions); - it('should work when query parameter with collection format multi is an empty array', function (done) { + it('should work when query parameter with collection format multi is null', function (done) { testClient.queries.arrayStringMultiNull(function (err, result, request, response) { should.not.exist(err); done(); diff --git a/test/vanilla/Expected/AcceptanceTests/UrlMultiCollectionFormat/operations/queries.js b/test/vanilla/Expected/AcceptanceTests/UrlMultiCollectionFormat/operations/queries.js index 5142d56..ee57c68 100644 --- a/test/vanilla/Expected/AcceptanceTests/UrlMultiCollectionFormat/operations/queries.js +++ b/test/vanilla/Expected/AcceptanceTests/UrlMultiCollectionFormat/operations/queries.js @@ -69,6 +69,7 @@ function _arrayStringMultiNull(options, callback) { queryParameters.push('arrayQuery=' + encodeURIComponent('')); } else { for (let item of arrayQuery) { + item = (item === null || item === undefined) ? '' : item; queryParameters.push('arrayQuery=' + encodeURIComponent('' + item)); } } @@ -188,6 +189,7 @@ function _arrayStringMultiEmpty(options, callback) { queryParameters.push('arrayQuery=' + encodeURIComponent('')); } else { for (let item of arrayQuery) { + item = (item === null || item === undefined) ? '' : item; queryParameters.push('arrayQuery=' + encodeURIComponent('' + item)); } } @@ -308,6 +310,7 @@ function _arrayStringMultiValid(options, callback) { queryParameters.push('arrayQuery=' + encodeURIComponent('')); } else { for (let item of arrayQuery) { + item = (item === null || item === undefined) ? '' : item; queryParameters.push('arrayQuery=' + encodeURIComponent('' + item)); } }