diff --git a/lib/msRest.ts b/lib/msRest.ts index 91e278f..89b293e 100644 --- a/lib/msRest.ts +++ b/lib/msRest.ts @@ -23,7 +23,7 @@ import { stripRequest, stripResponse, delay, executePromisesSequentially, generateUuid, encodeUri, ServiceCallback, promiseToCallback, promiseToServiceCallback, isValidUuid, dispatchRequest, - applyMixins, isNode, stringifyXML + applyMixins, isNode, stringifyXML, prepareXMLRootList } from "./util/utils"; // Credentials @@ -40,5 +40,5 @@ export { BasicAuthenticationCredentials, ApiKeyCredentials, ApiKeyCredentialOptions, ServiceClientCredentials, BaseFilter, LogFilter, ServiceClientOptions, ExponentialRetryPolicyFilter, SystemErrorRetryPolicyFilter, SigningFilter, MsRestUserAgentFilter, stripRequest, stripResponse, delay, executePromisesSequentially, generateUuid, isValidUuid, encodeUri, RestError, RequestOptionsBase, RequestFunction, ServiceCallback, promiseToCallback, - promiseToServiceCallback, isStream, dispatchRequest, RedirectFilter, applyMixins, isNode, stringifyXML + promiseToServiceCallback, isStream, dispatchRequest, RedirectFilter, applyMixins, isNode, stringifyXML, prepareXMLRootList }; diff --git a/lib/util/utils.ts b/lib/util/utils.ts index a7513c4..eec064d 100644 --- a/lib/util/utils.ts +++ b/lib/util/utils.ts @@ -8,7 +8,7 @@ import { Constants } from "./constants"; import { RestError } from "../restError"; import { HttpOperationResponse } from "../httpOperationResponse"; import * as xml2js from "xml2js"; -import { promisify } from "util"; +import { promisify, isArray } from "util"; /** * Provides the fetch() method based on the environment. @@ -279,6 +279,13 @@ export function stringifyXML(obj: any, opts?: { rootName?: string }) { return builder.buildObject(obj); } +export function prepareXMLRootList(obj: any, elementName: string) { + if (!isArray(obj)) { + obj = [obj]; + } + return { [elementName]: obj }; +} + /** * Sends the request and returns the received response. * @param {WebResource} options - The request to be sent.