Skip to content

Commit ca554e6

Browse files
committed
[INTERNAL] Schema: Update error messages / fix framework schema
1 parent 7a4dc09 commit ca554e6

File tree

6 files changed

+56
-11
lines changed

6 files changed

+56
-11
lines changed

lib/validation/ValidationError.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,16 @@ class ValidationError extends Error {
7979

8080
switch (error.keyword) {
8181
case "additionalProperties":
82-
message += `property ${error.params.additionalProperty} is not expected to be here`;
82+
message += `property ${error.params.additionalProperty} must not be provided here`;
8383
break;
8484
case "type":
85-
message += `should be of type '${error.params.type}'`;
85+
message += `must be of type '${error.params.type}'`;
86+
break;
87+
case "required":
88+
message += `must have required property '${error.params.missingProperty}'`;
8689
break;
8790
case "enum":
88-
message += error.message + "\n";
91+
message += "must be equal to one of the allowed values\n";
8992
message += "Allowed values: " + error.params.allowedValues.join(", ");
9093
break;
9194
default:

lib/validation/schema/specVersion/2.0/kind/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
"framework": {
257257
"type": "object",
258258
"additionalProperties": false,
259-
"required": ["name", "version"],
259+
"required": ["name"],
260260
"properties": {
261261
"name": {
262262
"enum": ["OpenUI5", "SAPUI5"]

test/lib/extensions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ test("Project with project-shim extension with invalid dependency configuration"
154154
const validationError = await t.throwsAsync(projectPreprocessor.processTree(tree), {
155155
instanceOf: ValidationError
156156
});
157-
t.true(validationError.message.includes("Configuration should have required property 'metadata'"),
157+
t.true(validationError.message.includes("Configuration must have required property 'metadata'"),
158158
"ValidationError should contain error about missing metadata configuration");
159159
});
160160

test/lib/validation/ValidationError.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ test.serial("ValidationError.formatMessage: keyword=type dataPath=", (t) => {
797797
schemaPath: "#/type",
798798
};
799799

800-
const expectedErrorMessage = "Configuration should be of type 'object'";
800+
const expectedErrorMessage = "Configuration must be of type 'object'";
801801

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

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

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

834-
const expectedErrorMessage = "Configuration should have required property 'specVersion'";
834+
const expectedErrorMessage = "Configuration must have required property 'specVersion'";
835835

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

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

851851
const errorMessage = ValidationError.formatMessage(error);
852852
t.is(errorMessage, expectedErrorMessage);
@@ -902,7 +902,7 @@ test.serial("ValidationError.formatMessage: keyword=additionalProperties", (t) =
902902
};
903903

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

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

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

926926
const errorMessage = ValidationError.formatMessage(error);

test/lib/validation/schema/specVersion/2.0/kind/project/application.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,24 @@ test("framework configuration: Invalid", async (t) => {
630630
}
631631
]);
632632
});
633+
634+
test("framework configuration: Missing 'name'", async (t) => {
635+
await assertValidation(t, {
636+
"specVersion": "2.0",
637+
"type": "application",
638+
"metadata": {
639+
"name": "my-application"
640+
},
641+
"framework": {}
642+
}, [
643+
{
644+
dataPath: "/framework",
645+
keyword: "required",
646+
message: "should have required property 'name'",
647+
params: {
648+
missingProperty: "name"
649+
},
650+
schemaPath: "../project.json#/definitions/framework/required",
651+
}
652+
]);
653+
});

test/lib/validation/schema/specVersion/2.0/kind/project/library.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,3 +702,24 @@ test("framework configuration: Invalid", async (t) => {
702702
}
703703
]);
704704
});
705+
706+
test("framework configuration: Missing 'name'", async (t) => {
707+
await assertValidation(t, {
708+
"specVersion": "2.0",
709+
"type": "library",
710+
"metadata": {
711+
"name": "my-library"
712+
},
713+
"framework": {}
714+
}, [
715+
{
716+
dataPath: "/framework",
717+
keyword: "required",
718+
message: "should have required property 'name'",
719+
params: {
720+
missingProperty: "name"
721+
},
722+
schemaPath: "../project.json#/definitions/framework/required",
723+
}
724+
]);
725+
});

0 commit comments

Comments
 (0)