File: check_schema.cpp

package info (click to toggle)
valijson 1.0.6%2Brepack-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,776 kB
  • sloc: cpp: 19,993; sh: 131; makefile: 24
file content (48 lines) | stat: -rw-r--r-- 1,177 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * @file
 *
 * @brief Loads a schema then exits. Exit code will be 0 if the schema is
 *        valid, and 1 otherwise. This example uses jsoncpp to parse the
 *        schema document.
 */

#include <iostream>

#include <valijson/adapters/jsoncpp_adapter.hpp>
#include <valijson/utils/jsoncpp_utils.hpp>
#include <valijson/schema.hpp>
#include <valijson/schema_parser.hpp>

using std::cerr;
using std::endl;

using valijson::Schema;
using valijson::SchemaParser;
using valijson::adapters::JsonCppAdapter;

int main(int argc, char *argv[])
{
    if (argc != 2) {
        cerr << "Usage: " << argv[0] << " <schema document>" << endl;
        return 1;
    }

    // Load the document containing the schema
    Json::Value schemaDocument;
    if (!valijson::utils::loadDocument(argv[1], schemaDocument)) {
        cerr << "Failed to load schema document." << endl;
        return 1;
    }

    Schema schema;
    SchemaParser parser;
    JsonCppAdapter adapter(schemaDocument);
    try {
        parser.populateSchema(adapter, schema);
    } catch (std::exception &e) {
        cerr << "Failed to parse schema: " << e.what() << endl;
        return 1;
    }

    return 0;
}