Skip to content

Commit

Permalink
[EDM] Schema definition contains NaN values (#4049)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThuF committed Jun 17, 2024
1 parent 132387d commit 2ad4537
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ function createModel(graph) {
'" dataName="' + _.escape(property.dataName) +
'" dataType="' + _.escape(property.dataType) + '"');
if (property.dataLength !== null) {
model.push(' dataLength="' + _.escape(property.dataLength) + '"');
if (property.dataType === 'CHAR' || property.dataType === 'VARCHAR') {
model.push(' dataLength="' + _.escape(property.dataLength) + '"');
}
}
if (property.dataNotNull) {
model.push(' dataNullable="' + (property.dataNotNull == "false") + '"');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ exports.generateGeneric = function (model, parameters, templateSources) {
const generatedFiles = []
const templateParameters = {};
Object.assign(templateParameters, model, parameters);

const cleanTemplateParameters = cleanData(templateParameters);

for (let i = 0; i < templateSources.length; i++) {
const template = templateSources[i];
const location = template.location;
Expand All @@ -33,7 +36,7 @@ exports.generateGeneric = function (model, parameters, templateSources) {
} else {
generatedFiles.push({
location: location,
content: getGenerationEngine(template).generate(location, content, templateParameters),
content: getGenerationEngine(template).generate(location, content, cleanTemplateParameters),
path: templateEngines.getMustacheEngine().generate(location, template.rename, parameters)
});
}
Expand Down Expand Up @@ -139,10 +142,13 @@ exports.generateFiles = function (model, parameters, templateSources) {
default:
// No collection
parameters.models = model.entities;

const cleanParameters = cleanData(parameters);

generatedFiles.push({
location: location,
content: getGenerationEngine(template).generate(location, content, parameters),
path: templateEngines.getMustacheEngine().generate(location, template.rename, parameters)
content: getGenerationEngine(template).generate(location, content, cleanParameters),
path: templateEngines.getMustacheEngine().generate(location, template.rename, cleanParameters)
});
break;
}
Expand All @@ -164,10 +170,12 @@ function generateCollection(location, content, template, collection, parameters)
collection.filter(e => e.perspectiveName === collection[i].perspectiveName).forEach(e => templateParameters.perspectiveViews.push(e.name + "-details"));
}

const cleanTemplateParameters = cleanData(templateParameters);

generatedFiles.push({
location: location,
content: generationEngine.generate(location, content, templateParameters),
path: templateEngines.getMustacheEngine().generate(location, template.rename, templateParameters)
content: generationEngine.generate(location, content, cleanTemplateParameters),
path: templateEngines.getMustacheEngine().generate(location, template.rename, cleanTemplateParameters)
});
}
return generatedFiles;
Expand Down Expand Up @@ -198,4 +206,25 @@ function getGenerationEngine(template) {
generationEngine.setEm(template.em);
}
return generationEngine;
}
}

function cleanData(data) {
if (typeof data === 'object' && data !== null) {
if (Array.isArray(data)) {
for (let i = 0; i < data.length; i++) {
cleanData(data[i]);
}
} else {
for (let key in data) {
if (data[key] !== undefined) {
if ((typeof data[key] === 'number' && isNaN(data[key])) || data[key] === 'NaN') {
delete data[key];
} else {
cleanData(data[key]);
}
}
}
}
}
return data;
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ exports.process = function (model, parameters) {
// TODO minLength is not available in the model and can't be determined
p.minLength = 0;
p.maxLength = -1;
let widgetLength = parseInt(p.widgetLength);
let dataLength = parseInt(p.dataLength)
let widgetLength = parseInt(p.widgetLength ? p.widgetLength : '0');
let dataLength = parseInt(p.dataLength ? p.dataLength : '0')
p.maxLength = dataLength > widgetLength ? widgetLength : dataLength;
} else if (p.dataTypeTypescript === "Date") {
p.isDateType = true;
Expand Down

0 comments on commit 2ad4537

Please sign in to comment.