blob: c5ec695ff2d9e971a088ff5e1115a34f78c2e63e [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/fitx/result.h>
#include <memory>
#include <sstream>
#include <string_view>
#include <rapidjson/document.h>
#include <rapidjson/schema.h>
namespace json_parser {
// Error for `InitSchema` function.
struct InitSchemaError {
// Offset in schema json where error occurred.
size_t offset;
// Call `rapidjson::GetParseError_En` on error code to get string representation.
rapidjson::ParseErrorCode code;
std::string ToString() const;
// Build a SchemaDocument from a json encoded string.
fitx::result<InitSchemaError, rapidjson::SchemaDocument> InitSchema(std::string_view json);
// Validate that the given json value match the given schema.
// Returns validation error on error.
fitx::result<std::string> ValidateSchema(const rapidjson::Value& value,
const rapidjson::SchemaDocument& schema,
std::string_view value_name = "");
} // namespace json_parser