Skip to content

Commit

Permalink
[INTERNAL] Schema: Add error message for metadata.name
Browse files Browse the repository at this point in the history
Also escape forward slash just to be sure
  • Loading branch information
RandomByte committed Jan 25, 2023
1 parent d5484f6 commit e573adf
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 89 deletions.
5 changes: 4 additions & 1 deletion lib/validation/schema/specVersion/kind/extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@
"type": "string",
"minLength": 3,
"maxLength": 50,
"pattern": "^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$"
"pattern": "^(?:@[0-9a-z-_.]+\\/)?[a-z][0-9a-z-_.]*$",
"title": "Extension Name",
"description": "Unique identifier for the extension. E.g. ui5-task-fearless-rock",
"errorMessage": "Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name"
},
"copyright": {
"type": "string"
Expand Down
5 changes: 4 additions & 1 deletion lib/validation/schema/specVersion/kind/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@
"type": "string",
"minLength": 3,
"maxLength": 50,
"pattern": "^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$"
"pattern": "^(?:@[0-9a-z-_.]+\\/)?[a-z][0-9a-z-_.]*$",
"title": "Project Name",
"description": "Unique identifier for the project. E.g. organization.product.project",
"errorMessage": "Not a valid project name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name"
},
"copyright": {
"type": "string"
Expand Down
68 changes: 49 additions & 19 deletions test/lib/validation/schema/__helper__/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,6 @@ export default {
}]);
});

test(`${type} (specVersion ${specVersion}): Invalid metadata.name`, async (t) => {
await assertValidation(t, {
"specVersion": specVersion,
"type": type,
"metadata": {
"name": {}
}
}, [
{
dataPath: "/metadata/name",
keyword: "type",
message: "should be string",
params: {
type: "string"
}
}
]);
});

test(`${type} (specVersion ${specVersion}): Invalid metadata.copyright`, async (t) => {
await assertValidation(t, {
"specVersion": specVersion,
Expand Down Expand Up @@ -278,5 +259,54 @@ export default {
}]);
});
});

// version specific tests
["2.6", "2.5", "2.4", "2.3", "2.2", "2.1", "2.0"].forEach((specVersion) => {
test(`${type} (specVersion ${specVersion}): Invalid metadata.name`, async (t) => {
await assertValidation(t, {
"specVersion": specVersion,
"type": type,
"metadata": {
"name": {}
}
}, [
{
dataPath: "/metadata/name",
keyword: "type",
message: "should be string",
params: {
type: "string"
}
}
]);
});
});
["3.0"].forEach((specVersion) => {
test(`${type} (specVersion ${specVersion}): Invalid metadata.name`, async (t) => {
await assertValidation(t, {
"specVersion": specVersion,
"type": type,
"metadata": {
"name": {}
}
}, [
{
dataPath: "/metadata/name",
keyword: "errorMessage",
message: `Not a valid project name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
errors: [{
dataPath: "/metadata/name",
keyword: "type",
message: "should be string",
params: {
type: "string",
}
}]
},
}
]);
});
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ async function assertValidation(t, config, expectedErrors = undefined) {
});
validationError.errors.forEach((error) => {
delete error.schemaPath;
if (error.params && Array.isArray(error.params.errors)) {
error.params.errors.forEach(($) => {
delete $.schemaPath;
});
}
});
t.deepEqual(validationError.errors, expectedErrors);
} else {
Expand Down Expand Up @@ -123,21 +128,28 @@ test.after.always((t) => {
});

["3.0"].forEach(function(specVersion) {
test(`Invalid project name (specVersion ${specVersion})`, async (t) => {
test(`Invalid extension name (specVersion ${specVersion})`, async (t) => {
await assertValidation(t, {
"specVersion": specVersion,
"kind": "extension",
"type": "project-shim",
"metadata": {
"name": "illegal-🦜"
"name": "illegal/name"
},
"shims": {}
}, [{
dataPath: "/metadata/name",
keyword: "pattern",
message: `should match pattern "^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$"`,
keyword: "errorMessage",
message: `Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
pattern: `^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$`,
errors: [{
dataPath: "/metadata/name",
keyword: "pattern",
message: `should match pattern "^(?:@[0-9a-z-_.]+\\/)?[a-z][0-9a-z-_.]*$"`,
params: {
pattern: "^(?:@[0-9a-z-_.]+\\/)?[a-z][0-9a-z-_.]*$",
}
}]
},
}]);
await assertValidation(t, {
Expand All @@ -150,10 +162,17 @@ test.after.always((t) => {
"shims": {}
}, [{
dataPath: "/metadata/name",
keyword: "minLength",
message: `should NOT be shorter than 3 characters`,
keyword: "errorMessage",
message: `Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
limit: 3,
errors: [{
dataPath: "/metadata/name",
keyword: "minLength",
message: "should NOT be shorter than 3 characters",
params: {
limit: 3,
}
}]
},
}]);
await assertValidation(t, {
Expand All @@ -166,10 +185,17 @@ test.after.always((t) => {
"shims": {}
}, [{
dataPath: "/metadata/name",
keyword: "maxLength",
message: `should NOT be longer than 50 characters`,
keyword: "errorMessage",
message: `Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
limit: 50,
errors: [{
dataPath: "/metadata/name",
keyword: "maxLength",
message: "should NOT be longer than 50 characters",
params: {
limit: 50,
}
}]
},
}]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ async function assertValidation(t, config, expectedErrors = undefined) {
});
validationError.errors.forEach((error) => {
delete error.schemaPath;
if (error.params && Array.isArray(error.params.errors)) {
error.params.errors.forEach(($) => {
delete $.schemaPath;
});
}
});
t.deepEqual(validationError.errors, expectedErrors);
} else {
Expand All @@ -41,7 +46,7 @@ test.after.always((t) => {
});

["3.0"].forEach(function(specVersion) {
test(`Invalid project name (specVersion ${specVersion})`, async (t) => {
test(`Invalid extension name (specVersion ${specVersion})`, async (t) => {
await assertValidation(t, {
"specVersion": specVersion,
"kind": "extension",
Expand All @@ -54,10 +59,17 @@ test.after.always((t) => {
}
}, [{
dataPath: "/metadata/name",
keyword: "pattern",
message: `should match pattern "^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$"`,
keyword: "errorMessage",
message: `Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
pattern: `^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$`,
errors: [{
dataPath: "/metadata/name",
keyword: "pattern",
message: `should match pattern "^(?:@[0-9a-z-_.]+\\/)?[a-z][0-9a-z-_.]*$"`,
params: {
pattern: "^(?:@[0-9a-z-_.]+\\/)?[a-z][0-9a-z-_.]*$",
}
}]
},
}]);
await assertValidation(t, {
Expand All @@ -72,10 +84,17 @@ test.after.always((t) => {
}
}, [{
dataPath: "/metadata/name",
keyword: "minLength",
message: `should NOT be shorter than 3 characters`,
keyword: "errorMessage",
message: `Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
limit: 3,
errors: [{
dataPath: "/metadata/name",
keyword: "minLength",
message: "should NOT be shorter than 3 characters",
params: {
limit: 3,
}
}]
},
}]);
await assertValidation(t, {
Expand All @@ -90,10 +109,17 @@ test.after.always((t) => {
}
}, [{
dataPath: "/metadata/name",
keyword: "maxLength",
message: `should NOT be longer than 50 characters`,
keyword: "errorMessage",
message: `Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
limit: 50,
errors: [{
dataPath: "/metadata/name",
keyword: "maxLength",
message: "should NOT be longer than 50 characters",
params: {
limit: 50,
}
}]
},
}]);
});
Expand Down
46 changes: 36 additions & 10 deletions test/lib/validation/schema/specVersion/kind/extension/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ async function assertValidation(t, config, expectedErrors = undefined) {
});
validationError.errors.forEach((error) => {
delete error.schemaPath;
if (error.params && Array.isArray(error.params.errors)) {
error.params.errors.forEach(($) => {
delete $.schemaPath;
});
}
});
t.deepEqual(validationError.errors, expectedErrors);
} else {
Expand All @@ -41,7 +46,7 @@ test.after.always((t) => {
});

["3.0"].forEach(function(specVersion) {
test(`Invalid project name (specVersion ${specVersion})`, async (t) => {
test(`Invalid extension name (specVersion ${specVersion})`, async (t) => {
await assertValidation(t, {
"specVersion": specVersion,
"kind": "extension",
Expand All @@ -54,10 +59,17 @@ test.after.always((t) => {
}
}, [{
dataPath: "/metadata/name",
keyword: "pattern",
message: `should match pattern "^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$"`,
keyword: "errorMessage",
message: `Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
pattern: `^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$`,
errors: [{
dataPath: "/metadata/name",
keyword: "pattern",
message: `should match pattern "^(?:@[0-9a-z-_.]+\\/)?[a-z][0-9a-z-_.]*$"`,
params: {
pattern: "^(?:@[0-9a-z-_.]+\\/)?[a-z][0-9a-z-_.]*$",
}
}]
},
}]);
await assertValidation(t, {
Expand All @@ -72,10 +84,17 @@ test.after.always((t) => {
}
}, [{
dataPath: "/metadata/name",
keyword: "minLength",
message: `should NOT be shorter than 3 characters`,
keyword: "errorMessage",
message: `Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
limit: 3,
errors: [{
dataPath: "/metadata/name",
keyword: "minLength",
message: "should NOT be shorter than 3 characters",
params: {
limit: 3,
}
}]
},
}]);
await assertValidation(t, {
Expand All @@ -90,10 +109,17 @@ test.after.always((t) => {
}
}, [{
dataPath: "/metadata/name",
keyword: "maxLength",
message: `should NOT be longer than 50 characters`,
keyword: "errorMessage",
message: `Not a valid extension name. It must consist of lowercase alphanumeric characters, dash, underscore and period only. Additionally, it may contain an npm-style package scope. For details see: https://sap.github.io/ui5-tooling/stable/pages/Configuration/#name`,
params: {
limit: 50,
errors: [{
dataPath: "/metadata/name",
keyword: "maxLength",
message: "should NOT be longer than 50 characters",
params: {
limit: 50,
}
}]
},
}]);
});
Expand Down
Loading

0 comments on commit e573adf

Please sign in to comment.