feat(@angular-devkit/core): add a schema for smart default keyword

This commit is contained in:
Charles Lyding 2018-07-01 19:55:17 -04:00 committed by Hans
parent d8a2ebc039
commit 2dbd0894d0

View File

@ -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' ],
}, },
}); });
} }