Skip to content

Commit 1645bf7

Browse files
authored
[core-xml] Create @azure/core-xml (Azure#10307)
Create new package for serializing XML payloads
1 parent 1c108b5 commit 1645bf7

23 files changed

+1295
-21
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 58 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dataplane.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
"name": "core-tracing",
4949
"path": "sdk\\core\\core-tracing"
5050
},
51+
{
52+
"name": "core-xml",
53+
"path": "sdk\\core\\core-xml"
54+
},
5155
{
5256
"name": "cosmos",
5357
"path": "sdk\\cosmosdb\\cosmos"

rush.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@
397397
"projectFolder": "sdk/core/core-tracing",
398398
"versionPolicyName": "core"
399399
},
400+
{
401+
"packageName": "@azure/core-xml",
402+
"projectFolder": "sdk/core/core-xml",
403+
"versionPolicyName": "core"
404+
},
400405
{
401406
"packageName": "@azure/cosmos",
402407
"projectFolder": "sdk/cosmosdb/cosmos",

sdk/core/core-client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"tslib": "^2.0.0"
8686
},
8787
"devDependencies": {
88+
"@azure/core-xml": "1.0.0-preview.1",
8889
"@microsoft/api-extractor": "7.7.11",
8990
"@rollup/plugin-commonjs": "11.0.2",
9091
"@rollup/plugin-json": "^4.0.0",

sdk/core/core-client/test/deserializationPolicy.spec.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
SendRequest,
1919
RawHttpHeaders
2020
} from "@azure/core-https";
21+
import { parseXML } from "@azure/core-xml";
2122

2223
describe("deserializationPolicy", function() {
2324
it(`should not modify a request that has no request body mapper`, async function() {
@@ -68,21 +69,20 @@ describe("deserializationPolicy", function() {
6869
assert.isUndefined(response.parsedHeaders);
6970
});
7071

71-
it.skip(`with xml response body, application/xml content-type, but no operation spec`, async function() {
72+
it(`with xml response body, application/xml content-type, but no operation spec`, async function() {
7273
const response = await getDeserializedResponse({
7374
headers: { "content-type": "application/xml" },
7475
bodyAsText: `<fruit><apples>3</apples></fruit>`
7576
});
7677
assert.exists(response);
7778
assert.isUndefined(response.readableStreamBody);
7879
assert.isUndefined(response.blobBody);
79-
assert.isUndefined(response.parsedBody);
8080
assert.isUndefined(response.parsedHeaders);
8181
assert.strictEqual(response.bodyAsText, `<fruit><apples>3</apples></fruit>`);
8282
assert.deepEqual(response.parsedBody, { apples: "3" });
8383
});
8484

85-
it.skip(`with xml response body with child element with attributes and value, application/xml content-type, but no operation spec`, async function() {
85+
it(`with xml response body with child element with attributes and value, application/xml content-type, but no operation spec`, async function() {
8686
const response = await getDeserializedResponse({
8787
headers: { "content-type": "application/xml" },
8888
bodyAsText: `<fruit><apples tasty="yes">3</apples></fruit>`
@@ -103,7 +103,7 @@ describe("deserializationPolicy", function() {
103103
assert.isUndefined(response.parsedHeaders);
104104
});
105105

106-
it.skip(`with xml response body, application/xml content-type, and operation spec for only String value`, async function() {
106+
it(`with xml response body, application/xml content-type, and operation spec for only String value`, async function() {
107107
const operationSpec: OperationSpec = {
108108
httpMethod: "GET",
109109
serializer: createSerializer({}, true),
@@ -144,7 +144,7 @@ describe("deserializationPolicy", function() {
144144
assert.isUndefined(response.parsedHeaders);
145145
});
146146

147-
it.skip(`with xml response body, application/xml content-type, and operation spec for only number value`, async function() {
147+
it(`with xml response body, application/xml content-type, and operation spec for only number value`, async function() {
148148
const operationSpec: OperationSpec = {
149149
httpMethod: "GET",
150150
serializer: createSerializer({}, true),
@@ -180,11 +180,11 @@ describe("deserializationPolicy", function() {
180180
assert.isUndefined(response.readableStreamBody);
181181
assert.isUndefined(response.blobBody);
182182
assert.strictEqual(response.bodyAsText, `<fruit><apples tasty="yes">3</apples></fruit>`);
183-
assert.deepEqual(response.parsedBody, { apples: "3" });
183+
assert.deepEqual(response.parsedBody, { apples: 3 });
184184
assert.isUndefined(response.parsedHeaders);
185185
});
186186

187-
it.skip(`with xml response body, application/xml content-type, and operation spec for only headers`, async function() {
187+
it(`with xml response body, application/xml content-type, and operation spec for only headers`, async function() {
188188
const operationSpec: OperationSpec = {
189189
httpMethod: "GET",
190190
serializer: createSerializer({}, true),
@@ -235,7 +235,7 @@ describe("deserializationPolicy", function() {
235235
assert.deepEqual(response.parsedBody, { apples: { tasty: "yes" } });
236236
});
237237

238-
it.skip(`with xml response body, application/atom+xml content-type, but no operation spec`, async function() {
238+
it(`with xml response body, application/atom+xml content-type, but no operation spec`, async function() {
239239
const response = await getDeserializedResponse({
240240
headers: { "content-type": "application/xml" },
241241
bodyAsText: `<fruit><apples>3</apples></fruit>`
@@ -249,7 +249,7 @@ describe("deserializationPolicy", function() {
249249
assert.deepEqual(response.parsedBody, { apples: "3" });
250250
});
251251

252-
it.skip(`with xml property with attribute and value, application/atom+xml content-type, but no operation spec`, async function() {
252+
it(`with xml property with attribute and value, application/atom+xml content-type, but no operation spec`, async function() {
253253
const response = await getDeserializedResponse({
254254
headers: { "content-type": "application/atom+xml" },
255255
bodyAsText: `<fruit><apples taste="good">3</apples></fruit>`
@@ -270,7 +270,7 @@ describe("deserializationPolicy", function() {
270270
});
271271
});
272272

273-
it.skip(`with xml property with attribute and value, my/weird-xml content-type, but no operation spec`, async function() {
273+
it(`with xml property with attribute and value, my/weird-xml content-type, but no operation spec`, async function() {
274274
const response = await getDeserializedResponse({
275275
headers: { "content-type": "my/weird-xml" },
276276
bodyAsText: `<fruit><apples taste="good">3</apples></fruit>`,
@@ -292,7 +292,7 @@ describe("deserializationPolicy", function() {
292292
});
293293
});
294294

295-
it.skip(`with service bus response body, application/atom+xml content-type, and no operationSpec`, async function() {
295+
it(`with service bus response body, application/atom+xml content-type, and no operationSpec`, async function() {
296296
const response = await getDeserializedResponse({
297297
headers: { "content-type": "application/atom+xml;type=entry;charset=utf-8" },
298298
bodyAsText: `<entry xmlns="http://www.w3.org/2005/Atom"><id>https://daschulttest1.servicebus.windows.net/testQueuePath/?api-version=2017-04&amp;enrich=False</id><title type="text">testQueuePath</title><published>2018-10-09T19:56:34Z</published><updated>2018-10-09T19:56:35Z</updated><author><name>daschulttest1</name></author><link rel="self" href="https://daschulttest1.servicebus.windows.net/testQueuePath/?api-version=2017-04&amp;enrich=False"/><content type="application/xml"><QueueDescription xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><LockDuration>PT1M</LockDuration><MaxSizeInMegabytes>1024</MaxSizeInMegabytes><RequiresDuplicateDetection>false</RequiresDuplicateDetection><RequiresSession>false</RequiresSession><DefaultMessageTimeToLive>P14D</DefaultMessageTimeToLive><DeadLetteringOnMessageExpiration>false</DeadLetteringOnMessageExpiration><DuplicateDetectionHistoryTimeWindow>PT10M</DuplicateDetectionHistoryTimeWindow><MaxDeliveryCount>10</MaxDeliveryCount><EnableBatchedOperations>true</EnableBatchedOperations><SizeInBytes>0</SizeInBytes><MessageCount>0</MessageCount><IsAnonymousAccessible>false</IsAnonymousAccessible><AuthorizationRules></AuthorizationRules><Status>Active</Status><CreatedAt>2018-10-09T19:56:34.903Z</CreatedAt><UpdatedAt>2018-10-09T19:56:35.013Z</UpdatedAt><AccessedAt>0001-01-01T00:00:00Z</AccessedAt><SupportOrdering>true</SupportOrdering><CountDetails xmlns:d2p1="http://schemas.microsoft.com/netservices/2011/06/servicebus"><d2p1:ActiveMessageCount>0</d2p1:ActiveMessageCount><d2p1:DeadLetterMessageCount>0</d2p1:DeadLetterMessageCount><d2p1:ScheduledMessageCount>0</d2p1:ScheduledMessageCount><d2p1:TransferMessageCount>0</d2p1:TransferMessageCount><d2p1:TransferDeadLetterMessageCount>0</d2p1:TransferDeadLetterMessageCount></CountDetails><AutoDeleteOnIdle>P10675199DT2H48M5.4775807S</AutoDeleteOnIdle><EnablePartitioning>false</EnablePartitioning><EntityAvailabilityStatus>Available</EntityAvailabilityStatus><EnableExpress>false</EnableExpress></QueueDescription></content></entry>`
@@ -444,7 +444,10 @@ async function getDeserializedResponse(
444444
xmlContentTypes?: string[];
445445
} = {}
446446
): Promise<FullOperationResponse> {
447-
const policy = deserializationPolicy({ expectedContentTypes: { xml: options.xmlContentTypes } });
447+
const policy = deserializationPolicy({
448+
expectedContentTypes: { xml: options.xmlContentTypes },
449+
parseXML
450+
});
448451
const request: OperationRequest = createPipelineRequest({ url: "https://example.com" });
449452
request.additionalInfo = {
450453
operationSpec: options.operationSpec

sdk/core/core-client/test/serviceClient.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
HttpsClient,
2222
createPipelineRequest
2323
} from "@azure/core-https";
24+
import { stringifyXML } from "@azure/core-xml";
2425
import { serializeRequestBody } from "../src/serviceClient";
2526
import { getOperationArgumentValueFromParameter } from "../src/operationHelpers";
2627
import { deserializationPolicy } from "../src/deserializationPolicy";
@@ -279,12 +280,13 @@ describe("ServiceClient", function() {
279280
},
280281
responses: { 200: {} },
281282
serializer: createSerializer()
282-
}
283+
},
284+
stringifyXML
283285
);
284286
assert.strictEqual(httpRequest.body, "body value");
285287
});
286288

287-
it.skip("should serialize an XML String request body", () => {
289+
it("should serialize an XML String request body", () => {
288290
const httpRequest = createPipelineRequest({ url: "https://example.com" });
289291
serializeRequestBody(
290292
httpRequest,
@@ -306,15 +308,16 @@ describe("ServiceClient", function() {
306308
responses: { 200: {} },
307309
serializer: createSerializer(),
308310
isXML: true
309-
}
311+
},
312+
stringifyXML
310313
);
311314
assert.strictEqual(
312315
httpRequest.body,
313316
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><bodyArg>body value</bodyArg>`
314317
);
315318
});
316319

317-
it.skip("should serialize an XML ByteArray request body", () => {
320+
it("should serialize an XML ByteArray request body", () => {
318321
const httpRequest = createPipelineRequest({ url: "https://example.com" });
319322
serializeRequestBody(
320323
httpRequest,
@@ -336,15 +339,16 @@ describe("ServiceClient", function() {
336339
responses: { 200: {} },
337340
serializer: createSerializer(),
338341
isXML: true
339-
}
342+
},
343+
stringifyXML
340344
);
341345
assert.strictEqual(
342346
httpRequest.body,
343347
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><bodyArg>SmF2YXNjcmlwdA==</bodyArg>`
344348
);
345349
});
346350

347-
it.skip("should serialize an XML Stream request body", () => {
351+
it("should serialize an XML Stream request body", () => {
348352
const httpRequest = createPipelineRequest({ url: "https://example.com" });
349353
serializeRequestBody(
350354
httpRequest,
@@ -366,7 +370,8 @@ describe("ServiceClient", function() {
366370
responses: { 200: {} },
367371
serializer: createSerializer(),
368372
isXML: true
369-
}
373+
},
374+
stringifyXML
370375
);
371376
assert.strictEqual(httpRequest.body, "body value");
372377
});

sdk/core/core-xml/.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"plugins": ["@azure/azure-sdk"],
3+
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"]
4+
}

sdk/core/core-xml/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Release History
2+
3+
## 1.0.0.preview.1 (UNRELEASED)

sdk/core/core-xml/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Microsoft
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

sdk/core/core-xml/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Azure Core XML client library for JavaScript (Experimental)
2+
3+
This library is primarily intended to be used in code generated by [AutoRest](https://github.com/Azure/Autorest) and [`autorest.typescript`](https://github.com/Azure/autorest.typescript) for APIs that require parsing XML payloads.
4+
5+
## Getting started
6+
7+
### Requirements
8+
9+
- [Node.js](https://nodejs.org) version > 8.x
10+
11+
### Installation
12+
13+
This package is primarily used in generated code and not meant to be consumed directly by end users.
14+
15+
## Key concepts
16+
17+
XML parsing is mostly delegated to the browser and `xml2js`.
18+
19+
## Examples
20+
21+
Examples can be found in the `samples` folder.
22+
23+
## Next steps
24+
25+
See `@azure/core-client` for actual usage.
26+
27+
## Troubleshooting
28+
29+
If you run into issues while using this library, please feel free to [file an issue](https://github.com/Azure/azure-sdk-for-js/issues/new).
30+
31+
## Contributing
32+
33+
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test the code.
34+
35+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcore%2Fcore-client%2FREADME.png)

0 commit comments

Comments
 (0)