Skip to content

Commit 0875313

Browse files
alan-agius4clydin
authored andcommitted
feat(@angular-devkit/core): update schema validator
With this change we update ajv to version 8 BREAKING CHANGE: support for JSON Schema draft-04 and draft-06 is removed. If you have schemas using the `id` keyword replace them with `$id`. For an interim period we will auto rename any top level `id` keyword to `$id`. **NB**: This change only effects schematics and builders authors.
1 parent c609e71 commit 0875313

File tree

10 files changed

+140
-256
lines changed

10 files changed

+140
-256
lines changed

etc/api/angular_devkit/core/src/_golden-api.d.ts

+4-49
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
export interface AdditionalPropertiesValidatorError extends SchemaValidatorErrorBase {
2-
keyword: 'additionalProperties';
3-
params: {
4-
additionalProperty: string;
5-
};
6-
}
7-
81
export declare function addUndefinedDefaults(value: JsonValue, _pointer: JsonPointer, schema?: JsonSchema): JsonValue;
92

103
export declare class AliasHost<StatsT extends object = {}> extends ResolverHost<StatsT> {
@@ -157,8 +150,8 @@ export interface CordHostRename {
157150

158151
export declare class CoreSchemaRegistry implements SchemaRegistry {
159152
constructor(formats?: SchemaFormat[]);
160-
protected _resolver(ref: string, validate?: ajv.ValidateFunction): {
161-
context?: ajv.ValidateFunction;
153+
protected _resolver(ref: string, validate?: ValidateFunction): {
154+
context?: ValidateFunction;
162155
schema?: JsonObject;
163156
};
164157
addFormat(format: SchemaFormat): void;
@@ -228,13 +221,6 @@ export declare class FileDoesNotExistException extends BaseException {
228221
constructor(path: string);
229222
}
230223

231-
export interface FormatValidatorError extends SchemaValidatorErrorBase {
232-
keyword: 'format';
233-
params: {
234-
format: string;
235-
};
236-
}
237-
238224
export declare class ForwardingAnalytics implements Analytics {
239225
protected _fn: AnalyticsForwarderFn;
240226
constructor(_fn: AnalyticsForwarderFn);
@@ -451,13 +437,6 @@ export declare class LevelTransformLogger extends Logger {
451437

452438
export declare function levenshtein(a: string, b: string): number;
453439

454-
export interface LimitValidatorError extends SchemaValidatorErrorBase {
455-
keyword: 'maxItems' | 'minItems' | 'maxLength' | 'minLength' | 'maxProperties' | 'minProperties';
456-
params: {
457-
limit: number;
458-
};
459-
}
460-
461440
export interface LogEntry extends LoggerMetadata {
462441
level: LogLevel;
463442
message: string;
@@ -746,24 +725,10 @@ export interface ReferenceResolver<ContextT> {
746725
};
747726
}
748727

749-
export interface RefValidatorError extends SchemaValidatorErrorBase {
750-
keyword: '$ref';
751-
params: {
752-
ref: string;
753-
};
754-
}
755-
756728
export declare function relative(from: Path, to: Path): Path;
757729

758730
export declare type ReplacementFunction = (path: Path) => Path;
759731

760-
export interface RequiredValidatorError extends SchemaValidatorErrorBase {
761-
keyword: 'required';
762-
params: {
763-
missingProperty: string;
764-
};
765-
}
766-
767732
export declare function resetNormalizeCache(): void;
768733

769734
export declare function resolve(p1: Path, p2: Path): Path;
@@ -801,10 +766,7 @@ export interface SchemaFormat {
801766
name: string;
802767
}
803768

804-
export interface SchemaFormatter {
805-
readonly async: boolean;
806-
validate(data: any): boolean | Observable<boolean>;
807-
}
769+
export declare type SchemaFormatter = Format;
808770

809771
export interface SchemaKeywordValidator {
810772
(data: JsonValue, schema: JsonValue, parent: JsonObject | JsonArray | undefined, parentProperty: string | number | undefined, pointer: JsonPointer, rootData: JsonValue): boolean | Observable<boolean>;
@@ -831,14 +793,7 @@ export interface SchemaValidator {
831793
(data: JsonValue, options?: SchemaValidatorOptions): Observable<SchemaValidatorResult>;
832794
}
833795

834-
export declare type SchemaValidatorError = RefValidatorError | LimitValidatorError | AdditionalPropertiesValidatorError | FormatValidatorError | RequiredValidatorError;
835-
836-
export interface SchemaValidatorErrorBase {
837-
data?: JsonValue;
838-
dataPath: string;
839-
keyword: string;
840-
message?: string;
841-
}
796+
export declare type SchemaValidatorError = ErrorObject;
842797

843798
export interface SchemaValidatorOptions {
844799
applyPostTransforms?: boolean;

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@
122122
"@types/webpack-dev-server": "^3.1.7",
123123
"@types/webpack-sources": "^2.0.0",
124124
"@yarnpkg/lockfile": "1.1.0",
125-
"ajv": "6.12.6",
125+
"ajv": "8.1.0",
126+
"ajv-formats": "2.0.2",
126127
"ansi-colors": "4.1.1",
127128
"babel-loader": "8.2.2",
128129
"bootstrap": "^4.0.0",

packages/angular_devkit/core/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ts_library(
3737
deps = [
3838
"@npm//@types/node",
3939
"@npm//ajv",
40+
"@npm//ajv-formats",
4041
"@npm//fast-json-stable-stringify",
4142
"@npm//magic-string",
4243
"@npm//rxjs",

packages/angular_devkit/core/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"core"
99
],
1010
"dependencies": {
11-
"ajv": "6.12.6",
11+
"ajv": "8.1.0",
12+
"ajv-formats": "2.0.2",
1213
"fast-json-stable-stringify": "2.1.0",
1314
"magic-string": "0.25.7",
1415
"rxjs": "6.6.7",

packages/angular_devkit/core/src/json/schema/interface.ts

+4-46
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,21 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import { ErrorObject, Format } from 'ajv';
89
import { Observable, SubscribableOrPromise } from 'rxjs';
910
import { JsonArray, JsonObject, JsonValue } from '../interface';
1011

1112
export type JsonPointer = string & {
1213
__PRIVATE_DEVKIT_JSON_POINTER: void;
1314
};
14-
15-
export type SchemaValidatorError =
16-
RefValidatorError |
17-
LimitValidatorError |
18-
AdditionalPropertiesValidatorError |
19-
FormatValidatorError |
20-
RequiredValidatorError;
21-
22-
export interface SchemaValidatorErrorBase {
23-
keyword: string;
24-
dataPath: string;
25-
message?: string;
26-
data?: JsonValue;
27-
}
28-
29-
export interface RefValidatorError extends SchemaValidatorErrorBase {
30-
keyword: '$ref';
31-
params: { ref: string };
32-
}
33-
34-
export interface LimitValidatorError extends SchemaValidatorErrorBase {
35-
keyword: 'maxItems' | 'minItems' | 'maxLength' | 'minLength' | 'maxProperties' | 'minProperties';
36-
params: { limit: number };
37-
}
38-
39-
export interface AdditionalPropertiesValidatorError extends SchemaValidatorErrorBase {
40-
keyword: 'additionalProperties';
41-
params: { additionalProperty: string };
42-
}
43-
44-
export interface FormatValidatorError extends SchemaValidatorErrorBase {
45-
keyword: 'format';
46-
params: { format: string };
47-
}
48-
49-
export interface RequiredValidatorError extends SchemaValidatorErrorBase {
50-
keyword: 'required';
51-
params: { missingProperty: string };
52-
}
53-
5415
export interface SchemaValidatorResult {
5516
data: JsonValue;
5617
success: boolean;
5718
errors?: SchemaValidatorError[];
5819
}
5920

21+
export type SchemaValidatorError = ErrorObject;
22+
6023
export interface SchemaValidatorOptions {
6124
applyPreTransforms?: boolean;
6225
applyPostTransforms?: boolean;
@@ -67,12 +30,7 @@ export interface SchemaValidator {
6730
(data: JsonValue, options?: SchemaValidatorOptions): Observable<SchemaValidatorResult>;
6831
}
6932

70-
export interface SchemaFormatter {
71-
readonly async: boolean;
72-
// TODO should be unknown remove before next major release
73-
// tslint:disable-next-line:no-any
74-
validate(data: any): boolean | Observable<boolean>;
75-
}
33+
export type SchemaFormatter = Format;
7634

7735
export interface SchemaFormat {
7836
name: string;

0 commit comments

Comments
 (0)