Skip to content

Commit d299ef7

Browse files
clydinvikerman
authored andcommitted
fix(@angular-devkit/core): correctly resolve schema references
1 parent cdbc198 commit d299ef7

File tree

1 file changed

+10
-12
lines changed
  • packages/angular_devkit/core/src/json/schema

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,21 @@ export class CoreSchemaRegistry implements SchemaRegistry {
171171
ref: string,
172172
validate: ajv.ValidateFunction,
173173
): { context?: ajv.ValidateFunction, schema?: JsonObject } {
174-
if (!validate) {
174+
if (!validate || !validate.refs || !validate.refVal || !ref) {
175175
return {};
176176
}
177177

178-
const refHash = ref.split('#', 2)[1];
179-
const refUrl = ref.startsWith('#') ? ref : ref.split('#', 1);
180-
181-
if (!ref.startsWith('#')) {
182-
// tslint:disable-next-line:no-any
183-
validate = (validate.refVal as any)[(validate.refs as any)[refUrl[0]]];
184-
}
185-
if (validate && refHash) {
186-
// tslint:disable-next-line:no-any
187-
validate = (validate.refVal as any)[(validate.refs as any)['#' + refHash]];
178+
// tslint:disable-next-line:no-any
179+
const id = (validate.schema as any).$id || (validate.schema as any).id;
180+
let fullReference = (ref[0] === '#' && id) ? id + ref : ref;
181+
if (fullReference.endsWith('#')) {
182+
fullReference = fullReference.slice(0, -1);
188183
}
189184

190-
return { context: validate, schema: validate && validate.schema as JsonObject };
185+
// tslint:disable-next-line:no-any
186+
const context = validate.refVal[(validate.refs as any)[fullReference]];
187+
188+
return { context, schema: context && context.schema as JsonObject };
191189
}
192190

193191
compile(schema: JsonObject): Observable<SchemaValidator> {

0 commit comments

Comments
 (0)