Skip to content

Commit

Permalink
[BREAKING] Schema: Restrict metadata.name for specVersion >= 3.0
Browse files Browse the repository at this point in the history
As proposed in chapter 6 of RFC0012([1]), restrict the 'name' property for
projects and extensions defining specification version 3.0 and later.

BREAKING CHANGE:

For projects and extensions defining specVersion 3.0 and later, the
metadata.name property must satisfy the following conditions:

* Must be at least 3 characters long
* Must be no longer than 50 characters
* Must contain lowercase characters only
* Must contain alphanumeric characters, dash, underscore and period only
    - Exception: `@` and `/` are allowed at certain positions as
      explained below
* Must start with an alphabetic character or an `@`-character
* If a name starts with an `@`-character, it must contain exactly one
  forward-slash `/`
    - This is aligned with the npm concept for package scopes
    - e.g. `@org/lib.name`

For details, please see refer to chapter 6 of RFC0012([1]).

[1]: SAP/ui5-tooling#664
  • Loading branch information
RandomByte committed Jan 24, 2023
1 parent cf96b6f commit 3fde053
Show file tree
Hide file tree
Showing 18 changed files with 670 additions and 107 deletions.
5 changes: 4 additions & 1 deletion lib/specifications/Specification.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Specification {
this._log.verbose(err.message);
throw new Error(
`${config.kind} ${config.metadata.name} defines unsupported Specification Version ` +
`${originalSpecVersion}. Please manually upgrade to 2.0 or higher. ` +
`${originalSpecVersion}. Please manually upgrade to 3.0 or higher. ` +
`For details see https://sap.github.io/ui5-tooling/pages/Configuration/#specification-versions - ` +
`An attempted migration to a supported specification version failed, ` +
`likely due to unrecognized configuration. Check verbose log for details.`);
Expand Down Expand Up @@ -249,6 +249,9 @@ class Specification {
}

_migrateLegacyProject(config) {
// Stick to 2.6 since 3.0 adds further restrictions (i.e. for the name) and enables
// functionality for extensions that shouldn't be enabled if the specVersion is not
// explicitly set to 3.x
config.specVersion = "2.6";

// propertiesFileSourceEncoding (relevant for applications and libraries) default
Expand Down
16 changes: 16 additions & 0 deletions lib/validation/schema/specVersion/kind/extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@
"type": "string"
}
}
},
"metadata-3.0": {
"type": "object",
"required": ["name"],
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"minLength": 3,
"maxLength": 50,
"pattern": "^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$"
},
"copyright": {
"type": "string"
}
}
}
}
}
69 changes: 50 additions & 19 deletions lib/validation/schema/specVersion/kind/extension/project-shim.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"required": ["specVersion", "kind", "type", "metadata", "shims"],
"if": {
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "3.0"] }
"specVersion": { "enum": ["3.0"] }
}
},
"then": {
"additionalProperties": false,
"properties": {
"specVersion": {
"enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "3.0"]
"enum": ["3.0"]
},
"kind": {
"enum": ["extension"]
Expand All @@ -22,7 +22,7 @@
"enum": ["project-shim"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
"$ref": "../extension.json#/definitions/metadata-3.0"
},
"shims": {
"$ref": "#/definitions/shims"
Expand All @@ -34,22 +34,53 @@
}
},
"else": {
"additionalProperties": false,
"properties": {
"specVersion": {
"enum": ["2.0"]
},
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["project-shim"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
},
"shims": {
"$ref": "#/definitions/shims"
"if": {
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6"] }
}
},
"then": {
"additionalProperties": false,
"properties": {
"specVersion": {
"enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6"]
},
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["project-shim"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
},
"shims": {
"$ref": "#/definitions/shims"
},
"customConfiguration": {
"type": "object",
"additionalProperties": true
}
}
},
"else": {
"additionalProperties": false,
"properties": {
"specVersion": {
"enum": ["2.0"]
},
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["project-shim"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
},
"shims": {
"$ref": "#/definitions/shims"
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
"required": ["specVersion", "kind", "type", "metadata", "middleware"],
"if": {
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "3.0"] }
"specVersion": { "enum": ["3.0"] }
}
},
"then": {
"additionalProperties": false,
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "3.0"] },
"specVersion": { "enum": ["3.0"] },
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["server-middleware"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
"$ref": "../extension.json#/definitions/metadata-3.0"
},
"middleware": {
"$ref": "#/definitions/middleware"
Expand All @@ -33,20 +33,49 @@
}
},
"else": {
"additionalProperties": false,
"properties": {
"specVersion": { "enum": ["2.0"] },
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["server-middleware"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
},
"middleware": {
"$ref": "#/definitions/middleware"
"if": {
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6"] }
}
},
"then": {
"additionalProperties": false,
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6"] },
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["server-middleware"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
},
"middleware": {
"$ref": "#/definitions/middleware"
},
"customConfiguration": {
"type": "object",
"additionalProperties": true
}
}
},
"else": {
"additionalProperties": false,
"properties": {
"specVersion": { "enum": ["2.0"] },
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["server-middleware"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
},
"middleware": {
"$ref": "#/definitions/middleware"
}
}
}
},
Expand Down
63 changes: 46 additions & 17 deletions lib/validation/schema/specVersion/kind/extension/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
"required": ["specVersion", "kind", "type", "metadata", "task"],
"if": {
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "3.0"] }
"specVersion": { "enum": ["3.0"] }
}
},
"then": {
"additionalProperties": false,
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "3.0"] },
"specVersion": { "enum": ["3.0"] },
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["task"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
"$ref": "../extension.json#/definitions/metadata-3.0"
},
"task": {
"$ref": "#/definitions/task"
Expand All @@ -32,20 +32,49 @@
}
},
"else": {
"additionalProperties": false,
"properties": {
"specVersion": { "enum": ["2.0"] },
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["task"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
},
"task": {
"$ref": "#/definitions/task"
"if": {
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6"] }
}
},
"then": {
"additionalProperties": false,
"properties": {
"specVersion": { "enum": ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6"] },
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["task"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
},
"task": {
"$ref": "#/definitions/task"
},
"customConfiguration": {
"type": "object",
"additionalProperties": true
}
}
},
"else": {
"additionalProperties": false,
"properties": {
"specVersion": { "enum": ["2.0"] },
"kind": {
"enum": ["extension"]
},
"type": {
"enum": ["task"]
},
"metadata": {
"$ref": "../extension.json#/definitions/metadata"
},
"task": {
"$ref": "#/definitions/task"
}
}
}
},
Expand Down
28 changes: 28 additions & 0 deletions lib/validation/schema/specVersion/kind/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@
}
}
},
"metadata-3.0": {
"type": "object",
"required": ["name"],
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"minLength": 3,
"maxLength": 50,
"pattern": "^(?:@[0-9a-z-_.]+/)?[a-z][0-9a-z-_.]*$"
},
"copyright": {
"type": "string"
},
"deprecated": {
"type": "boolean",
"default": false
},
"sapInternal": {
"type": "boolean",
"default": false
},
"allowSapInternal": {
"type": "boolean",
"default": false
}
}
},
"resources-configuration-propertiesFileSourceEncoding": {
"enum": ["UTF-8", "ISO-8859-1"],
"default": "UTF-8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"enum": ["application"]
},
"metadata": {
"$ref": "../project.json#/definitions/metadata"
"$ref": "../project.json#/definitions/metadata-3.0"
},
"framework": {
"$ref": "../project.json#/definitions/framework"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"enum": ["library"]
},
"metadata": {
"$ref": "../project.json#/definitions/metadata"
"$ref": "../project.json#/definitions/metadata-3.0"
},
"framework": {
"$ref": "../project.json#/definitions/framework"
Expand Down
Loading

0 comments on commit 3fde053

Please sign in to comment.