Skip to content

Commit

Permalink
Ensure that a primitive type (string, number, boolean, null, undefine…
Browse files Browse the repository at this point in the history
…d) response body with or without a `bodyMapper` is not flattened.
  • Loading branch information
amarzavery committed Jul 31, 2019
1 parent 401b56e commit 096687b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/serviceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const Constants = {
* @const
* @type {string}
*/
msRestVersion: "2.0.3",
msRestVersion: "2.0.4",

/**
* Specifies HTTP.
Expand Down
10 changes: 10 additions & 0 deletions lib/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 096687b

Please sign in to comment.