#include <vector>\r
#include <map>\r
#include "Properties.h"\r
-#include "Items.h"\r
#include "Definitions.h"\r
+#if defined (__TIZENRT__)\r
+#include <apps/netutils/cJSON.h>\r
+#else\r
#include "cJSON.h"\r
-#include "Helpers.h"\r
-#include "AllowedValues.h"\r
+#endif\r
#include <memory>\r
\r
#include "IncludeResolver.h"\r
/**\r
* Constructor of JsonSchema.\r
*/\r
- JsonSchema() : m_cjson(NULL), m_includeResolver(NULL) {}\r
+ JsonSchema() : m_additionalProperties(cJSON_True), m_cjson(NULL), m_includeResolver(NULL) {}\r
\r
/**\r
* Constructor of JsonSchema.\r
*\r
* @param includeResolver - Reference to IncludeResolver for reading external files\r
*/\r
- JsonSchema(const IncludeResolverPtr &includeResolver) : m_cjson(NULL),\r
+ JsonSchema(const IncludeResolverPtr &includeResolver) : m_additionalProperties(cJSON_True),\r
+ m_cjson(NULL),\r
m_includeResolver(includeResolver) {}\r
\r
/**\r
* @param cjson - pointer to cjson\r
* @param includeResolver - Reference to IncludeResolver for reading external files\r
*/\r
- JsonSchema(cJSON *cjson , const IncludeResolverPtr &includeResolver) : m_cjson(cjson),\r
+ JsonSchema(cJSON *cjson , const IncludeResolverPtr &includeResolver) : m_additionalProperties(\r
+ cJSON_True), m_cjson(cjson),\r
m_includeResolver(includeResolver) { readJson(); }\r
\r
\r
*\r
* @return pointer to Properties\r
*/\r
- inline PropertiesPtr getProperty(const std::string &name)\r
+ PropertiesPtr getProperty(const std::string &name)\r
{\r
if (m_properties.end() != m_properties.find(name))\r
{\r
*\r
* @return map of Properties name and pointer to Properties\r
*/\r
- inline std::map<std::string, PropertiesPtr > const &getProperties()\r
+ std::map<std::string, PropertiesPtr > const &getProperties()\r
{\r
return m_properties;\r
}\r
*\r
* @return map of Definitions name and pointer to Definitions\r
*/\r
- inline std::map<std::string, DefinitionsPtr > const &getDefinitions()\r
+ std::map<std::string, DefinitionsPtr > const &getDefinitions()\r
{\r
return m_definition;\r
}\r
return m_additionalProperties;\r
}\r
\r
- /**\r
- * This method is for setting Items to JsonSchema.\r
- *\r
- * @param item -pointer to Items\r
- */\r
- void setItem(const ItemsPtr &item)\r
- {\r
- m_items.push_back(item);\r
- }\r
-\r
- /**\r
- * This method is for getting Items from JsonSchema.\r
- *\r
- * @return vector of Items\r
- */\r
- std::vector<ItemsPtr> const &getItems()\r
+ private:\r
+ class JsonParameters\r
{\r
- return m_items;\r
- }\r
+ public:\r
+ std::map<std::string, PropertiesPtr > getProperties() const { return m_properties; }\r
+ void addProperties(const std::string &name, const PropertiesPtr &prop) { m_properties[name] = prop; }\r
+ void addProperties(const std::map<std::string, PropertiesPtr > &properties)\r
+ {\r
+ for (auto prop : properties)\r
+ m_properties[prop.first] = prop.second;\r
+ }\r
+ std::vector<std::string> getRequired() const { return m_required; }\r
+ void addRequired(const std::string &req) { m_required.push_back(req); }\r
+ void addRequired(const std::vector<std::string> &required)\r
+ {\r
+ for (auto req : required)\r
+ m_required.push_back(req);\r
+ }\r
+ std::string getType() const { return m_type; }\r
+ void setType(const std::string &type)\r
+ {\r
+ if (m_type.empty())\r
+ m_type = type;\r
+ }\r
+\r
+ private:\r
+ std::map<std::string, PropertiesPtr > m_properties;\r
+ std::vector<std::string> m_required;\r
+ std::string m_type;\r
+ };\r
\r
- private:\r
void readJson();\r
DefinitionsPtr readDef(cJSON *childDefinitions, const std::string &defName);\r
PropertiesPtr readProp(cJSON *childProperties, const std::string &attName );\r
- void readValues( cJSON *childProperties, PropertiesPtr property ,\r
+ void readDefaultValue(cJSON *defaultValue, PropertiesPtr &property, const std::string &attType);\r
+ void readAllowedValues(cJSON *allowedvalues, PropertiesPtr &property, std::string &attType);\r
+ void readValues( cJSON *childProperties, PropertiesPtr &property ,\r
const std::string &attType);\r
- void readString( cJSON *childProperties, PropertiesPtr property);\r
- void readArray( cJSON *childProperties, PropertiesPtr property);\r
- void readNumber( cJSON *childProperties, PropertiesPtr property);\r
- DefinitionsPtr readRef(std::string m_ref);\r
-\r
-\r
- void readJsonRef(cJSON *jsonReference);\r
- void readDefRef(cJSON *defReference, DefinitionsPtr definition);\r
- void readAllOf(cJSON *allofValues);\r
- void readDefAllOf(cJSON *allofValues, DefinitionsPtr definition);\r
- ItemsPtr readItems(cJSON *item);\r
- void readItemRef(cJSON *itemReference, ItemsPtr item);\r
- void readItemAllOf(cJSON *allofValues, ItemsPtr item);\r
+ void readString( cJSON *childProperties, PropertiesPtr &property);\r
+ void readInteger( cJSON *childProperties, PropertiesPtr &property);\r
+ void readDouble( cJSON *childProperties, PropertiesPtr &property);\r
+ void readArray( cJSON *childProperties, PropertiesPtr &property);\r
+ void readItems(cJSON *item, PropertiesPtr &property);\r
+ void readObject(cJSON *childProperties, PropertiesPtr &property);\r
+\r
+ void readFile(std::string &fileName , JsonParameters ¶m);\r
+ void readFile(std::string &fileName , std::string &defName , JsonParameters ¶m);\r
+ void readRef(std::string ref , JsonParameters ¶m);\r
+ void readJsonRef(cJSON *jsonReference , JsonParameters ¶m);\r
+ void readAllOf(cJSON *allofValues , JsonParameters &allParams);\r
\r
private:\r
std::map<std::string, PropertiesPtr > m_properties;\r
std::string m_type;\r
cJSON *m_cjson;\r
std::vector<std::string> m_required;\r
- std::vector<ItemsPtr > m_items;\r
+ PropertiesPtr m_property;\r
IncludeResolverPtr m_includeResolver;\r
+\r
};\r
\r
/** JsonSchemaPtr - shared Ptr to JsonSchema.*/\r