Skip to content

Commit

Permalink
[core-http] support x-ms-text via the new xmlIsMsText flag (Azure…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremymeng authored Oct 28, 2022
1 parent 0b91e87 commit 48deccf
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sdk/core/core-http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Release History

## 2.2.8 (Unreleased)
## 2.3.0 (Unreleased)

### Features Added

- add support for `x-ms-text`

### Breaking Changes

### Bugs Fixed
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@azure/core-http",
"sdk-type": "client",
"author": "Microsoft Corporation",
"version": "2.2.8",
"version": "2.3.0",
"description": "Isomorphic client Runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest",
"tags": [
"isomorphic",
Expand Down
1 change: 1 addition & 0 deletions sdk/core/core-http/review/core-http.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface BaseMapper {
type: MapperType;
xmlElementName?: string;
xmlIsAttribute?: boolean;
xmlIsMsText?: boolean;
xmlIsWrapped?: boolean;
xmlName?: string;
xmlNamespace?: string;
Expand Down
6 changes: 6 additions & 0 deletions sdk/core/core-http/src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,8 @@ function deserializeCompositeType(
propertyObjectName,
options
);
} else if (propertyMapper.xmlIsMsText && responseBody[XML_CHARKEY] !== undefined) {
instance[key] = responseBody[XML_CHARKEY];
} else {
const propertyName = xmlElementName || xmlName || serializedName;
if (propertyMapper.xmlIsWrapped) {
Expand Down Expand Up @@ -1302,6 +1304,10 @@ export interface BaseMapper {
* Determines if the current property should be serialized as an attribute of the parent xml element
*/
xmlIsAttribute?: boolean;
/**
* Determines if the current property should be serialized as the inner content of the xml element
*/
xmlIsMsText?: boolean;
/**
* Name for the xml elements when serializing an array
*/
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-http/src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const Constants = {
/**
* The core-http version
*/
coreHttpVersion: "2.2.8",
coreHttpVersion: "2.3.0",

/**
* Specifies HTTP.
Expand Down
40 changes: 40 additions & 0 deletions sdk/core/core-http/test/serializationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,46 @@ describe("msrest", function () {

assert.deepEqual(result, { cors: [] });
});

it("should handle xmlIsMsText flag", function () {
const stringEncoded: msRest.CompositeMapper = {
serializedName: "StringEncoded",
type: {
name: "Composite",
className: "StringEncoded",
modelProperties: {
encoded: {
serializedName: "Encoded",
xmlName: "Encoded",
xmlIsAttribute: true,
type: {
name: "Boolean",
},
},
content: {
serializedName: "content",
xmlName: "content",
xmlIsMsText: true,
type: {
name: "String",
},
},
},
},
};

const mappers = {
StringEncoded: stringEncoded,
};
const serializer = new msRest.Serializer(mappers, true);
const result: any = serializer.deserialize(
stringEncoded,
{ $: { Encoded: true }, _: "dir%EF%BF%BE0166562954291707607" },
"mockedStringEncoded"
);

assert.deepEqual(result, { encoded: true, content: "dir%EF%BF%BE0166562954291707607" });
});
});

describe("polymorphic composite type array", () => {
Expand Down

0 comments on commit 48deccf

Please sign in to comment.