Skip to content

Commit d7b464c

Browse files
committed
Merge pull request #43 from johog/master
Looks good, I'm gonna go a bit out of order: merge first and test second. :^)
2 parents 6e40844 + 5acac64 commit d7b464c

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

src/wjelement/schema.c

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,45 @@ static XplBool SchemaValidate(WJElement schema, WJElement document,
426426
}
427427

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

0 commit comments

Comments
 (0)