Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions dataplane.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
"name": "core-tracing",
"path": "sdk\\core\\core-tracing"
},
{
"name": "core-xml",
"path": "sdk\\core\\core-xml"
},
{
"name": "cosmos",
"path": "sdk\\cosmosdb\\cosmos"
Expand Down
5 changes: 5 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@
"projectFolder": "sdk/core/core-tracing",
"versionPolicyName": "core"
},
{
"packageName": "@azure/core-xml",
"projectFolder": "sdk/core/core-xml",
"versionPolicyName": "core"
},
{
"packageName": "@azure/cosmos",
"projectFolder": "sdk/cosmosdb/cosmos",
Expand Down
1 change: 1 addition & 0 deletions sdk/core/core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"tslib": "^2.0.0"
},
"devDependencies": {
"@azure/core-xml": "1.0.0-preview.1",
"@microsoft/api-extractor": "7.7.11",
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-json": "^4.0.0",
Expand Down
27 changes: 15 additions & 12 deletions sdk/core/core-client/test/deserializationPolicy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SendRequest,
RawHttpHeaders
} from "@azure/core-https";
import { parseXML } from "@azure/core-xml";

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

it.skip(`with xml response body, application/xml content-type, but no operation spec`, async function() {
it(`with xml response body, application/xml content-type, but no operation spec`, async function() {
const response = await getDeserializedResponse({
headers: { "content-type": "application/xml" },
bodyAsText: `<fruit><apples>3</apples></fruit>`
});
assert.exists(response);
assert.isUndefined(response.readableStreamBody);
assert.isUndefined(response.blobBody);
assert.isUndefined(response.parsedBody);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious what leads to this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I converted the tests I rewrote some of the assertions... and because many test assertions are similar I was copy pasting a lot. Since the tests were disabled though I didn't notice my copypaste errors. 😅

assert.isUndefined(response.parsedHeaders);
assert.strictEqual(response.bodyAsText, `<fruit><apples>3</apples></fruit>`);
assert.deepEqual(response.parsedBody, { apples: "3" });
});

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

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

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

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

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

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

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

it.skip(`with service bus response body, application/atom+xml content-type, and no operationSpec`, async function() {
it(`with service bus response body, application/atom+xml content-type, and no operationSpec`, async function() {
const response = await getDeserializedResponse({
headers: { "content-type": "application/atom+xml;type=entry;charset=utf-8" },
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>`
Expand Down Expand Up @@ -444,7 +444,10 @@ async function getDeserializedResponse(
xmlContentTypes?: string[];
} = {}
): Promise<FullOperationResponse> {
const policy = deserializationPolicy({ expectedContentTypes: { xml: options.xmlContentTypes } });
const policy = deserializationPolicy({
expectedContentTypes: { xml: options.xmlContentTypes },
parseXML
});
const request: OperationRequest = createPipelineRequest({ url: "https://example.com" });
request.additionalInfo = {
operationSpec: options.operationSpec
Expand Down
19 changes: 12 additions & 7 deletions sdk/core/core-client/test/serviceClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
HttpsClient,
createPipelineRequest
} from "@azure/core-https";
import { stringifyXML } from "@azure/core-xml";
import { serializeRequestBody } from "../src/serviceClient";
import { getOperationArgumentValueFromParameter } from "../src/operationHelpers";
import { deserializationPolicy } from "../src/deserializationPolicy";
Expand Down Expand Up @@ -279,12 +280,13 @@ describe("ServiceClient", function() {
},
responses: { 200: {} },
serializer: createSerializer()
}
},
stringifyXML
);
assert.strictEqual(httpRequest.body, "body value");
});

it.skip("should serialize an XML String request body", () => {
it("should serialize an XML String request body", () => {
const httpRequest = createPipelineRequest({ url: "https://example.com" });
serializeRequestBody(
httpRequest,
Expand All @@ -306,15 +308,16 @@ describe("ServiceClient", function() {
responses: { 200: {} },
serializer: createSerializer(),
isXML: true
}
},
stringifyXML
);
assert.strictEqual(
httpRequest.body,
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><bodyArg>body value</bodyArg>`
);
});

it.skip("should serialize an XML ByteArray request body", () => {
it("should serialize an XML ByteArray request body", () => {
const httpRequest = createPipelineRequest({ url: "https://example.com" });
serializeRequestBody(
httpRequest,
Expand All @@ -336,15 +339,16 @@ describe("ServiceClient", function() {
responses: { 200: {} },
serializer: createSerializer(),
isXML: true
}
},
stringifyXML
);
assert.strictEqual(
httpRequest.body,
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><bodyArg>SmF2YXNjcmlwdA==</bodyArg>`
);
});

it.skip("should serialize an XML Stream request body", () => {
it("should serialize an XML Stream request body", () => {
const httpRequest = createPipelineRequest({ url: "https://example.com" });
serializeRequestBody(
httpRequest,
Expand All @@ -366,7 +370,8 @@ describe("ServiceClient", function() {
responses: { 200: {} },
serializer: createSerializer(),
isXML: true
}
},
stringifyXML
);
assert.strictEqual(httpRequest.body, "body value");
});
Expand Down
4 changes: 4 additions & 0 deletions sdk/core/core-xml/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["@azure/azure-sdk"],
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"]
}
3 changes: 3 additions & 0 deletions sdk/core/core-xml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Release History

## 1.0.0.preview.1 (UNRELEASED)
21 changes: 21 additions & 0 deletions sdk/core/core-xml/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
35 changes: 35 additions & 0 deletions sdk/core/core-xml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Azure Core XML client library for JavaScript (Experimental)

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.

## Getting started

### Requirements

- [Node.js](https://nodejs.org) version > 8.x

### Installation

This package is primarily used in generated code and not meant to be consumed directly by end users.

## Key concepts

XML parsing is mostly delegated to the browser and `xml2js`.

## Examples

Examples can be found in the `samples` folder.

## Next steps

See `@azure/core-client` for actual usage.

## Troubleshooting

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).

## Contributing

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.

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcore%2Fcore-client%2FREADME.png)
Loading