-
Notifications
You must be signed in to change notification settings - Fork 14
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
[FEATURE] Add Configuration Schema #274
Conversation
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.
I like what I see
Should be rebased on top of #277 |
const escapeStringRegExp = require("escape-string-regexp"); | ||
const matchAll = require("string.prototype.matchall"); | ||
|
||
class ValidationError extends Error { |
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.
I am really missing some jsdoc here for the class and methods.
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.
Done
"properties": { | ||
"specVersion": { "enum": ["2.0"] }, | ||
"kind": { | ||
"enum": ["project", null] |
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.
What is the enum entry "null" for?
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.
The default when it's not defined. I've added comments.
return JSON.parse(schemaFile); | ||
} | ||
|
||
class Validator { |
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.
Same here, no documentation. Most of the methods logic is obvious but at least the class could use some doc.
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.
Done for the public API
test/lib/projectPreprocessor.js
Outdated
}); | ||
|
||
t.is(validationError.errors.length, 1, "ValidationError should have one error object"); | ||
t.is(validationError.errors.length, 1, "ValidationError should have one error object"); |
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.
Duplicate assertion
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.
Done
lib/projectPreprocessor.js
Outdated
@@ -3,8 +3,9 @@ const fs = require("graceful-fs"); | |||
const path = require("path"); | |||
const {promisify} = require("util"); | |||
const readFile = promisify(fs.readFile); | |||
const parseYaml = require("js-yaml").safeLoadAll; | |||
const {loadAll: parseYaml, DEFAULT_SAFE_SCHEMA} = require("js-yaml"); |
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.
This change is needed because of the issues with safeLoadAll
? If yes, maybe add a comment for that.
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.
Yes, good point. Done.
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.
I did not look into all the new tests, it's just too much. But that's still a good thing 👍
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.
projectPreprocessor » readConfigFile: Exception for invalid config
failed on Windows: https://dev.azure.com/sap/opensource/_build/results?buildId=47033&view=ms.vss-test-web.build-test-results-tab&runId=1017232&resultId=100193&paneView=debug
lib/validation/validator.js
Outdated
* @param {number} [options.yaml.documentIndex=0] Document index in case the YAML file contains multiple documents | ||
* @throws {module:@ui5/project.validation.ValidationError} | ||
* Throws a {@link module:@ui5/project.validation.ValidationError ValidationError} when the validation fails. | ||
* @returns {undefined} Returns when the validation succeeds |
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.
Returns a Promise, right?
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.
Done
Tests should be fixed now. |
const yaml = { | ||
path: "/my-project/ui5.yaml", | ||
source: | ||
`--- |
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.
What about one (or multiple) newlines at the beginning of the file?
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.
Good point. Done 👍
source: configFile, | ||
documentIndex | ||
configs.map(async (config, documentIndex) => { | ||
try { |
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.
We should document that the try/catch block here is required to get the first error of the first document. And not the first error to occur in any document.
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.
Done
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.
I like it, let's enforce the schema!!!11
🚓 👮 👮♀ 🚔
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.
Whenever errors are triggered, the word "should" is not strong enough. Please replace "should" by "must" in all error messages.
schemaPath: "#/type", | ||
}; | ||
|
||
const expectedErrorMessage = `Configuration ${chalk.underline(chalk.red("foo"))} should be of type 'object'`; |
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.
"should" --> "must"
schemaPath: "#/required", | ||
}; | ||
|
||
const expectedErrorMessage = "Configuration should have required property 'specVersion'"; |
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.
"Configuration must have the required property 'specVersion'"
message: "should have required property 'name'" | ||
}; | ||
|
||
const expectedErrorMessage = `Configuration ${chalk.underline(chalk.red("metadata"))} should have required property 'name'`; |
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.
"Configuration ${chalk.underline(chalk.red("metadata"))} must have the required property 'name'"
}; | ||
|
||
const expectedErrorMessage = | ||
`Configuration ${chalk.underline(chalk.red("type"))} should be equal to one of the allowed values |
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.
"Configuration ${chalk.underline(chalk.red("type"))} must be equal to one of the allowed values"
}; | ||
|
||
const expectedErrorMessage = | ||
`Configuration ${chalk.underline(chalk.red("resources/configuration"))} property propertiesFileEncoding is not expected to be here`; |
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.
"Configuration ${chalk.underline(chalk.red("resources/configuration"))} property propertiesFileEncoding must not be provided here"
Thank you for your contribution! 🙌
To get it merged faster, kindly review the checklist below:
Pull Request Checklist