2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <folly/ExceptionWrapper.h>
20 #include <folly/dynamic.h>
21 #include <folly/Range.h>
24 * Validation according to the draft v4 standard: http://json-schema.org/
26 * If your schema is invalid, then it won't validate anything. For example, if
27 * you set "type": "invalid_type" in your schema, then it won't check for any
28 * type, as if you had left that property out. If you want to make sure your
29 * schema is valid, you can optionally validate it first according to the
33 * - We don't support fetching schemas via HTTP.
34 * - We don't support remote $refs.
35 * - We don't support $ref via id (only by path).
36 * - We don't support UTF-8 for string lengths, i.e. we will count bytes for
37 * schemas that use minLength/maxLength.
41 namespace jsonschema {
44 * Interface for a schema validator.
47 virtual ~Validator() = 0;
50 * Check whether the given value passes the schema. Throws if it fails.
52 virtual void validate(const dynamic& value) const = 0;
55 * Check whether the given value passes the schema. Returns an
56 * exception_wrapper indicating success or what the failure was.
58 virtual exception_wrapper try_validate(const dynamic& value) const
63 * Make a validator that can be used to check various json. Thread-safe.
65 std::unique_ptr<Validator> makeValidator(const dynamic& schema);
68 * Makes a validator for schemas. You should probably check your schema with
69 * this before you use makeValidator().
71 std::shared_ptr<Validator> makeSchemaValidator();