2 * Copyright (c) 2014, Vsevolod Stakhov
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "ucl_internal.h"
43 static bool ucl_schema_validate (const ucl_object_t *schema,
44 const ucl_object_t *obj, bool try_array,
45 struct ucl_schema_error *err,
46 const ucl_object_t *root);
49 ucl_string_to_type (const char *input, ucl_type_t *res)
51 if (strcasecmp (input, "object") == 0) {
54 else if (strcasecmp (input, "array") == 0) {
57 else if (strcasecmp (input, "integer") == 0) {
60 else if (strcasecmp (input, "number") == 0) {
63 else if (strcasecmp (input, "string") == 0) {
66 else if (strcasecmp (input, "boolean") == 0) {
69 else if (strcasecmp (input, "null") == 0) {
80 ucl_object_type_to_string (ucl_type_t type)
82 const char *res = "unknown";
114 * Create validation error
117 ucl_schema_create_error (struct ucl_schema_error *err,
118 enum ucl_schema_error_code code, const ucl_object_t *obj,
119 const char *fmt, ...)
127 vsnprintf (err->msg, sizeof (err->msg), fmt, va);
133 * Check whether we have a pattern specified
135 static const ucl_object_t *
136 ucl_schema_test_pattern (const ucl_object_t *obj, const char *pattern)
138 const ucl_object_t *res = NULL;
141 const ucl_object_t *elt;
142 ucl_object_iter_t iter = NULL;
144 if (regcomp (®, pattern, REG_EXTENDED | REG_NOSUB) == 0) {
145 while ((elt = ucl_iterate_object (obj, &iter, true)) != NULL) {
146 if (regexec (®, ucl_object_key (elt), 0, NULL, 0) == 0) {
158 * Check dependencies for an object
161 ucl_schema_validate_dependencies (const ucl_object_t *deps,
162 const ucl_object_t *obj, struct ucl_schema_error *err,
163 const ucl_object_t *root)
165 const ucl_object_t *elt, *cur, *cur_dep;
166 ucl_object_iter_t iter = NULL, piter;
169 while (ret && (cur = ucl_iterate_object (deps, &iter, true)) != NULL) {
170 elt = ucl_object_find_key (obj, ucl_object_key (cur));
172 /* Need to check dependencies */
173 if (cur->type == UCL_ARRAY) {
175 while (ret && (cur_dep = ucl_iterate_object (cur, &piter, true)) != NULL) {
176 if (ucl_object_find_key (obj, ucl_object_tostring (cur_dep)) == NULL) {
177 ucl_schema_create_error (err, UCL_SCHEMA_MISSING_DEPENDENCY, elt,
178 "dependency %s is missing for key %s",
179 ucl_object_tostring (cur_dep), ucl_object_key (cur));
185 else if (cur->type == UCL_OBJECT) {
186 ret = ucl_schema_validate (cur, obj, true, err, root);
198 ucl_schema_validate_object (const ucl_object_t *schema,
199 const ucl_object_t *obj, struct ucl_schema_error *err,
200 const ucl_object_t *root)
202 const ucl_object_t *elt, *prop, *found, *additional_schema = NULL,
203 *required = NULL, *pat, *pelt;
204 ucl_object_iter_t iter = NULL, piter = NULL;
205 bool ret = true, allow_additional = true;
208 while (ret && (elt = ucl_iterate_object (schema, &iter, true)) != NULL) {
209 if (elt->type == UCL_OBJECT &&
210 strcmp (ucl_object_key (elt), "properties") == 0) {
212 while (ret && (prop = ucl_iterate_object (elt, &piter, true)) != NULL) {
213 found = ucl_object_find_key (obj, ucl_object_key (prop));
215 ret = ucl_schema_validate (prop, found, true, err, root);
219 else if (strcmp (ucl_object_key (elt), "additionalProperties") == 0) {
220 if (elt->type == UCL_BOOLEAN) {
221 if (!ucl_object_toboolean (elt)) {
222 /* Deny additional fields completely */
223 allow_additional = false;
226 else if (elt->type == UCL_OBJECT) {
227 /* Define validator for additional fields */
228 additional_schema = elt;
231 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt,
232 "additionalProperties attribute is invalid in schema");
237 else if (strcmp (ucl_object_key (elt), "required") == 0) {
238 if (elt->type == UCL_ARRAY) {
242 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt,
243 "required attribute is invalid in schema");
248 else if (strcmp (ucl_object_key (elt), "minProperties") == 0
249 && ucl_object_toint_safe (elt, &minmax)) {
250 if (obj->len < minmax) {
251 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
252 "object has not enough properties: %u, minimum is: %u",
253 obj->len, (unsigned)minmax);
258 else if (strcmp (ucl_object_key (elt), "maxProperties") == 0
259 && ucl_object_toint_safe (elt, &minmax)) {
260 if (obj->len > minmax) {
261 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
262 "object has too many properties: %u, maximum is: %u",
263 obj->len, (unsigned)minmax);
268 else if (strcmp (ucl_object_key (elt), "patternProperties") == 0) {
270 while (ret && (prop = ucl_iterate_object (elt, &piter, true)) != NULL) {
271 found = ucl_schema_test_pattern (obj, ucl_object_key (prop));
273 ret = ucl_schema_validate (prop, found, true, err, root);
277 else if (elt->type == UCL_OBJECT &&
278 strcmp (ucl_object_key (elt), "dependencies") == 0) {
279 ret = ucl_schema_validate_dependencies (elt, obj, err, root);
284 /* Additional properties */
285 if (!allow_additional || additional_schema != NULL) {
286 /* Check if we have exactly the same properties in schema and object */
288 prop = ucl_object_find_key (schema, "properties");
289 while ((elt = ucl_iterate_object (obj, &iter, true)) != NULL) {
290 found = ucl_object_find_key (prop, ucl_object_key (elt));
292 /* Try patternProperties */
294 pat = ucl_object_find_key (schema, "patternProperties");
295 while ((pelt = ucl_iterate_object (pat, &piter, true)) != NULL) {
296 found = ucl_schema_test_pattern (obj, ucl_object_key (pelt));
303 if (!allow_additional) {
304 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
305 "object has non-allowed property %s",
306 ucl_object_key (elt));
310 else if (additional_schema != NULL) {
311 if (!ucl_schema_validate (additional_schema, elt, true, err, root)) {
319 /* Required properties */
320 if (required != NULL) {
322 while ((elt = ucl_iterate_object (required, &iter, true)) != NULL) {
323 if (ucl_object_find_key (obj, ucl_object_tostring (elt)) == NULL) {
324 ucl_schema_create_error (err, UCL_SCHEMA_MISSING_PROPERTY, obj,
325 "object has missing property %s",
326 ucl_object_tostring (elt));
339 ucl_schema_validate_number (const ucl_object_t *schema,
340 const ucl_object_t *obj, struct ucl_schema_error *err)
342 const ucl_object_t *elt, *test;
343 ucl_object_iter_t iter = NULL;
344 bool ret = true, exclusive = false;
345 double constraint, val;
346 const double alpha = 1e-16;
348 while (ret && (elt = ucl_iterate_object (schema, &iter, true)) != NULL) {
349 if ((elt->type == UCL_FLOAT || elt->type == UCL_INT) &&
350 strcmp (ucl_object_key (elt), "multipleOf") == 0) {
351 constraint = ucl_object_todouble (elt);
352 if (constraint <= 0) {
353 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt,
354 "multipleOf must be greater than zero");
358 val = ucl_object_todouble (obj);
359 if (fabs (remainder (val, constraint)) > alpha) {
360 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
361 "number %.4f is not multiple of %.4f, remainder is %.7f",
367 else if ((elt->type == UCL_FLOAT || elt->type == UCL_INT) &&
368 strcmp (ucl_object_key (elt), "maximum") == 0) {
369 constraint = ucl_object_todouble (elt);
370 test = ucl_object_find_key (schema, "exclusiveMaximum");
371 if (test && test->type == UCL_BOOLEAN) {
372 exclusive = ucl_object_toboolean (test);
374 val = ucl_object_todouble (obj);
375 if (val > constraint || (exclusive && val >= constraint)) {
376 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
377 "number is too big: %.3f, maximum is: %.3f",
383 else if ((elt->type == UCL_FLOAT || elt->type == UCL_INT) &&
384 strcmp (ucl_object_key (elt), "minimum") == 0) {
385 constraint = ucl_object_todouble (elt);
386 test = ucl_object_find_key (schema, "exclusiveMinimum");
387 if (test && test->type == UCL_BOOLEAN) {
388 exclusive = ucl_object_toboolean (test);
390 val = ucl_object_todouble (obj);
391 if (val < constraint || (exclusive && val <= constraint)) {
392 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
393 "number is too small: %.3f, minimum is: %.3f",
405 ucl_schema_validate_string (const ucl_object_t *schema,
406 const ucl_object_t *obj, struct ucl_schema_error *err)
408 const ucl_object_t *elt;
409 ucl_object_iter_t iter = NULL;
416 while (ret && (elt = ucl_iterate_object (schema, &iter, true)) != NULL) {
417 if (elt->type == UCL_INT &&
418 strcmp (ucl_object_key (elt), "maxLength") == 0) {
419 constraint = ucl_object_toint (elt);
420 if (obj->len > constraint) {
421 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
422 "string is too big: %.3f, maximum is: %.3f",
423 obj->len, constraint);
428 else if (elt->type == UCL_INT &&
429 strcmp (ucl_object_key (elt), "minLength") == 0) {
430 constraint = ucl_object_toint (elt);
431 if (obj->len < constraint) {
432 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
433 "string is too short: %.3f, minimum is: %.3f",
434 obj->len, constraint);
440 else if (elt->type == UCL_STRING &&
441 strcmp (ucl_object_key (elt), "pattern") == 0) {
442 if (regcomp (&re, ucl_object_tostring (elt),
443 REG_EXTENDED | REG_NOSUB) != 0) {
444 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt,
445 "cannot compile pattern %s", ucl_object_tostring (elt));
449 if (regexec (&re, ucl_object_tostring (obj), 0, NULL, 0) != 0) {
450 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
451 "string doesn't match regexp %s",
452 ucl_object_tostring (elt));
463 struct ucl_compare_node {
464 const ucl_object_t *obj;
465 TREE_ENTRY(ucl_compare_node) link;
466 struct ucl_compare_node *next;
469 typedef TREE_HEAD(_tree, ucl_compare_node) ucl_compare_tree_t;
471 TREE_DEFINE(ucl_compare_node, link)
474 ucl_schema_elt_compare (struct ucl_compare_node *n1, struct ucl_compare_node *n2)
476 const ucl_object_t *o1 = n1->obj, *o2 = n2->obj;
478 return ucl_object_compare (o1, o2);
482 ucl_schema_array_is_unique (const ucl_object_t *obj, struct ucl_schema_error *err)
484 ucl_compare_tree_t tree = TREE_INITIALIZER (ucl_schema_elt_compare);
485 ucl_object_iter_t iter = NULL;
486 const ucl_object_t *elt;
487 struct ucl_compare_node *node, test, *nodes = NULL, *tmp;
490 while ((elt = ucl_iterate_object (obj, &iter, true)) != NULL) {
492 node = TREE_FIND (&tree, ucl_compare_node, link, &test);
494 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, elt,
495 "duplicate values detected while uniqueItems is true");
499 node = calloc (1, sizeof (*node));
501 ucl_schema_create_error (err, UCL_SCHEMA_UNKNOWN, elt,
502 "cannot allocate tree node");
507 TREE_INSERT (&tree, ucl_compare_node, link, node);
508 LL_PREPEND (nodes, node);
511 LL_FOREACH_SAFE (nodes, node, tmp) {
519 ucl_schema_validate_array (const ucl_object_t *schema,
520 const ucl_object_t *obj, struct ucl_schema_error *err,
521 const ucl_object_t *root)
523 const ucl_object_t *elt, *it, *found, *additional_schema = NULL,
524 *first_unvalidated = NULL;
525 ucl_object_iter_t iter = NULL, piter = NULL;
526 bool ret = true, allow_additional = true, need_unique = false;
529 while (ret && (elt = ucl_iterate_object (schema, &iter, true)) != NULL) {
530 if (strcmp (ucl_object_key (elt), "items") == 0) {
531 if (elt->type == UCL_ARRAY) {
532 found = obj->value.av;
533 while (ret && (it = ucl_iterate_object (elt, &piter, true)) != NULL) {
535 ret = ucl_schema_validate (it, found, false, err, root);
540 /* The first element that is not validated */
541 first_unvalidated = found;
544 else if (elt->type == UCL_OBJECT) {
545 /* Validate all items using the specified schema */
546 while (ret && (it = ucl_iterate_object (obj, &piter, true)) != NULL) {
547 ret = ucl_schema_validate (elt, it, false, err, root);
551 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt,
552 "items attribute is invalid in schema");
557 else if (strcmp (ucl_object_key (elt), "additionalItems") == 0) {
558 if (elt->type == UCL_BOOLEAN) {
559 if (!ucl_object_toboolean (elt)) {
560 /* Deny additional fields completely */
561 allow_additional = false;
564 else if (elt->type == UCL_OBJECT) {
565 /* Define validator for additional fields */
566 additional_schema = elt;
569 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt,
570 "additionalItems attribute is invalid in schema");
575 else if (elt->type == UCL_BOOLEAN &&
576 strcmp (ucl_object_key (elt), "uniqueItems") == 0) {
577 need_unique = ucl_object_toboolean (elt);
579 else if (strcmp (ucl_object_key (elt), "minItems") == 0
580 && ucl_object_toint_safe (elt, &minmax)) {
581 if (obj->len < minmax) {
582 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
583 "array has not enough items: %u, minimum is: %u",
584 obj->len, (unsigned)minmax);
589 else if (strcmp (ucl_object_key (elt), "maxItems") == 0
590 && ucl_object_toint_safe (elt, &minmax)) {
591 if (obj->len > minmax) {
592 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
593 "array has too many items: %u, maximum is: %u",
594 obj->len, (unsigned)minmax);
602 /* Additional properties */
603 if (!allow_additional || additional_schema != NULL) {
604 if (first_unvalidated != NULL) {
605 if (!allow_additional) {
606 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
607 "array has undefined item");
610 else if (additional_schema != NULL) {
611 elt = first_unvalidated;
613 if (!ucl_schema_validate (additional_schema, elt, false,
623 /* Required properties */
624 if (ret && need_unique) {
625 ret = ucl_schema_array_is_unique (obj, err);
633 * Returns whether this object is allowed for this type
636 ucl_schema_type_is_allowed (const ucl_object_t *type, const ucl_object_t *obj,
637 struct ucl_schema_error *err)
639 ucl_object_iter_t iter = NULL;
640 const ucl_object_t *elt;
641 const char *type_str;
645 /* Any type is allowed */
649 if (type->type == UCL_ARRAY) {
650 /* One of allowed types */
651 while ((elt = ucl_iterate_object (type, &iter, true)) != NULL) {
652 if (ucl_schema_type_is_allowed (elt, obj, err)) {
657 else if (type->type == UCL_STRING) {
658 type_str = ucl_object_tostring (type);
659 if (!ucl_string_to_type (type_str, &t)) {
660 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, type,
661 "Type attribute is invalid in schema");
664 if (obj->type != t) {
665 /* Some types are actually compatible */
666 if (obj->type == UCL_TIME && t == UCL_FLOAT) {
669 else if (obj->type == UCL_INT && t == UCL_FLOAT) {
673 ucl_schema_create_error (err, UCL_SCHEMA_TYPE_MISMATCH, obj,
674 "Invalid type of %s, expected %s",
675 ucl_object_type_to_string (obj->type),
676 ucl_object_type_to_string (t));
680 /* Types are equal */
689 * Check if object is equal to one of elements of enum
692 ucl_schema_validate_enum (const ucl_object_t *en, const ucl_object_t *obj,
693 struct ucl_schema_error *err)
695 ucl_object_iter_t iter = NULL;
696 const ucl_object_t *elt;
699 while ((elt = ucl_iterate_object (en, &iter, true)) != NULL) {
700 if (ucl_object_compare (elt, obj) == 0) {
707 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
708 "object is not one of enumerated patterns");
716 * Check a single ref component
718 static const ucl_object_t *
719 ucl_schema_resolve_ref_component (const ucl_object_t *cur,
720 const char *refc, int len,
721 struct ucl_schema_error *err)
723 const ucl_object_t *res = NULL;
727 if (cur->type == UCL_OBJECT) {
728 /* Find a key inside an object */
729 res = ucl_object_find_keyl (cur, refc, len);
731 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, cur,
732 "reference %s is invalid, missing path component", refc);
736 else if (cur->type == UCL_ARRAY) {
737 /* We must figure out a number inside array */
738 num = strtoul (refc, &err_str, 10);
739 if (err_str != NULL && *err_str != '/' && *err_str != '\0') {
740 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, cur,
741 "reference %s is invalid, invalid item number", refc);
746 while (res != NULL) {
753 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, cur,
754 "reference %s is invalid, item number %d does not exist",
760 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, res,
761 "reference %s is invalid, contains primitive object in the path",
769 * Find reference schema
771 static const ucl_object_t *
772 ucl_schema_resolve_ref (const ucl_object_t *root, const char *ref,
773 struct ucl_schema_error *err)
776 const ucl_object_t *res = NULL;
780 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, root,
781 "reference %s is invalid, not started with #", ref);
787 else if (ref[1] == '\0') {
791 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, root,
792 "reference %s is invalid, not started with #/", ref);
802 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, res,
803 "reference %s is invalid, empty path component", ref);
806 /* Now we have some url part, so we need to figure out where we are */
807 res = ucl_schema_resolve_ref_component (res, c, p - c, err);
817 res = ucl_schema_resolve_ref_component (res, c, p - c, err);
820 if (res == NULL || res->type != UCL_OBJECT) {
821 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, res,
822 "reference %s is invalid, cannot find specified object",
831 ucl_schema_validate_values (const ucl_object_t *schema, const ucl_object_t *obj,
832 struct ucl_schema_error *err)
834 const ucl_object_t *elt, *cur;
835 int64_t constraint, i;
837 elt = ucl_object_find_key (schema, "maxValues");
838 if (elt != NULL && elt->type == UCL_INT) {
839 constraint = ucl_object_toint (elt);
843 if (i > constraint) {
844 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
845 "object has more values than defined: %ld",
846 (long int)constraint);
853 elt = ucl_object_find_key (schema, "minValues");
854 if (elt != NULL && elt->type == UCL_INT) {
855 constraint = ucl_object_toint (elt);
859 if (i >= constraint) {
865 if (i < constraint) {
866 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
867 "object has less values than defined: %ld",
868 (long int)constraint);
877 ucl_schema_validate (const ucl_object_t *schema,
878 const ucl_object_t *obj, bool try_array,
879 struct ucl_schema_error *err,
880 const ucl_object_t *root)
882 const ucl_object_t *elt, *cur;
883 ucl_object_iter_t iter = NULL;
886 if (schema->type != UCL_OBJECT) {
887 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, schema,
888 "schema is %s instead of object", ucl_object_type_to_string (schema->type));
894 * Special case for multiple values
896 if (!ucl_schema_validate_values (schema, obj, err)) {
899 LL_FOREACH (obj, cur) {
900 if (!ucl_schema_validate (schema, cur, false, err, root)) {
907 elt = ucl_object_find_key (schema, "enum");
908 if (elt != NULL && elt->type == UCL_ARRAY) {
909 if (!ucl_schema_validate_enum (elt, obj, err)) {
914 elt = ucl_object_find_key (schema, "allOf");
915 if (elt != NULL && elt->type == UCL_ARRAY) {
917 while ((cur = ucl_iterate_object (elt, &iter, true)) != NULL) {
918 ret = ucl_schema_validate (cur, obj, true, err, root);
925 elt = ucl_object_find_key (schema, "anyOf");
926 if (elt != NULL && elt->type == UCL_ARRAY) {
928 while ((cur = ucl_iterate_object (elt, &iter, true)) != NULL) {
929 ret = ucl_schema_validate (cur, obj, true, err, root);
939 err->code = UCL_SCHEMA_OK;
943 elt = ucl_object_find_key (schema, "oneOf");
944 if (elt != NULL && elt->type == UCL_ARRAY) {
947 while ((cur = ucl_iterate_object (elt, &iter, true)) != NULL) {
949 ret = ucl_schema_validate (cur, obj, true, err, root);
951 else if (ucl_schema_validate (cur, obj, true, err, root)) {
961 elt = ucl_object_find_key (schema, "not");
962 if (elt != NULL && elt->type == UCL_OBJECT) {
963 if (ucl_schema_validate (elt, obj, true, err, root)) {
968 err->code = UCL_SCHEMA_OK;
972 elt = ucl_object_find_key (schema, "$ref");
974 cur = ucl_schema_resolve_ref (root, ucl_object_tostring (elt), err);
978 if (!ucl_schema_validate (cur, obj, try_array, err, root)) {
983 elt = ucl_object_find_key (schema, "type");
984 if (!ucl_schema_type_is_allowed (elt, obj, err)) {
990 return ucl_schema_validate_object (schema, obj, err, root);
993 return ucl_schema_validate_array (schema, obj, err, root);
997 return ucl_schema_validate_number (schema, obj, err);
1000 return ucl_schema_validate_string (schema, obj, err);
1010 ucl_object_validate (const ucl_object_t *schema,
1011 const ucl_object_t *obj, struct ucl_schema_error *err)
1013 return ucl_schema_validate (schema, obj, true, err, schema);