forked from loafle/openapi-generator-original
typescript-node: bug in models.mustache with for...in on an empty array. (#8575)
* Fixed typescript bug in models.mustache with for...in on an empty array. When an empty array comes in, the current for...in syntax results in creating an empty object being created and added to the array. This is the output from receiving an empty array that gets deserialized, resulting in an object with undefined values. Switching to a for i < array.length loop fixes this issue. ``` body: [ GroupCustomResource { apiVersion: undefined, kind: undefined, spec: undefined, metadata: undefined, status: undefined, '': undefined } ] ``` * Fixed typescript deserialization bug that was adding non-existent entries to objects during deserialization. When an object comes in, the current for...in syntax results in adding an undefined key/value pair to each nested object, with key being empty string and value being undefined. This is the output from receiving an object that gets deserialized. Adding a check to see if attributeType.name exists before adding it to the deserialized object fixes this. ``` res.body of listGroup for saved group is [ GroupCustomResource { apiVersion: 'v1', kind: 'Group', spec: GroupSpec { name: 'TestDeploymentGroup67264', tenancyId: 'tenancy', description: 'TestGroup description', '': undefined }, metadata: { additionalProp1: {}, spectra: [Object] }, status: undefined, '': undefined } ] ``` * Fixed for array for loop in serialize and added truth check for deserialize * Made for...in loop a for loop; gets rid of the need for the truth check * Fixed serialze/deserialize for loops for arrays Co-authored-by: Gary Blaser <gary.blaser@oracle.com>
This commit is contained in:
parent
3c4b1a0c4c
commit
0e16eba06a
@ -113,9 +113,9 @@ export class ObjectSerializer {
|
||||
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
|
||||
subType = subType.substring(0, subType.length - 1); // Type> => Type
|
||||
let transformedData: any[] = [];
|
||||
for (let index in data) {
|
||||
let date = data[index];
|
||||
transformedData.push(ObjectSerializer.serialize(date, subType));
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
let datum = data[index];
|
||||
transformedData.push(ObjectSerializer.serialize(datum, subType));
|
||||
}
|
||||
return transformedData;
|
||||
} else if (type === "Date") {
|
||||
@ -134,7 +134,7 @@ export class ObjectSerializer {
|
||||
// get the map for the correct type.
|
||||
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
||||
let instance: {[index: string]: any} = {};
|
||||
for (let index in attributeTypes) {
|
||||
for (let index = 0; index < attributeTypes.length; index++) {
|
||||
let attributeType = attributeTypes[index];
|
||||
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
|
||||
}
|
||||
@ -153,9 +153,9 @@ export class ObjectSerializer {
|
||||
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
|
||||
subType = subType.substring(0, subType.length - 1); // Type> => Type
|
||||
let transformedData: any[] = [];
|
||||
for (let index in data) {
|
||||
let date = data[index];
|
||||
transformedData.push(ObjectSerializer.deserialize(date, subType));
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
let datum = data[index];
|
||||
transformedData.push(ObjectSerializer.deserialize(datum, subType));
|
||||
}
|
||||
return transformedData;
|
||||
} else if (type === "Date") {
|
||||
@ -170,7 +170,7 @@ export class ObjectSerializer {
|
||||
}
|
||||
let instance = new typeMap[type]();
|
||||
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
||||
for (let index in attributeTypes) {
|
||||
for (let index = 0; index < attributeTypes.length; index++) {
|
||||
let attributeType = attributeTypes[index];
|
||||
instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type);
|
||||
}
|
||||
|
@ -98,9 +98,9 @@ export class ObjectSerializer {
|
||||
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
|
||||
subType = subType.substring(0, subType.length - 1); // Type> => Type
|
||||
let transformedData: any[] = [];
|
||||
for (let index in data) {
|
||||
let date = data[index];
|
||||
transformedData.push(ObjectSerializer.serialize(date, subType));
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
let datum = data[index];
|
||||
transformedData.push(ObjectSerializer.serialize(datum, subType));
|
||||
}
|
||||
return transformedData;
|
||||
} else if (type === "Date") {
|
||||
@ -119,7 +119,7 @@ export class ObjectSerializer {
|
||||
// get the map for the correct type.
|
||||
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
||||
let instance: {[index: string]: any} = {};
|
||||
for (let index in attributeTypes) {
|
||||
for (let index = 0; index < attributeTypes.length; index++) {
|
||||
let attributeType = attributeTypes[index];
|
||||
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
|
||||
}
|
||||
@ -138,9 +138,9 @@ export class ObjectSerializer {
|
||||
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
|
||||
subType = subType.substring(0, subType.length - 1); // Type> => Type
|
||||
let transformedData: any[] = [];
|
||||
for (let index in data) {
|
||||
let date = data[index];
|
||||
transformedData.push(ObjectSerializer.deserialize(date, subType));
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
let datum = data[index];
|
||||
transformedData.push(ObjectSerializer.deserialize(datum, subType));
|
||||
}
|
||||
return transformedData;
|
||||
} else if (type === "Date") {
|
||||
@ -155,7 +155,7 @@ export class ObjectSerializer {
|
||||
}
|
||||
let instance = new typeMap[type]();
|
||||
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
||||
for (let index in attributeTypes) {
|
||||
for (let index = 0; index < attributeTypes.length; index++) {
|
||||
let attributeType = attributeTypes[index];
|
||||
instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type);
|
||||
}
|
||||
|
@ -98,9 +98,9 @@ export class ObjectSerializer {
|
||||
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
|
||||
subType = subType.substring(0, subType.length - 1); // Type> => Type
|
||||
let transformedData: any[] = [];
|
||||
for (let index in data) {
|
||||
let date = data[index];
|
||||
transformedData.push(ObjectSerializer.serialize(date, subType));
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
let datum = data[index];
|
||||
transformedData.push(ObjectSerializer.serialize(datum, subType));
|
||||
}
|
||||
return transformedData;
|
||||
} else if (type === "Date") {
|
||||
@ -119,7 +119,7 @@ export class ObjectSerializer {
|
||||
// get the map for the correct type.
|
||||
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
||||
let instance: {[index: string]: any} = {};
|
||||
for (let index in attributeTypes) {
|
||||
for (let index = 0; index < attributeTypes.length; index++) {
|
||||
let attributeType = attributeTypes[index];
|
||||
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
|
||||
}
|
||||
@ -138,9 +138,9 @@ export class ObjectSerializer {
|
||||
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
|
||||
subType = subType.substring(0, subType.length - 1); // Type> => Type
|
||||
let transformedData: any[] = [];
|
||||
for (let index in data) {
|
||||
let date = data[index];
|
||||
transformedData.push(ObjectSerializer.deserialize(date, subType));
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
let datum = data[index];
|
||||
transformedData.push(ObjectSerializer.deserialize(datum, subType));
|
||||
}
|
||||
return transformedData;
|
||||
} else if (type === "Date") {
|
||||
@ -155,7 +155,7 @@ export class ObjectSerializer {
|
||||
}
|
||||
let instance = new typeMap[type]();
|
||||
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
||||
for (let index in attributeTypes) {
|
||||
for (let index = 0; index < attributeTypes.length; index++) {
|
||||
let attributeType = attributeTypes[index];
|
||||
instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user