From 096687b5445c72e301a1028911f11e8bfb54a0a7 Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Tue, 30 Jul 2019 19:15:46 -0700 Subject: [PATCH] Ensure that a primitive type (string, number, boolean, null, undefined) response body with or without a `bodyMapper` is not flattened. --- Changelog.md | 3 +++ lib/serviceClient.ts | 2 +- lib/util/constants.ts | 2 +- lib/util/utils.ts | 10 ++++++++++ package.json | 2 +- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 49b5cef5..46d916bd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,7 @@ # Changelog +## 2.0.4 - 2019-07-30 +- Ensure that a primitive type (string, number, boolean, null, undefined) response body with or without a `bodyMapper` is not flattened. + ## 2.0.3 - 2019-07-11 - Added support to not send default values while sending the request. - Added support to populate entities with it's default value if it is present in the mapper while deserializing the response. diff --git a/lib/serviceClient.ts b/lib/serviceClient.ts index 0a9a8af5..37b604e0 100644 --- a/lib/serviceClient.ts +++ b/lib/serviceClient.ts @@ -576,7 +576,7 @@ export function flattenResponse(_response: HttpOperationResponse, responseSpec: } } - if (bodyMapper || _response.request.method === "HEAD") { + if (bodyMapper || _response.request.method === "HEAD" || utils.isPrimitiveType(_response.parsedBody)) { // primitive body types and HEAD booleans return addOperationResponse({ ...parsedHeaders, diff --git a/lib/util/constants.ts b/lib/util/constants.ts index 5a4d0724..fd5e714a 100644 --- a/lib/util/constants.ts +++ b/lib/util/constants.ts @@ -7,7 +7,7 @@ export const Constants = { * @const * @type {string} */ - msRestVersion: "2.0.3", + msRestVersion: "2.0.4", /** * Specifies HTTP. diff --git a/lib/util/utils.ts b/lib/util/utils.ts index 2aebd651..a4557fae 100644 --- a/lib/util/utils.ts +++ b/lib/util/utils.ts @@ -249,3 +249,13 @@ export function isDuration(value: string): boolean { export function replaceAll(value: string | undefined, searchValue: string, replaceValue: string): string | undefined { return !value || !searchValue ? value : value.split(searchValue).join(replaceValue || ""); } + +/** + * Determines whether the given enity is a basic/primitive type + * (string, number, boolean, null, undefined). + * @param value Any entity + * @return boolean - true is it is primitive type, false otherwise. + */ +export function isPrimitiveType(value: any): boolean { + return (typeof value !== "object" && typeof value !== "function") || value === null; +} \ No newline at end of file diff --git a/package.json b/package.json index f65d9d47..55861e81 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "email": "azsdkteam@microsoft.com", "url": "https://github.com/Azure/ms-rest-js" }, - "version": "2.0.3", + "version": "2.0.4", "description": "Isomorphic client Runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest", "tags": [ "isomorphic",