1 /******************************************************************
\r
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
19 ******************************************************************/
\r
21 #ifndef JSON_SCHEMA_H_
\r
22 #define JSON_SCHEMA_H_
\r
27 #include "Properties.h"
\r
29 #include "Definitions.h"
\r
31 #include "Helpers.h"
\r
32 #include "AllowedValues.h"
\r
34 #include "IncludeResolver.h"
\r
41 JsonSchema() : m_cjson(NULL), m_includeResolver(NULL) {}
\r
42 JsonSchema(const IncludeResolverPtr &includeResolver) : m_cjson(NULL),
\r
43 m_includeResolver(includeResolver) {}
\r
44 JsonSchema(cJSON *cjson , const IncludeResolverPtr &includeResolver) : m_cjson(cjson),
\r
45 m_includeResolver(includeResolver) { readJson(); }
\r
47 void setcJson(cJSON *cjson) {m_cjson = cjson; readJson(); }
\r
50 return m_properties.size();
\r
52 inline bool getProperty(const std::string &name, Properties *value)
\r
54 if (m_properties.end() != m_properties.find(name))
\r
56 value = m_properties[name];
\r
61 inline std::map<std::string, Properties *> getProperties()
\r
63 return m_properties;
\r
65 inline std::map<std::string, Definitions *> getDefinitions()
\r
67 return m_definition;
\r
69 void addProperty(const std::string &name, Properties *property)
\r
71 if (m_properties.end() == m_properties.find(name))
\r
73 m_properties[name] = property;
\r
76 void setRequiredValue(const std::string &reqValue)
\r
78 if (m_required.end() == std::find(m_required.begin(), m_required.end(), reqValue))
\r
80 m_required.push_back(reqValue);
\r
83 std::vector<std::string> getRequiredValues()
\r
87 void addDefinition(const std::string &defName, Definitions *definition)
\r
89 if (m_definition.end() == m_definition.find(defName))
\r
91 m_definition[defName] = definition;
\r
94 Definitions *getDefinition(const std::string &defName)
\r
96 if (m_definition.end() != m_definition.find(defName))
\r
98 return m_definition[defName];
\r
102 std::string getType()
\r
106 std::string getId()
\r
110 std::string getSchema()
\r
114 std::string getDescription()
\r
116 return m_description;
\r
118 std::string getTitle()
\r
123 bool getAdditionalProperties()
\r
125 return m_additionalProperties;
\r
127 void setItem(Items *item)
\r
129 m_items.push_back(item);
\r
131 std::vector<Items *> getItems()
\r
137 Definitions *readDef(cJSON *childDefinitions, const std::string &defName);
\r
138 Properties *readProp(cJSON *childProperties, const std::string &attName );
\r
139 void readValues( cJSON *childProperties, Properties *property , const std::string &attType);
\r
140 void readString( cJSON *childProperties, Properties *property);
\r
141 void readArray( cJSON *childProperties, Properties *property);
\r
142 void readNumber( cJSON *childProperties, Properties *property);
\r
143 Definitions *readRef(std::string m_ref);
\r
146 void readJsonRef(cJSON *jsonReference);
\r
147 void readDefRef(cJSON *defReference, Definitions *definition);
\r
148 void readAllOf(cJSON *allofValues);
\r
149 void readDefAllOf(cJSON *allofValues, Definitions *definition);
\r
150 Items *readItems(cJSON *item);
\r
151 void readItemRef(cJSON *itemReference, Items *item);
\r
152 void readItemAllOf(cJSON *allofValues, Items *item);
\r
155 std::map<std::string, Properties *> m_properties;
\r
156 std::map<std::string, Definitions *> m_definition;
\r
158 std::string m_schema;
\r
159 std::string m_title;
\r
160 std::string m_description;
\r
161 bool m_additionalProperties;
\r
162 std::string m_type;
\r
164 std::vector<std::string> m_required;
\r
165 std::vector<Items *> m_items;
\r
166 IncludeResolverPtr m_includeResolver;
\r
168 typedef std::shared_ptr<JsonSchema> JsonSchemaPtr;
\r