iFun Engine API  1.0.0-b6053
Great Technology for Great Games
json_schema.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
9 #ifndef INCLUDE_FUNAPI_COMMON_JSON_SCHEMA_H_
10 #define INCLUDE_FUNAPI_COMMON_JSON_SCHEMA_H_
11 
12 #include <funapi/common/json.h>
13 #include <funapi/types.h>
14 
15 #include <vector>
16 
17 
18 namespace fun {
19 
20 class FUNAPI_DLL_VISIBILITY JsonSchema {
21  public:
22  enum Type {
23  kInvalid = 0,
24  kBoolean,
25  kInteger,
26  kDouble,
27  kString,
28  kObject,
29  kArray
30  };
31 
32  static const JsonSchema kNull;
33 
34  // for object attribute for all types
35  JsonSchema(const string &name, const Type &type, const bool &required);
36  // for object attribute for object or array
37  JsonSchema(const string &name, const Type &type, const bool &required,
38  const JsonSchema &e1, const JsonSchema &e2 = kNull,
39  const JsonSchema &e3 = kNull, const JsonSchema &e4 = kNull,
40  const JsonSchema &e5 = kNull, const JsonSchema &e6 = kNull,
41  const JsonSchema &e7 = kNull, const JsonSchema &e8 = kNull,
42  const JsonSchema &e9 = kNull, const JsonSchema &e10 = kNull,
43  const JsonSchema &e11 = kNull, const JsonSchema &e12 = kNull);
44  // for array element for all types
45  explicit JsonSchema(const Type &type);
46  // for root object or array element for object or array
47  JsonSchema(const Type &type, const JsonSchema &e1,
48  const JsonSchema &e2 = kNull, const JsonSchema &e3 = kNull,
49  const JsonSchema &e4 = kNull, const JsonSchema &e5 = kNull,
50  const JsonSchema &e6 = kNull, const JsonSchema &e7 = kNull,
51  const JsonSchema &e8 = kNull, const JsonSchema &e9 = kNull,
52  const JsonSchema &e10 = kNull, const JsonSchema &e11 = kNull,
53  const JsonSchema &e12 = kNull);
54 
55  bool ValidateJsonMessage(const Json &json_object) const;
56 
57  bool HasName() const;
58  const string &name() const;
59  Type type() const;
60  bool required() const;
61  const std::vector<JsonSchema> &items() const;
62  void insert(const JsonSchema &item);
63  void insert(const std::vector<JsonSchema> &items);
64 
65  private:
66  static bool ValidateJsonMessage(const Json &json,
67  const JsonSchema &json_schema);
68 
69  string name_;
70  Type type_;
71  bool required_;
72  std::vector<JsonSchema> items_;
73 };
74 
75 
76 FUNAPI_DLL_VISIBILITY bool operator !=(const JsonSchema &lhs, const JsonSchema &rhs);
77 FUNAPI_DLL_VISIBILITY bool operator ==(const JsonSchema &lhs, const JsonSchema &rhs);
78 
79 } // namespace fun
80 
81 #endif // INCLUDE_FUNAPI_COMMON_JSON_SCHEMA_H_
Definition: json_schema.h:20
Definition: json.h:18
Definition: json.h:27