Skip to content

Commit abced26

Browse files
committed
Add Inline dereferencing. Looking for definitions
1 parent 0858be4 commit abced26

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

src/wjelement/schema.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,42 @@ static XplBool SchemaValidate(WJElement schema, WJElement document,
427427

428428
/* swap in any $ref'erenced schema */
429429
if(loadcb && (str = WJEString(schema, "[\"$ref\"]", WJE_GET, NULL))) {
430-
sub = loadcb(str, client, __FILE__, __LINE__);
431-
fail = SchemaValidate(sub, document, err, loadcb, freecb, client,
432-
name, version);
433-
if(freecb) {
434-
freecb(sub, client);
435-
} else {
436-
WJECloseDocument(sub);
437-
}
430+
// Johan: Add Inline dereferencing. Looking for definitions
431+
const char* inline_dereferencing = "#/definitions/";
432+
if (strncmp (inline_dereferencing, str, strlen (inline_dereferencing)) == 0) {
433+
WJElement schema_root = schema->parent;
434+
while (schema_root->parent) {
435+
schema_root = schema_root->parent;
436+
}
437+
438+
WJElement schema_definitions = WJEObject(schema_root, "definitions", WJE_GET);
439+
if (schema_definitions) {
440+
char *ptr = strrchr (str, '/');
441+
if (ptr) {
442+
++ptr;
443+
sub = WJEObject(schema_definitions, ptr, WJE_GET);
444+
if (sub) {
445+
fail = SchemaValidate (sub, document, err, loadcb, freecb, client,
446+
name,
447+
version);
448+
}
449+
}
450+
}
451+
}
452+
453+
if (!sub) {
454+
sub = loadcb (str, client, __FILE__, __LINE__);
455+
456+
fail = SchemaValidate (sub, document, err, loadcb, freecb, client,
457+
name,
458+
version);
459+
if (freecb) {
460+
freecb (sub, client);
461+
}
462+
else {
463+
WJECloseDocument (sub);
464+
}
465+
}
438466
return fail;
439467
}
440468

0 commit comments

Comments
 (0)