зеркало из https://github.com/Azure/ms-rest-js.git
Copy attributes back post de-serializing array
This commit is contained in:
Родитель
ef37d563d7
Коммит
2315bfb63c
|
@ -735,7 +735,15 @@ function deserializeCompositeType(
|
|||
// paging
|
||||
if (Array.isArray(responseBody[key]) && modelProps[key].serializedName === "") {
|
||||
propertyInstance = responseBody[key];
|
||||
instance = serializer.deserialize(propertyMapper, propertyInstance, propertyObjectName);
|
||||
const arrayInstance = serializer.deserialize(propertyMapper, propertyInstance, propertyObjectName);
|
||||
// Copy over any properties that have already been added into the instance, where they do
|
||||
// not exist on the newly de-serialized array
|
||||
Object.entries(instance).forEach(([key, value]) => {
|
||||
if (!arrayInstance.hasOwnProperty(key)) {
|
||||
arrayInstance[key] = value;
|
||||
}
|
||||
});
|
||||
instance = arrayInstance
|
||||
} else if (propertyInstance !== undefined || propertyMapper.defaultValue !== undefined) {
|
||||
serializedValue = serializer.deserialize(
|
||||
propertyMapper,
|
||||
|
|
|
@ -473,6 +473,36 @@ internalMappers.ProductListResultNextLink = {
|
|||
},
|
||||
},
|
||||
};
|
||||
internalMappers.ProductListResultNextLinkFirst = {
|
||||
required: false,
|
||||
serializedName: "ProductListResultNextLinkFirst",
|
||||
type: {
|
||||
name: "Composite",
|
||||
className: "ProductListResultNextLinkFirst",
|
||||
modelProperties: {
|
||||
nextLink: {
|
||||
serializedName: "nextLink",
|
||||
required: false,
|
||||
type: {
|
||||
name: "String",
|
||||
},
|
||||
},
|
||||
value: {
|
||||
serializedName: "",
|
||||
required: false,
|
||||
type: {
|
||||
name: "Sequence",
|
||||
element: {
|
||||
type: {
|
||||
name: "Composite",
|
||||
className: "Product",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
internalMappers.SawShark = {
|
||||
required: false,
|
||||
serializedName: "sawshark",
|
||||
|
|
|
@ -1100,6 +1100,50 @@ describe("msrest", function () {
|
|||
done();
|
||||
});
|
||||
|
||||
it("should correctly deserialize a pageable type with nextLink first in mapper", function (done) {
|
||||
const client = new TestClient("http://localhost:9090");
|
||||
const mapper = Mappers.ProductListResultNextLinkFirst;
|
||||
const responseBody = {
|
||||
value: [
|
||||
{
|
||||
id: 101,
|
||||
name: "TestProduct",
|
||||
properties: {
|
||||
provisioningState: "Succeeded",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 104,
|
||||
name: "TestProduct1",
|
||||
properties: {
|
||||
provisioningState: "Failed",
|
||||
},
|
||||
},
|
||||
],
|
||||
nextLink: "https://helloworld.com",
|
||||
};
|
||||
const deserializedProduct = client.serializer.deserialize(
|
||||
mapper,
|
||||
responseBody,
|
||||
"responseBody"
|
||||
);
|
||||
Array.isArray(deserializedProduct).should.be.true;
|
||||
deserializedProduct.length.should.equal(2);
|
||||
deserializedProduct.nextLink.should.equal("https://helloworld.com");
|
||||
for (let i = 0; i < deserializedProduct.length; i++) {
|
||||
if (i === 0) {
|
||||
deserializedProduct[i].id.should.equal(101);
|
||||
deserializedProduct[i].name.should.equal("TestProduct");
|
||||
deserializedProduct[i].provisioningState.should.equal("Succeeded");
|
||||
} else if (i === 1) {
|
||||
deserializedProduct[i].id.should.equal(104);
|
||||
deserializedProduct[i].name.should.equal("TestProduct1");
|
||||
deserializedProduct[i].provisioningState.should.equal("Failed");
|
||||
}
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
it("should correctly deserialize object version of polymorphic discriminator", function (done) {
|
||||
const client = new TestClient("http://localhost:9090");
|
||||
const mapper = Mappers.Fish;
|
||||
|
|
Загрузка…
Ссылка в новой задаче