mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 10:33:43 +08:00
feat(@angular-devkit/core): add a schema for smart default keyword
This commit is contained in:
parent
d8a2ebc039
commit
2dbd0894d0
@ -186,10 +186,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
|||||||
// in synchronous (if available).
|
// in synchronous (if available).
|
||||||
let validator: Observable<ajv.ValidateFunction>;
|
let validator: Observable<ajv.ValidateFunction>;
|
||||||
try {
|
try {
|
||||||
const maybeFnValidate = this._ajv.compile({
|
const maybeFnValidate = this._ajv.compile(schema);
|
||||||
$async: this._smartDefaultKeyword ? true : undefined,
|
|
||||||
...schema,
|
|
||||||
});
|
|
||||||
validator = observableOf(maybeFnValidate);
|
validator = observableOf(maybeFnValidate);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Propagate the error.
|
// Propagate the error.
|
||||||
@ -293,8 +290,8 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
|||||||
this._smartDefaultKeyword = true;
|
this._smartDefaultKeyword = true;
|
||||||
|
|
||||||
this._ajv.addKeyword('$default', {
|
this._ajv.addKeyword('$default', {
|
||||||
modifying: true,
|
errors: false,
|
||||||
async: true,
|
valid: true,
|
||||||
compile: (schema, _parentSchema, it) => {
|
compile: (schema, _parentSchema, it) => {
|
||||||
// We cheat, heavily.
|
// We cheat, heavily.
|
||||||
this._smartDefaultRecord.set(
|
this._smartDefaultRecord.set(
|
||||||
@ -303,9 +300,15 @@ export class CoreSchemaRegistry implements SchemaRegistry {
|
|||||||
schema,
|
schema,
|
||||||
);
|
);
|
||||||
|
|
||||||
return function() {
|
return () => true;
|
||||||
return Promise.resolve(true);
|
},
|
||||||
};
|
metaSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
'$source': { type: 'string' },
|
||||||
|
},
|
||||||
|
additionalProperties: true,
|
||||||
|
required: [ '$source' ],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user