Skip to content

Commit

Permalink
[INTERNAL] Schema: Update error messages / fix framework schema
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Mar 26, 2020
1 parent 7f24f6c commit f490224
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 11 deletions.
9 changes: 6 additions & 3 deletions lib/validation/ValidationError.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ class ValidationError extends Error {

switch (error.keyword) {
case "additionalProperties":
message += `property ${error.params.additionalProperty} is not expected to be here`;
message += `property ${error.params.additionalProperty} must not be provided here`;
break;
case "type":
message += `should be of type '${error.params.type}'`;
message += `must be of type '${error.params.type}'`;
break;
case "required":
message += `must have required property '${error.params.missingProperty}'`;
break;
case "enum":
message += error.message + "\n";
message += "must be equal to one of the allowed values\n";
message += "Allowed values: " + error.params.allowedValues.join(", ");
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion lib/validation/schema/specVersion/2.0/kind/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
"framework": {
"type": "object",
"additionalProperties": false,
"required": ["name", "version"],
"required": ["name"],
"properties": {
"name": {
"enum": ["OpenUI5", "SAPUI5"]
Expand Down
2 changes: 1 addition & 1 deletion test/lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ test("Project with project-shim extension with invalid dependency configuration"
const validationError = await t.throwsAsync(projectPreprocessor.processTree(tree), {
instanceOf: ValidationError
});
t.true(validationError.message.includes("Configuration should have required property 'metadata'"),
t.true(validationError.message.includes("Configuration must have required property 'metadata'"),
"ValidationError should contain error about missing metadata configuration");
});

Expand Down
12 changes: 6 additions & 6 deletions test/lib/validation/ValidationError.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ test.serial("ValidationError.formatMessage: keyword=type dataPath=", (t) => {
schemaPath: "#/type",
};

const expectedErrorMessage = "Configuration should be of type 'object'";
const expectedErrorMessage = "Configuration must be of type 'object'";

const errorMessage = ValidationError.formatMessage(error);
t.is(errorMessage, expectedErrorMessage);
Expand All @@ -814,7 +814,7 @@ test.serial("ValidationError.formatMessage: keyword=type", (t) => {
schemaPath: "#/type",
};

const expectedErrorMessage = `Configuration ${chalk.underline(chalk.red("foo"))} should be of type 'object'`;
const expectedErrorMessage = `Configuration ${chalk.underline(chalk.red("foo"))} must be of type 'object'`;

const errorMessage = ValidationError.formatMessage(error);
t.is(errorMessage, expectedErrorMessage);
Expand All @@ -831,7 +831,7 @@ test.serial("ValidationError.formatMessage: keyword=required w/o dataPath", (t)
schemaPath: "#/required",
};

const expectedErrorMessage = "Configuration should have required property 'specVersion'";
const expectedErrorMessage = "Configuration must have required property 'specVersion'";

const errorMessage = ValidationError.formatMessage(error);
t.is(errorMessage, expectedErrorMessage);
Expand All @@ -846,7 +846,7 @@ test.serial("ValidationError.formatMessage: keyword=required", (t) => {
message: "should have required property 'name'"
};

const expectedErrorMessage = `Configuration ${chalk.underline(chalk.red("metadata"))} should have required property 'name'`;
const expectedErrorMessage = `Configuration ${chalk.underline(chalk.red("metadata"))} must have required property 'name'`;

const errorMessage = ValidationError.formatMessage(error);
t.is(errorMessage, expectedErrorMessage);
Expand Down Expand Up @@ -902,7 +902,7 @@ test.serial("ValidationError.formatMessage: keyword=additionalProperties", (t) =
};

const expectedErrorMessage =
`Configuration ${chalk.underline(chalk.red("resources/configuration"))} property propertiesFileEncoding is not expected to be here`;
`Configuration ${chalk.underline(chalk.red("resources/configuration"))} property propertiesFileEncoding must not be provided here`;

const errorMessage = ValidationError.formatMessage(error);
t.is(errorMessage, expectedErrorMessage);
Expand All @@ -920,7 +920,7 @@ test.serial("ValidationError.formatMessage: keyword=enum", (t) => {
};

const expectedErrorMessage =
`Configuration ${chalk.underline(chalk.red("type"))} should be equal to one of the allowed values
`Configuration ${chalk.underline(chalk.red("type"))} must be equal to one of the allowed values
Allowed values: application, library, theme-library, module`;

const errorMessage = ValidationError.formatMessage(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,24 @@ test("framework configuration: Invalid", async (t) => {
}
]);
});

test("framework configuration: Missing 'name'", async (t) => {
await assertValidation(t, {
"specVersion": "2.0",
"type": "application",
"metadata": {
"name": "my-application"
},
"framework": {}
}, [
{
dataPath: "/framework",
keyword: "required",
message: "should have required property 'name'",
params: {
missingProperty: "name"
},
schemaPath: "../project.json#/definitions/framework/required",
}
]);
});
21 changes: 21 additions & 0 deletions test/lib/validation/schema/specVersion/2.0/kind/project/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,3 +702,24 @@ test("framework configuration: Invalid", async (t) => {
}
]);
});

test("framework configuration: Missing 'name'", async (t) => {
await assertValidation(t, {
"specVersion": "2.0",
"type": "library",
"metadata": {
"name": "my-library"
},
"framework": {}
}, [
{
dataPath: "/framework",
keyword: "required",
message: "should have required property 'name'",
params: {
missingProperty: "name"
},
schemaPath: "../project.json#/definitions/framework/required",
}
]);
});

0 comments on commit f490224

Please sign in to comment.