Skip to content

Commit 371bd61

Browse files
cexbrayatvikerman
authored andcommitted
fix(@angular/cli): validate version in doc command
As the JSON Schema validation is minimum in the CLI, we have to also validate in code. This PR: - updates the JSON Schema to use `number` and `enum` instead of `integer` and `const` that are not supported. - adds validation in the doc command implementation - adds error reporting if the version is not valid - fixes a typo in an error message in the parser
1 parent bbb12e3 commit 371bd61

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

packages/angular/cli/commands/doc-impl.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ export class DocCommand extends Command<DocCommandSchema> {
2323
let domain = 'angular.io';
2424

2525
if (options.version) {
26+
// version can either be a string containing "next"
2627
if (options.version == 'next') {
2728
domain = 'next.angular.io';
28-
} else {
29+
// or a number where version must be a valid Angular version (i.e. not 0, 1 or 3)
30+
} else if (!isNaN(+options.version) && ![0, 1, 3].includes(+options.version)) {
2931
domain = `v${options.version}.angular.io`;
32+
} else {
33+
this.logger.error('Version should either be a number (2, 4, 5, 6...) or "next"');
34+
35+
return 0;
3036
}
3137
}
3238

packages/angular/cli/commands/doc.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@
2727
"description": "When true, searches all of angular.io. Otherwise, searches only API reference documentation."
2828
},
2929
"version" : {
30-
"anyOf": [
30+
"oneOf": [
3131
{
32-
"const" : 2
33-
},
34-
{
35-
"type" : "integer",
32+
"type": "number",
3633
"minimum": 4
3734
},
3835
{
39-
"const": "next"
36+
"enum": [2, "next"]
4037
}
4138
],
4239
"description": "Contains the version of Angular to use for the documentation."

packages/angular/cli/models/parser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class ParseArgumentException extends BaseException {
1616
public readonly parsed: Arguments,
1717
public readonly ignored: string[],
1818
) {
19-
super(`One or more errors occured while parsing arguments:\n ${comments.join('\n ')}`);
19+
super(`One or more errors occurred while parsing arguments:\n ${comments.join('\n ')}`);
2020
}
2121
}
2222

0 commit comments

Comments
 (0)