Skip to content

Commit

Permalink
[INTERNAL] Workspace Schema: Validate metadata.name
Browse files Browse the repository at this point in the history
Apply the same rules as for project and extension names.
Also see #552

Also update links to future Workspace configuration page.
  • Loading branch information
RandomByte committed Jan 27, 2023
1 parent d0ea703 commit da8439e
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 9 deletions.
9 changes: 7 additions & 2 deletions lib/validation/schema/ui5-workspace.json
Expand Up @@ -10,7 +10,7 @@
"additionalProperties": false,
"specVersion": {
"enum": ["workspace/1.0"],
"errorMessage": "Unsupported \"specVersion\"\nYour UI5 CLI installation might be outdated.\nSupported specification versions: \"workspace/1.0\"\nFor details see: // TODO: Add link to Documentation"
"errorMessage": "Unsupported \"specVersion\"\nYour UI5 CLI installation might be outdated.\nSupported specification versions: \"workspace/1.0\"\nFor details see: https://sap.github.io/ui5-tooling/stable/pages/Workspace/#workspace-specification-versions"
},
"metadata": {
"$ref": "#/definitions/metadata"
Expand All @@ -27,7 +27,12 @@
"additionalProperties": false,
"name": {
"type": "string",
"errorMessage": "Workspace name is not provided. There must be a wokrspace name defined."
"minLength": 3,
"maxLength": 50,
"pattern": "^(?:@[0-9a-z-_.]+\\/)?[a-z][0-9a-z-_.]*$",
"title": "Workspace Name",
"description": "Identifier for the workspace configuration. Workspaces named 'default' will be used automatically by UI5 Tooling",
"errorMessage": "Not a valid workspace 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/Workspace/#name"
}
}
},
Expand Down
127 changes: 120 additions & 7 deletions test/lib/validation/schema/ui5-workspace.js
Expand Up @@ -62,7 +62,7 @@ test("Empty config", async (t) => {
message: `Unsupported "specVersion"
Your UI5 CLI installation might be outdated.
Supported specification versions: "workspace/1.0"
For details see: // TODO: Add link to Documentation`,
For details see: https://sap.github.io/ui5-tooling/stable/pages/Workspace/#workspace-specification-versions`,
params: {
errors: [
{
Expand Down Expand Up @@ -143,6 +143,121 @@ test("Missing metadata.name", async (t) => {
);
});

test("Invalid metadata.name: Illegal characters", async (t) => {
await assertValidation(
t,
{
specVersion: "workspace/1.0",
metadata: {
name: "🦭🦭🦭"
},
dependencyManagement: {
resolutions: [
{
path: "path/to/resource/1",
},
],
},
},
[
{
dataPath: "/metadata/name",
keyword: "errorMessage",
message: "Not a valid workspace 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/Workspace/#name",
params: {
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-_.]*$",
},
},
],
},
},
]
);
});

test("Invalid metadata.name: Too short", async (t) => {
await assertValidation(
t,
{
specVersion: "workspace/1.0",
metadata: {
name: "a"
},
dependencyManagement: {
resolutions: [
{
path: "path/to/resource/1",
},
],
},
},
[
{
dataPath: "/metadata/name",
keyword: "errorMessage",
message: "Not a valid workspace 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/Workspace/#name",
params: {
errors: [
{
dataPath: "/metadata/name",
keyword: "minLength",
message: "should NOT be shorter than 3 characters",
params: {
limit: 3,
},
},
],
},
},
]
);
});


test("Invalid metadata.name: Too long", async (t) => {
await assertValidation(
t,
{
specVersion: "workspace/1.0",
metadata: {
name: "b".repeat(51)
},
dependencyManagement: {
resolutions: [
{
path: "path/to/resource/1",
},
],
},
},
[
{
dataPath: "/metadata/name",
keyword: "errorMessage",
message: "Not a valid workspace 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/Workspace/#name",
params: {
errors: [
{
dataPath: "/metadata/name",
keyword: "maxLength",
message: "should NOT be longer than 50 characters",
params: {
limit: 50,
},
}
],
},
},
]
);
});

test("Invalid fields", async (t) => {
await assertValidation(
t,
Expand All @@ -164,7 +279,7 @@ test("Invalid fields", async (t) => {
message: `Unsupported "specVersion"
Your UI5 CLI installation might be outdated.
Supported specification versions: "workspace/1.0"
For details see: // TODO: Add link to Documentation`,
For details see: https://sap.github.io/ui5-tooling/stable/pages/Workspace/#workspace-specification-versions`,
params: {
errors: [
{
Expand All @@ -182,8 +297,7 @@ For details see: // TODO: Add link to Documentation`,
{
dataPath: "/metadata/name",
keyword: "errorMessage",
message:
"Workspace name is not provided. There must be a wokrspace name defined.",
message: "Not a valid workspace 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/Workspace/#name",
params: {
errors: [
{
Expand Down Expand Up @@ -234,7 +348,7 @@ test("Invalid types", async (t) => {
message: `Unsupported "specVersion"
Your UI5 CLI installation might be outdated.
Supported specification versions: "workspace/1.0"
For details see: // TODO: Add link to Documentation`,
For details see: https://sap.github.io/ui5-tooling/stable/pages/Workspace/#workspace-specification-versions`,
params: {
errors: [
{
Expand All @@ -252,8 +366,7 @@ For details see: // TODO: Add link to Documentation`,
{
dataPath: "/metadata/name",
keyword: "errorMessage",
message:
"Workspace name is not provided. There must be a wokrspace name defined.",
message: "Not a valid workspace 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/Workspace/#name",
params: {
errors: [
{
Expand Down

0 comments on commit da8439e

Please sign in to comment.