-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Database validation in jdl #12975
Conversation
Validation as a whole should be disabled when using blueprints.... Not just that. |
sorry for my misunderstanding, how can I know if a blueprint is used in this part? |
@nicolas63 don't be! I'm gonna walk you through how it can be done step by step. If you look at the
Now, go line 179. you'll see this function: function checkForErrors(jdlObject, configuration) {
let validator;
if (jdlObject.getApplicationQuantity() === 0) {
let application = configuration.application;
if (!application && doesFileExist('.yo-rc.json')) {
application = readJSONFile('.yo-rc.json');
}
let applicationType = configuration.applicationType;
let databaseType = configuration.databaseType;
let skippedUserManagement = configuration.skipUserManagement;
if (application && application['generator-jhipster']) {
if (applicationType === undefined) {
applicationType = application['generator-jhipster'].applicationType;
}
if (databaseType === undefined) {
databaseType = application['generator-jhipster'].databaseType;
}
if (skippedUserManagement === undefined) {
skippedUserManagement = application['generator-jhipster'].skipUserManagement;
}
}
validator = JDLWithoutApplicationValidator.createValidator(jdlObject, {
applicationType,
databaseType,
skippedUserManagement,
});
} else {
validator = JDLWithApplicationValidator.createValidator(jdlObject);
}
validator.checkForErrors();
} This function checks a passed JDL object for errors. This is the validation is done. When there's no blueprint, the actual rules for validations are implemented and it works. There are two fixes to do:
There are two files: For the "no app" case, we need to pass to the validator whether there are blueprints involved, which is done line 173 of the function checkForErrors(jdlObject, configuration) {
let validator;
if (jdlObject.getApplicationQuantity() === 0) {
let application = configuration.application;
if (!application && doesFileExist('.yo-rc.json')) {
application = readJSONFile('.yo-rc.json');
}
let applicationType = configuration.applicationType;
let databaseType = configuration.databaseType;
let skippedUserManagement = configuration.skipUserManagement;
let blueprints = configuration.blueprints; // first there
if (application && application['generator-jhipster']) {
if (applicationType === undefined) {
applicationType = application['generator-jhipster'].applicationType;
}
if (databaseType === undefined) {
databaseType = application['generator-jhipster'].databaseType;
}
if (skippedUserManagement === undefined) {
skippedUserManagement = application['generator-jhipster'].skipUserManagement;
}
if (blueprints === undefined) { // here
blueprints = application['generator-jhipster'].blueprints;
}
}
validator = JDLWithoutApplicationValidator.createValidator(jdlObject, {
applicationType,
databaseType,
skippedUserManagement,
blueprints, // and there
});
} else {
validator = JDLWithApplicationValidator.createValidator(jdlObject);
}
validator.checkForErrors();
} and finally in the
function createValidator(jdlObject, applicationSettings = {}, logger = console) {
if (!jdlObject) {
throw new Error('A JDL object must be passed to check for business errors.');
}
if (applicationSettings.blueprints && applicationSettings.blueprints.length !== 0) {
return { checkForErrors: () => {} };
}
return {
checkForErrors: () => {
checkForEntityErrors();
checkForRelationshipErrors();
checkForEnumErrors();
checkDeploymentsErrors();
checkForOptionErrors();
},
};
// ...
} That's the hardest part. The easiest part will be updating the function createValidator(jdlObject, logger = console) {
if (!jdlObject) {
throw new Error('A JDL object must be passed to check for business errors.');
}
return {
checkForErrors: () => {
checkForApplicationErrors();
jdlObject.forEachApplication(jdlApplication => {
const blueprints = jdlApplication.getConfigurationOptionValue('blueprints');
if (!blueprints || blueprints.length > 0) {
return;
}
checkForEntityErrors(jdlApplication);
checkForRelationshipErrors(jdlApplication);
checkForEnumErrors();
checkDeploymentsErrors();
checkForOptionErrors(jdlApplication);
});
checkForRelationshipsBetweenApplications();
},
};
// ...
} There will be some testing to do: check no validation is performed when blueprints are passed in the two cases. This should be done at the highest level: for the Hope it wasn't too long :) if you want to do this PR, it'd be awesome! |
thank you @MathieuAA for your precious explanation, I will make the changes. |
Print a warning:
|
Maybe not console.log, but console.warn :) |
@MathieuAA how can i do this ? i have try to spy logger but the method createValidator don't use should I use it rather than console in |
In the tests, pass whatever log object you want to test like it's done l.85 of the |
@MathieuAA i have added UT but some checks failed during CI, it's due to my modification ? |
I'll check right away |
It looks like an issue with Actions as a whole, I'm looking into it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice :) only a few changes needed and it's good to go.
There was an issue with GH actions (I've noticed warning about 429 errors) and restarting the tests worked like a charm. |
@nicolas63 thanks!! Feel free to merge it once the CI report goes green :) |
thanks to you @MathieuAA for your advice ! Can you merge it ? I don't have the rights to do |
Please make sure the below checklist is followed for Pull Requests.
When you are still working on the PR, consider converting it to Draft (bellow reviewers) and adding
skip-ci
label, you can still see CI build result at your branch.fix #12959