******************************************************************/\r
\r
#include "RamlParser.h"\r
+#include "Helpers.h"\r
#include <iostream>\r
#include <string>\r
#include <memory>\r
\r
for ( auto pro : body->getSchema()->getProperties()->getProperties() )\r
{\r
+ std::cout << "-----------------------------" << std::endl;\r
std::cout << "Name : " << pro.second->getName() << std::endl;\r
- std::cout << "default : " << pro.second->getValue() << std::endl;\r
- std::cout << "update_frequency : " << pro.second->getUpdateFrequencyTime() << std::endl;\r
- int min = 0, max = 0, multipleOf = 0;\r
- pro.second->getRange(min, max, multipleOf);\r
-\r
- std::cout << "range_min : " << min << std::endl;\r
- std::cout << "range_max : " << max << std::endl;\r
- std::cout << "allowed values : " << std::endl;\r
- for (auto v : pro.second->getAllowedValues())\r
- std::cout << v << " ";\r
- std::cout << std::endl;\r
+ std::cout << "-----------------------------" << std::endl;\r
+ try\r
+ {\r
+ switch (pro.second->getVariantType())\r
+ {\r
+ case VariantType::INT : // Integer\r
+ std::cout << "Defaut: " << pro.second->getValueInt() << std::endl;\r
+ for (auto tt : pro.second->getAllowedValuesInt())\r
+ {\r
+ std::cout << "enum value : " << tt << std::endl;\r
+ }\r
+ {\r
+ int min = 0, max = 0, mul = 0;\r
+ pro.second->getRange(min, max, mul);\r
+ std::cout << "Minimum: " << min << std::endl;\r
+ std::cout << "Maximum: " << max << std::endl;\r
+ }\r
+ break;\r
+\r
+ case VariantType::DOUBLE : // Double\r
+ std::cout << "Defaut: " << pro.second->getValueDouble() << std::endl;\r
+ for (auto tt : pro.second->getAllowedValuesDouble())\r
+ {\r
+ std::cout << "enum value : " << tt << std::endl;\r
+ }\r
+ {\r
+ double min = 0, max = 0;\r
+ int mul = 0;\r
+ pro.second->getRangeDouble(min, max, mul);\r
+ std::cout << "MinimumDouble: " << min << std::endl;\r
+ std::cout << "MaximumDouble: " << max << std::endl;\r
+ }\r
+ break;\r
+\r
+ case VariantType::BOOL : // Boolean\r
+ std::cout << "Defaut: " << std::boolalpha << pro.second->getValueBool() << std::noboolalpha <<\r
+ std::endl;\r
+ for (auto tt : pro.second->getAllowedValuesBool())\r
+ {\r
+ std::cout << "enum value : " << tt << std::endl;\r
+ }\r
+ break;\r
+\r
+ case VariantType::STRING : // String\r
+ std::cout << "Defaut: " << pro.second->getValueString() << std::endl;\r
+ for (auto tt : pro.second->getAllowedValuesString())\r
+ {\r
+ std::cout << "enum value : " << tt << std::endl;\r
+ }\r
+ {\r
+ int min = 0, max = 0, mul = 0;\r
+ pro.second->getRange(min, max, mul);\r
+ std::cout << "MinimumLength: " << min << std::endl;\r
+ std::cout << "MaximumLength: " << max << std::endl;\r
+ }\r
+ break;\r
+ default:\r
+ break;\r
+\r
+ }\r
+ }\r
+ catch (const boost::bad_lexical_cast &e)\r
+ {\r
+ std::cout << e.what() << std::endl;\r
+ }\r
+ catch ( ... )\r
+ {\r
+ std::cout << "Unknown exception caught!" << std::endl;\r
+ }\r
\r
}\r
+ std::cout << "-----------------------------" << std::endl;\r
std::cout << "Body : example : " << body->getExample() << std::endl;\r
\r
#ifdef PRINT_REQUEST_RESPONSE_BODY_PARAMS\r
std::cout << "-------------------------------" << std::endl;\r
std::cout << "Type: " << prop->getType() << std::endl;\r
std::cout << "Description: " << prop->getDescription() << std::endl;\r
- int type = prop->getValueType();\r
- if (type)\r
+ try\r
{\r
- std::cout << "Defaut: " << prop->getValueString() << std::endl;\r
- for (auto tt : prop->getAllowedValuesString())\r
+ switch (prop->getVariantType())\r
{\r
- std::cout << "enum value : " << tt << std::endl;\r
+ case VariantType::INT : // Integer\r
+ std::cout << "Defaut: " << prop->getValueInt() << std::endl;\r
+ for (auto tt : prop->getAllowedValuesInt())\r
+ {\r
+ std::cout << "enum value : " << tt << std::endl;\r
+ }\r
+ {\r
+ int min = 0, max = 0, mul = 0;\r
+ prop->getRange(min, max, mul);\r
+ std::cout << "Minimum: " << min << std::endl;\r
+ std::cout << "Maximum: " << max << std::endl;\r
+ }\r
+ break;\r
+\r
+ case VariantType::DOUBLE : // Double\r
+ std::cout << "Defaut: " << prop->getValueDouble() << std::endl;\r
+ for (auto tt : prop->getAllowedValuesDouble())\r
+ {\r
+ std::cout << "enum value : " << tt << std::endl;\r
+ }\r
+ {\r
+ double min = 0, max = 0;\r
+ int mul = 0;\r
+ prop->getRangeDouble(min, max, mul);\r
+ std::cout << "MinimumDouble: " << min << std::endl;\r
+ std::cout << "MaximumDouble: " << max << std::endl;\r
+ }\r
+ break;\r
+\r
+ case VariantType::BOOL : // Boolean\r
+ std::cout << "Defaut: " << std::boolalpha << prop->getValueBool() << std::noboolalpha << std::endl;\r
+ for (auto tt : prop->getAllowedValuesBool())\r
+ {\r
+ std::cout << std::boolalpha << "enum value : " << tt << std::noboolalpha << std::endl;\r
+ }\r
+ break;\r
+\r
+ case VariantType::STRING : // String\r
+ std::cout << "Defaut: " << prop->getValueString() << std::endl;\r
+ for (auto tt : prop->getAllowedValuesString())\r
+ {\r
+ std::cout << "enum value : " << tt << std::endl;\r
+ }\r
+ {\r
+ int min = 0, max = 0, mul = 0;\r
+ prop->getRange(min, max, mul);\r
+ std::cout << "MinimumLength: " << min << std::endl;\r
+ std::cout << "MaximumLength: " << max << std::endl;\r
+ }\r
+ break;\r
+ default:\r
+ break;\r
+\r
}\r
}\r
- else\r
+ catch (const boost::bad_lexical_cast &e)\r
{\r
- std::cout << "Defaut: " << prop->getValueInt() << std::endl;\r
- for (auto tt : prop->getAllowedValuesString())\r
- {\r
- std::cout << "enum value : " << tt << std::endl;\r
- }\r
+ std::cout << e.what() << std::endl;\r
}\r
+ catch ( ... )\r
+ {\r
+ std::cout << "Unknown exception caught!" << std::endl;\r
+ }\r
+\r
if (prop->getType() == "array")\r
{\r
for (auto it : prop->getItems())\r
{\r
std::cout << "enum value : " << tt << std::endl;\r
}\r
+ for (auto tt : it->getProperties())\r
+ {\r
+ printProperties(tt.second);\r
+ }\r
+ std::cout << "Item Required Values : " << std::endl;\r
+ for (auto tt : it->getRequiredValues())\r
+ {\r
+ std::cout << tt << std::endl;\r
+ }\r
}\r
}\r
- int min = 0, max = 0, mul = 0;\r
- prop->getRange(min, max, mul);\r
- std::cout << "Minimum: " << min << std::endl;\r
- std::cout << "Maximum: " << max << std::endl;\r
- std::cout << "MultipleOf: " << mul << std::endl;\r
#endif\r
\r
}\r
{\r
PropertiesPtr property = std::make_shared<Properties>(attName);\r
\r
- cJSON *propertyUpdateFrequency = cJSON_GetObjectItem(childProperties, "update_frequency");\r
- if (propertyUpdateFrequency)\r
- {\r
- property->setUpdateFrequencyTime(propertyUpdateFrequency->valueint);\r
- }\r
cJSON *propertyDescription = cJSON_GetObjectItem(childProperties, "description");\r
if (propertyDescription)\r
{\r
}\r
else if (attType == "integer")\r
{\r
- readNumber(childProperties, property);\r
+ readInteger(childProperties, property);\r
}\r
else if (attType == "array")\r
{\r
}\r
else if (attType == "number")\r
{\r
- readNumber(childProperties, property);\r
+ readDouble(childProperties, property);\r
}\r
}\r
\r
}\r
}\r
\r
- void JsonSchema::readNumber(cJSON *childProperties, PropertiesPtr property)\r
+ void JsonSchema::readInteger(cJSON *childProperties, PropertiesPtr property)\r
{\r
cJSON *Max = cJSON_GetObjectItem(childProperties, "maximum");\r
if (Max)\r
}\r
\r
}\r
+\r
+ void JsonSchema::readDouble(cJSON *childProperties, PropertiesPtr property)\r
+ {\r
+ cJSON *Max = cJSON_GetObjectItem(childProperties, "maximum");\r
+ if (Max)\r
+ {\r
+ cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");\r
+ if (exclusiveMax)\r
+ {\r
+ if (exclusiveMax->type == cJSON_True)\r
+ property->setMaxDouble( --(Max->valuedouble));\r
+ else\r
+ property->setMaxDouble(Max->valuedouble);\r
+ }\r
+ else\r
+ property->setMaxDouble(Max->valuedouble);\r
+ }\r
+ cJSON *Min = cJSON_GetObjectItem(childProperties, "minimum");\r
+ if (Min)\r
+ {\r
+ cJSON *exclusiveMin = cJSON_GetObjectItem(childProperties, "exclusiveMinimum");\r
+ if (exclusiveMin)\r
+ {\r
+ if (exclusiveMin->type == cJSON_True)\r
+ property->setMinDouble( ++(Min->valuedouble));\r
+ else\r
+ property->setMinDouble(Min->valuedouble);\r
+ }\r
+ else\r
+ property->setMinDouble(Min->valuedouble);\r
+ }\r
+ cJSON *multipleOf = cJSON_GetObjectItem(childProperties, "multipleOf");\r
+ if (multipleOf)\r
+ {\r
+ property->setMultipleOf(multipleOf->valueint);\r
+ }\r
+\r
+ }\r
+\r
DefinitionsPtr JsonSchema::readRef(std::string m_ref)\r
{\r
std::string delimiter1 = "#";\r
/**\r
* Constructor of Properties.\r
*/\r
- Properties(): m_min(INT_MAX), m_max(INT_MAX), m_multipleOf(INT_MAX), m_updateInterval(0),\r
- m_unique(false), m_additionalItems(false) {}\r
+ Properties(): m_min(INT_MAX), m_max(INT_MAX), m_doubleMin(INT_MAX), m_doubleMax(INT_MAX),\r
+ m_multipleOf(INT_MAX), m_unique(false), m_additionalItems(false) {}\r
\r
/**\r
* Constructor of Properties.\r
* @param name - Properties name as string.\r
*/\r
Properties(const std::string &name) : m_name(name), m_min(INT_MAX), m_max(INT_MAX),\r
- m_multipleOf(INT_MAX), m_updateInterval(0), m_unique(false), m_additionalItems(false) {}\r
+ m_doubleMin(INT_MAX), m_doubleMax(INT_MAX), m_multipleOf(INT_MAX),\r
+ m_unique(false), m_additionalItems(false) {}\r
\r
/**\r
* This method is for getting Name from Properties.\r
}\r
\r
/**\r
+ * This method is for getting Range from Properties.\r
+ *\r
+ * @param min - reference to hold Minimum value of Properties.\r
+ * @param max - reference to hold Maximum value of Properties.\r
+ * @param multipleOf - reference to hold multipleOf value of Properties.\r
+ */\r
+ inline void getRangeDouble(double &min, double &max, int &multipleOf) const\r
+ {\r
+ min = m_doubleMin;\r
+ max = m_doubleMax;\r
+ multipleOf = m_multipleOf;\r
+ }\r
+ /**\r
* This method is for setting Minimum to Properties\r
*\r
* @param min - Minimum value of Properties.\r
}\r
\r
/**\r
+ * This method is for setting Minimum to Properties\r
+ *\r
+ * @param min - Minimum value of Properties.\r
+ */\r
+ inline void setMinDouble(const double &min)\r
+ {\r
+ m_doubleMin = min;\r
+ }\r
+\r
+ /**\r
+ * This method is for setting Maximum to Properties\r
+ *\r
+ * @param max - Maximum value of Properties.\r
+ */\r
+ inline void setMaxDouble(const double &max)\r
+ {\r
+ m_doubleMax = max;\r
+ }\r
+ /**\r
* This method is for setting multipleOf to Properties\r
*\r
* @param multipleOf - multipleOf value of Properties.\r
}\r
\r
/**\r
- * This method is for getting UpdateFrequency from Properties.\r
- *\r
- * @return UpdateFrequency as int\r
- */\r
- inline int getUpdateFrequencyTime()\r
- {\r
- return m_updateInterval;\r
- }\r
-\r
- /**\r
- * This method is for setting UpdateFrequency to Properties\r
- *\r
- * @param interval - UpdateFrequency as int.\r
- */\r
- inline void setUpdateFrequencyTime(int interval)\r
- {\r
- m_updateInterval = interval;\r
- }\r
-\r
- /**\r
* This method is for setting Type to Properties\r
*\r
* @param type - Type as string.\r
ValueVariant m_value;\r
int m_min;\r
int m_max;\r
+ double m_doubleMin;\r
+ double m_doubleMax;\r
int m_multipleOf;\r
AllowedValues m_allowedValues;\r
- int m_updateInterval;\r
std::string m_type;\r
std::string m_pattern;\r
std::string m_format;\r