Design Changes to JsonSchema Parser
authorAbitha Shankar <abitha.s@samsung.com>
Wed, 6 Jan 2016 11:37:14 +0000 (17:07 +0530)
committerUze Choi <uzchoi@samsung.com>
Thu, 7 Jan 2016 07:09:34 +0000 (07:09 +0000)
1. Changes to read Json Schema to read Simple Arrays and Array of Array of Properties required for Collection
2. Changes to read as Simple Attribute as vector of homogeneous values into Simulator Factory
3. Changes to Read the Properties from schema in a Unified Manner using ValueVariant to hold the values
4. Added Support to read Multiple ValueProperties for each property
5. Added support for Pattern, Format and Array ValueProperties.
6.Changes to read the referenced file in Json Schema from a single Implementation
7. Added Default values for attributes when not obtained from Schema

Change-Id: Iccc3a1cb0881d19b511cc743975299e85fd27c2d
Signed-off-by: Abitha Shankar <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4755
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Radha Bhavani <radha.p@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
14 files changed:
service/simulator/ramlparser/SConscript
service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h [deleted file]
service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.h
service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h [deleted file]
service/simulator/ramlparser/raml/jsonSchemaParser/Items.h [deleted file]
service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.cpp
service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.h
service/simulator/ramlparser/raml/jsonSchemaParser/Properties.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/jsonSchemaParser/Properties.h
service/simulator/src/common/request_model_builder.cpp
service/simulator/src/common/request_model_builder.h [changed mode: 0644->0755]
service/simulator/src/server/simulator_resource_factory.cpp [changed mode: 0644->0755]
service/simulator/src/server/simulator_resource_factory.h

index adb8803..7e1504c 100755 (executable)
@@ -32,6 +32,8 @@ raml_env.AppendUnique(CPPPATH = ['raml/model','raml/jsonSchemaParser','raml', '.
 raml_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])\r
 raml_env.AppendUnique(CPPDEFINES = ['LINUX'])\r
 \r
+raml_env.Append( RPATH = env.Literal('\\$$ORIGIN'))\r
+\r
 raml_env.AppendUnique(CPPPATH = ['../../../extlibs/cjson/'])\r
 raml_env.PrependUnique(LIBS = ['octbstack', 'YamlParser'])\r
 raml_env.AppendUnique(LIBS = ['pthread'])\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h b/service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h
deleted file mode 100755 (executable)
index b0946ae..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/******************************************************************\r
- *\r
- * Copyright 2015 Samsung Electronics All Rights Reserved.\r
- *\r
- *\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- ******************************************************************/\r
-\r
-/**\r
- * @file   AllowedValues.h\r
- *\r
- * @brief   This file provides data Model for Json Schema AllowedValues.\r
- */\r
-\r
-#ifndef ALLOWED_VALUES_H_\r
-#define ALLOWED_VALUES_H_\r
-\r
-#include <string>\r
-#include <vector>\r
-#include <map>\r
-#include <boost/variant.hpp>\r
-#include <boost/lexical_cast.hpp>\r
-#include "Helpers.h"\r
-\r
-namespace RAML\r
-{\r
-    /**\r
-     * @class   AllowedValues\r
-     * @brief   This class provides data Model for Json Schema AllowedValues.\r
-     */\r
-    class AllowedValues\r
-    {\r
-        public:\r
-            /**\r
-                 * This method is for setting AllowedValues\r
-                 *\r
-                 * @param value - Allowed Value to set.\r
-                 */\r
-            template <typename T>\r
-            void addValue(const T &value)\r
-            {\r
-                ValueVariant temp = value;\r
-                m_values.push_back(temp);\r
-            }\r
-\r
-            /**\r
-                 * This method is for setting AllowedValues\r
-                 *\r
-                 * @param values - list of Allowed Values to set.\r
-                 */\r
-            template <typename T>\r
-            void addValues(const std::vector<T> &values)\r
-            {\r
-                for (auto value : values)\r
-                {\r
-                    ValueVariant vValue = value;\r
-                    m_values.push_back(vValue);\r
-                }\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting AllowedValues\r
-                 *\r
-                 * @param index - Allowed Values at index to be fetched\r
-                 */\r
-            inline ValueVariant &at(int index)\r
-            {\r
-                return m_values.at(index);\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting size of AllowedValues\r
-                 *\r
-                 * @return size of Allowed Values list\r
-                 */\r
-            inline int size() const\r
-            {\r
-                return m_values.size();\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting AllowedValues.\r
-                 *\r
-                 * @return list of AllowedValues\r
-                 */\r
-            inline std::vector<ValueVariant> getValues()\r
-            {\r
-                return m_values;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting AllowedValues as integer.\r
-                 *\r
-                 * @return list of AllowedValues as integer.\r
-                 */\r
-            inline std::vector<int> getValuesInt()\r
-            {\r
-                std::vector<int> values;\r
-                for (auto value : m_values)\r
-                {\r
-                    values.push_back(boost::lexical_cast<int> (value));\r
-                }\r
-                return values;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting AllowedValues as string.\r
-                 *\r
-                 * @return list of AllowedValues as string.\r
-                 */\r
-            inline std::vector<std::string> getValuesString()\r
-            {\r
-                std::vector<std::string> values;\r
-                for (auto value : m_values)\r
-                {\r
-                    values.push_back(boost::lexical_cast<std::string> (value));\r
-                }\r
-                return values;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting AllowedValues as Double.\r
-                 *\r
-                 * @return list of AllowedValues as Double.\r
-                 */\r
-            inline std::vector<double> getValuesDouble()\r
-            {\r
-                std::vector<double> values;\r
-                for (auto value : m_values)\r
-                {\r
-                    values.push_back(boost::lexical_cast<double> (value));\r
-                }\r
-                return values;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting AllowedValues as Bool.\r
-                 *\r
-                 * @return list of AllowedValues as Bool.\r
-                 */\r
-            inline std::vector<bool> getValuesBool()\r
-            {\r
-                std::vector<bool> values;\r
-                for (auto value : m_values)\r
-                {\r
-                    values.push_back(boost::lexical_cast<bool> (value));\r
-                }\r
-                return values;\r
-            }\r
-\r
-        private:\r
-            std::vector<ValueVariant> m_values;\r
-    };\r
-\r
-}\r
-#endif\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.cpp b/service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.cpp
new file mode 100755 (executable)
index 0000000..f662469
--- /dev/null
@@ -0,0 +1,91 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+/**\r
+ * @file   Definitions.cpp\r
+ *\r
+ * @brief   This file provides data Model for Json Schema Definitions.\r
+ */\r
+\r
+#include "Definitions.h"\r
+\r
+namespace RAML\r
+{\r
+    std::string Definitions::getName() const\r
+    {\r
+        return m_defName;\r
+    }\r
+\r
+    void Definitions::setName(const std::string &name)\r
+    {\r
+        m_defName = name;\r
+    }\r
+\r
+    std::string Definitions::getType() const\r
+    {\r
+        return m_type;\r
+    }\r
+\r
+    void Definitions::setType(const std::string &type)\r
+    {\r
+        m_type = type;\r
+    }\r
+\r
+    std::vector<std::string> const &Definitions::getRequiredValues() const\r
+    {\r
+        return m_required;\r
+    }\r
+\r
+    void Definitions::setRequiredValue(const std::string &reqValue)\r
+    {\r
+        auto it = m_required.begin();\r
+        for (; it != m_required.end(); ++it)\r
+        {\r
+            if (*it == reqValue)\r
+                break;\r
+        }\r
+        if (m_required.end() == it)\r
+        {\r
+            m_required.push_back(reqValue);\r
+        }\r
+    }\r
+\r
+    PropertiesPtr Definitions::getproperty(const std::string &propName )\r
+    {\r
+        if (m_properties.end() != m_properties.find(propName))\r
+        {\r
+            return m_properties[propName];\r
+        }\r
+        return nullptr;\r
+    }\r
+\r
+    std::map<std::string, PropertiesPtr> const  &Definitions::getProperties()\r
+    {\r
+        return m_properties;\r
+    }\r
+\r
+    void Definitions::addProperty(const std::string &propName, const PropertiesPtr &property)\r
+    {\r
+        if (m_properties.end() == m_properties.find(propName))\r
+        {\r
+            m_properties[propName] =  property;\r
+        }\r
+    }\r
+}\r
index d2eec8f..b6afe8a 100755 (executable)
@@ -47,6 +47,30 @@ namespace RAML
                   * Constructor of Definitions.\r
                   */\r
             Definitions() = default;\r
+            /**\r
+                  * Copy Constructor of Definitions.\r
+                  *\r
+                  * @param Definitions\r
+                  */\r
+            Definitions(const Definitions &) = default;\r
+            /**\r
+                  * Assignment operator for Definitions.\r
+                  *\r
+                  * @param Definitions\r
+                  */\r
+            Definitions &operator=(const Definitions &) = default;\r
+            /**\r
+                  * Copy Constructor of Definitions.\r
+                  *\r
+                  * @param Definitions\r
+                  */\r
+            Definitions(Definitions &&) = default;\r
+            /**\r
+                  * Assignment operator for Definitions.\r
+                  *\r
+                  * @param Definitions\r
+                  */\r
+            Definitions &operator=(Definitions &&) = default;\r
 \r
             /**\r
                   * Constructor of Definitions.\r
@@ -60,69 +84,40 @@ namespace RAML
                  *\r
                  * @return Definitions name as string\r
                  */\r
-            inline std::string getName(void) const\r
-            {\r
-                return m_defName;\r
-            }\r
-\r
+            std::string getName() const;\r
             /**\r
                  * This method is for setting name to Definitions\r
                  *\r
                  * @param name - Definitions name as string.\r
                  */\r
-            inline void setName(const std::string &name)\r
-            {\r
-                m_defName = name;\r
-            }\r
+            void setName(const std::string &name);\r
 \r
             /**\r
                  * This method is for getting Type from Definitions.\r
                  *\r
                  * @return Definitions Type as string\r
                  */\r
-            inline std::string getType(void) const\r
-            {\r
-                return m_type;\r
-            }\r
+            std::string getType() const;\r
 \r
             /**\r
                  * This method is for setting Type to Definitions\r
                  *\r
                  * @param type - Definitions Type as string.\r
                  */\r
-            inline void setType(const std::string &type)\r
-            {\r
-                m_type = type;\r
-            }\r
-\r
+            void setType(const std::string &type);\r
             /**\r
                  * This method is for getting RequiredValue from Definitions.\r
                  *\r
                  * @return list of RequiredValue as string\r
                  */\r
-            std::vector<std::string> const &getRequiredValues() const\r
-            {\r
-                return m_required;\r
-            }\r
+            std::vector<std::string> const &getRequiredValues() const;\r
 \r
             /**\r
                  * This method is for setting RequiredValue to Definitions\r
                  *\r
                  * @param reqValue - RequiredValue as string.\r
                  */\r
-            void setRequiredValue(const std::string &reqValue)\r
-            {\r
-                auto it = m_required.begin();\r
-                for (; it != m_required.end(); ++it)\r
-                {\r
-                    if (*it == reqValue)\r
-                        break;\r
-                }\r
-                if (m_required.end() == it)\r
-                {\r
-                    m_required.push_back(reqValue);\r
-                }\r
-            }\r
+            void setRequiredValue(const std::string &reqValue);\r
 \r
             /**\r
                  * This method is for getting size of Properties from Definitions.\r
@@ -138,24 +133,14 @@ namespace RAML
                  *\r
                  * @return pointer to Properties.\r
                  */\r
-            inline PropertiesPtr getproperty(const std::string &propName )\r
-            {\r
-                if (m_properties.end() != m_properties.find(propName))\r
-                {\r
-                    return m_properties[propName];\r
-                }\r
-                return nullptr;\r
-            }\r
+            PropertiesPtr getproperty(const std::string &propName );\r
 \r
             /**\r
                  * This method is for getting Properties from Definitions.\r
                  *\r
                  * @return map of Property name and pointer to Properties\r
                  */\r
-            inline std::map<std::string, PropertiesPtr> const  &getProperties()\r
-            {\r
-                return m_properties;\r
-            }\r
+            std::map<std::string, PropertiesPtr> const  &getProperties();\r
 \r
             /**\r
                  * This method is for setting Properties to Definitions\r
@@ -163,13 +148,8 @@ namespace RAML
                  * @param propName - Definitions Type as string.\r
                  * @param property - pointer to Properties.\r
                  */\r
-            void addProperty(const std::string &propName, const PropertiesPtr &property)\r
-            {\r
-                if (m_properties.end() == m_properties.find(propName))\r
-                {\r
-                    m_properties[propName] =  property;\r
-                }\r
-            }\r
+            void addProperty(const std::string &propName, const PropertiesPtr &property);\r
+\r
         private:\r
             std::map<std::string, PropertiesPtr > m_properties;\r
             std::string m_defName;\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h
deleted file mode 100755 (executable)
index d5ceb68..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/******************************************************************\r
- *\r
- * Copyright 2015 Samsung Electronics All Rights Reserved.\r
- *\r
- *\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- ******************************************************************/\r
-\r
-/**\r
- * @file   Helpers.h\r
- *\r
- * @brief   This file provides helper definitions for Json Schema parser.\r
- */\r
-\r
-#ifndef HELPERS_H_\r
-#define HELPERS_H_\r
-\r
-#include <string>\r
-#include <vector>\r
-#include <map>\r
-#include <boost/variant.hpp>\r
-#include <boost/lexical_cast.hpp>\r
-\r
-namespace RAML\r
-{\r
-\r
-    /** ValueVariant - Boost Variant to hold type of int, string, double and bool*/\r
-    typedef boost::variant <\r
-    int,\r
-    double,\r
-    bool,\r
-    std::string\r
-    > ValueVariant;\r
-\r
-    /** VariantType - enumeration for variant types*/\r
-    enum class VariantType\r
-    {\r
-        INT, DOUBLE, BOOL, STRING\r
-    };\r
-\r
-\r
-}\r
-#endif\r
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Items.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Items.h
deleted file mode 100755 (executable)
index d2463b2..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/******************************************************************\r
- *\r
- * Copyright 2015 Samsung Electronics All Rights Reserved.\r
- *\r
- *\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- ******************************************************************/\r
-\r
-/**\r
- * @file   Items.h\r
- *\r
- * @brief   This file provides data Model for Json Schema Array Items.\r
- */\r
-\r
-#ifndef ITEMS_H_\r
-#define ITEMS_H_\r
-\r
-#include <string>\r
-#include <vector>\r
-#include <map>\r
-#include "Properties.h"\r
-#include "Helpers.h"\r
-#include "AllowedValues.h"\r
-#include <memory>\r
-\r
-namespace RAML\r
-{\r
-    class Properties;\r
-    class AllowedValues;\r
-    /**\r
-     * @class   Items\r
-     * @brief   This class provides data Model for Json Schema Array Items.\r
-     */\r
-    class Items\r
-    {\r
-        public:\r
-            /**\r
-                  * Constructor of Items.\r
-                  */\r
-            Items() {}\r
-\r
-            /**\r
-                 * This method is for setting Properties to Items\r
-                 *\r
-                 * @param propName - Properties name as string.\r
-                 * @param property - pointer to Properties.\r
-                 */\r
-            void addProperty(const std::string &propName, const std::shared_ptr<Properties> &property)\r
-            {\r
-                if (m_properties.end() == m_properties.find(propName))\r
-                {\r
-                    m_properties[propName] =  property;\r
-                }\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting Properties from Items.\r
-                 *\r
-                 * @param propName - Properties name as string.\r
-                 *\r
-                 * @return  pointer to Properties to put the value got\r
-                 */\r
-            std::shared_ptr<Properties> getproperty(const std::string &propName)\r
-            {\r
-                if (m_properties.end() != m_properties.find(propName))\r
-                {\r
-                    return m_properties[propName];\r
-                }\r
-                return nullptr;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting Properties from Items.\r
-                 *\r
-                 * @return map of Properties name as string and pointer to Properties\r
-                 */\r
-            std::map<std::string, std::shared_ptr<Properties> > const &getProperties()\r
-            {\r
-                return m_properties;\r
-            }\r
-\r
-            /**\r
-                 * This method is for setting Type to Items\r
-                 *\r
-                 * @param type - Type as string.\r
-                 */\r
-            void setType(const std::string &type)\r
-            {\r
-                m_type = type;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting Type from Items.\r
-                 *\r
-                 * @return Type as string\r
-                 */\r
-            std::string getType()\r
-            {\r
-                return m_type;\r
-            }\r
-\r
-            /**\r
-                 * This method is for setting RequiredValue to Items\r
-                 *\r
-                 * @param reqValue - RequiredValue as string.\r
-                 */\r
-            void setRequiredValue(const std::string &reqValue)\r
-            {\r
-                auto it = m_required.begin();\r
-                for (; it != m_required.end(); ++it)\r
-                {\r
-                    if (*it == reqValue)\r
-                        break;\r
-                }\r
-                if (m_required.end() == it)\r
-                {\r
-                    m_required.push_back(reqValue);\r
-                }\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting RequiredValue from Items.\r
-                 *\r
-                 * @return list of RequiredValue as string\r
-                 */\r
-            std::vector<std::string> const &getRequiredValues()\r
-            {\r
-                return m_required;\r
-            }\r
-\r
-            /**\r
-                 * This method is for setting AllowedValues to Items\r
-                 *\r
-                 * @param values -list of AllowedValues.\r
-                 */\r
-            template <typename T>\r
-            bool setAllowedValues(const std::vector<T> &values)\r
-            {\r
-                m_allowedValues.addValues(values);\r
-                return true;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting size of AllowedValues from Items.\r
-                 *\r
-                 * @return size of AllowedValues\r
-                 */\r
-            inline int getAllowedValuesSize() const\r
-            {\r
-                return m_allowedValues.size();\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting AllowedValues from Items.\r
-                 *\r
-                 * @return list of AllowedValues\r
-                 */\r
-            inline std::vector<ValueVariant> getAllowedValues()\r
-            {\r
-                return m_allowedValues.getValues();\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting AllowedValues as Integer from Items.\r
-                 *\r
-                 * @return list of AllowedValues as Integer\r
-                 */\r
-            inline std::vector<int> getAllowedValuesInt()\r
-            {\r
-                return m_allowedValues.getValuesInt();\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting AllowedValues as String from Items.\r
-                 *\r
-                 * @return list of AllowedValues as String\r
-                 */\r
-            inline std::vector<std::string> getAllowedValuesString()\r
-            {\r
-                return m_allowedValues.getValuesString();\r
-            }\r
-        private:\r
-            std::map<std::string, std::shared_ptr<Properties> > m_properties;\r
-            std::string m_type;\r
-            std::vector<std::string>  m_required;\r
-            AllowedValues m_allowedValues;\r
-    };\r
-\r
-    /** ItemsPtr - shared Ptr to Items.*/\r
-    typedef std::shared_ptr<Items> ItemsPtr;\r
-}\r
-#endif\r
-\r
index 0a0c11a..b62dcb5 100755 (executable)
  *\r
  ******************************************************************/\r
 \r
-#include "JsonSchema.h"\r
-using namespace std;\r
+/**\r
+ * @file   JsonSchema.cpp\r
+ *\r
+ * @brief   This file reads data from Json Schema.\r
+ */\r
 \r
+#include "JsonSchema.h"\r
+#include <iostream>\r
 namespace RAML\r
 {\r
 \r
@@ -78,26 +83,11 @@ namespace RAML
         }\r
         if (m_type == "array")\r
         {\r
-            cJSON *jsonItems = cJSON_GetObjectItem(m_cjson, "items");\r
-            if (jsonItems)\r
-            {\r
-                if (jsonItems->type == 5)\r
-                {\r
-                    int item_size = cJSON_GetArraySize(jsonItems);\r
-                    int item_index = 0;\r
-                    do\r
-                    {\r
-                        cJSON *item = cJSON_GetArrayItem(jsonItems, item_index);\r
-                        setItem(readItems(item));\r
-                    }\r
-                    while ( ++item_index < item_size);\r
-                }\r
-                else\r
-                {\r
-                    setItem(readItems(jsonItems));\r
-                }\r
-            }\r
+            PropertiesPtr property = std::make_shared<Properties>("array");\r
+            readArray(m_cjson, property);\r
+            addProperty("array" , property);\r
         }\r
+\r
         cJSON *jsonAdditionalProperties = cJSON_GetObjectItem(m_cjson, "additionalProperties");\r
         if (jsonAdditionalProperties)\r
             m_additionalProperties = jsonAdditionalProperties->type;\r
@@ -107,12 +97,37 @@ namespace RAML
         cJSON *jsonReference = cJSON_GetObjectItem(m_cjson, "$ref");\r
         if (jsonReference)\r
         {\r
-            readJsonRef(jsonReference);\r
+            JsonParameters param;\r
+            readJsonRef(jsonReference, param);\r
+\r
+            for (auto it : param.getProperties())\r
+            {\r
+                addProperty(it.first, it.second);\r
+            }\r
+            for ( auto it : param.getRequired())\r
+            {\r
+                setRequiredValue(it);\r
+            }\r
+            if (m_type.empty())\r
+                m_type = param.getType();\r
         }\r
         cJSON *jsonAllOf = cJSON_GetObjectItem(m_cjson, "allOf");\r
         if (jsonAllOf)\r
         {\r
-            readAllOf(jsonAllOf);\r
+            JsonParameters param;\r
+\r
+            readAllOf(jsonAllOf, param);\r
+\r
+            for (auto it : param.getProperties())\r
+            {\r
+                addProperty(it.first, it.second);\r
+            }\r
+            for ( auto it : param.getRequired())\r
+            {\r
+                setRequiredValue(it);\r
+            }\r
+            if (m_type.empty())\r
+                m_type = param.getType();\r
         }\r
         cJSON *jsonRequiredValues = cJSON_GetObjectItem(m_cjson, "required");\r
         if (jsonRequiredValues)\r
@@ -136,6 +151,12 @@ namespace RAML
         {\r
             std::string type = defType->valuestring;\r
             definition->setType(type);\r
+            if (type == "array")\r
+            {\r
+                PropertiesPtr property = std::make_shared<Properties>("array");\r
+                readArray(childDefinitions, property);\r
+                definition->addProperty("array" , property);\r
+            }\r
         }\r
         cJSON *defProperties = cJSON_GetObjectItem(childDefinitions, "properties");\r
         if (defProperties)\r
@@ -162,12 +183,36 @@ namespace RAML
         cJSON *defReference = cJSON_GetObjectItem(childDefinitions, "$ref");\r
         if (defReference)\r
         {\r
-            readDefRef(defReference, definition);\r
+            JsonParameters param;\r
+            readJsonRef(defReference, param);\r
+\r
+            for (auto it : param.getProperties())\r
+            {\r
+                definition->addProperty(it.first, it.second);\r
+            }\r
+            for ( auto it : param.getRequired())\r
+            {\r
+                definition->setRequiredValue(it);\r
+            }\r
+            if (definition->getType().empty())\r
+                definition->setType(param.getType());\r
         }\r
         cJSON *defAllOf = cJSON_GetObjectItem(childDefinitions, "allOf");\r
         if (defAllOf)\r
         {\r
-            readDefAllOf(defAllOf, definition);\r
+            JsonParameters param;\r
+            readAllOf(defAllOf, param);\r
+\r
+            for (auto it : param.getProperties())\r
+            {\r
+                definition->addProperty(it.first, it.second);\r
+            }\r
+            for ( auto it : param.getRequired())\r
+            {\r
+                definition->setRequiredValue(it);\r
+            }\r
+            if (definition->getType().empty())\r
+                definition->setType(param.getType());\r
         }\r
         return definition;\r
     }\r
@@ -182,106 +227,125 @@ namespace RAML
             property->setDescription(propertyDescription->valuestring);\r
         }\r
         cJSON *propertyType = cJSON_GetObjectItem(childProperties, "type");\r
+        std::string attType;\r
         if (propertyType)\r
         {\r
-            std::string attType;\r
             if (propertyType->type == 4)\r
             {\r
                 attType = propertyType->valuestring;\r
-                property->setType(attType);\r
             }\r
             else if (propertyType->type == 5)\r
             {\r
                 attType = cJSON_GetArrayItem(propertyType, 0)->valuestring;\r
-                property->setType(attType);\r
             }\r
-            readValues(childProperties, property, attType);\r
         }\r
-        cJSON *defaultValue = cJSON_GetObjectItem(childProperties, "default");\r
-        if (defaultValue)\r
+        if (!(attType == "array") && !(attType == "object"))\r
         {\r
-            if (defaultValue->type == 4)\r
+            cJSON *defaultValue = cJSON_GetObjectItem(childProperties, "default");\r
+            if (defaultValue)\r
             {\r
-                property->setValue((std::string)defaultValue->valuestring);\r
+                readDefaultValue(defaultValue, property, attType);\r
             }\r
-            else if (defaultValue->type == 3)\r
-            {\r
-                if (property->getType() == "number")\r
-                    property->setValue((double)defaultValue->valuedouble);\r
-                else\r
-                    property->setValue((int)defaultValue->valueint );\r
-            }\r
-            else if (defaultValue->type == 1)\r
-            {\r
-                property->setValue((bool)true);\r
-            }\r
-            else if (defaultValue->type == 0)\r
-            {\r
-                property->setValue((bool)false);\r
-            }\r
-\r
         }\r
+        readValues(childProperties, property, attType);\r
         cJSON *allowedvalues = cJSON_GetObjectItem(childProperties, "enum");\r
         if (allowedvalues)\r
         {\r
-            if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 4)\r
+            readAllowedValues(allowedvalues, property, attType);\r
+        }\r
+        property->setTypeString(attType);\r
+        return property;\r
+    }\r
+\r
+    void JsonSchema::readDefaultValue(cJSON *defaultValue,  PropertiesPtr &property,\r
+                                      const std::string &attType)\r
+    {\r
+        if (defaultValue->type == 4)\r
+        {\r
+            property->setValue((std::string)defaultValue->valuestring);\r
+        }\r
+        else if (defaultValue->type == 3)\r
+        {\r
+            if (attType == "number")\r
+                property->setValue((double)defaultValue->valuedouble);\r
+            else\r
+                property->setValue((int)defaultValue->valueint );\r
+        }\r
+        else if (defaultValue->type == 1)\r
+        {\r
+            property->setValue((bool)true);\r
+        }\r
+        else if (defaultValue->type == 0)\r
+        {\r
+            property->setValue((bool)false);\r
+        }\r
+    }\r
+\r
+    void JsonSchema::readAllowedValues(cJSON *allowedvalues,  PropertiesPtr &property,\r
+                                       std::string &attType)\r
+    {\r
+        if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 4)\r
+        {\r
+            int size = cJSON_GetArraySize(allowedvalues);\r
+            int idx = 0;\r
+            std::vector<std::string> allwdValues;\r
+            do\r
             {\r
-                int size = cJSON_GetArraySize(allowedvalues);\r
-                int idx = 0;\r
-                std::vector<std::string> allwdValues;\r
-                do\r
-                {\r
-                    allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuestring);\r
-                }\r
-                while ( ++idx < size);\r
-                property->setAllowedValues(allwdValues);\r
+                allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuestring);\r
             }\r
-            else if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 3)\r
+            while ( ++idx < size);\r
+            property->setValueProperty(std::make_shared<ValueProperty>(allwdValues));\r
+            if (attType.empty())\r
+                attType = "string";\r
+        }\r
+        else if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 3)\r
+        {\r
+            int size = cJSON_GetArraySize(allowedvalues);\r
+            int idx = 0;\r
+            if (attType == "number")\r
             {\r
-                int size = cJSON_GetArraySize(allowedvalues);\r
-                int idx = 0;\r
-                if (property->getType() == "number")\r
-                {\r
-                    std::vector<double> allwdValues;\r
-                    do\r
-                    {\r
-                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuedouble);\r
-                    }\r
-                    while ( ++idx < size);\r
-                    property->setAllowedValues(allwdValues);\r
-                }\r
-                else\r
+                std::vector<double> allwdValues;\r
+                do\r
                 {\r
-                    std::vector<int> allwdValues;\r
-                    do\r
-                    {\r
-                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valueint);\r
-                    }\r
-                    while ( ++idx < size);\r
-                    property->setAllowedValues(allwdValues);\r
+                    allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuedouble);\r
                 }\r
+                while ( ++idx < size);\r
+                property->setValueProperty(std::make_shared<ValueProperty>(allwdValues));\r
             }\r
-            else if (((cJSON_GetArrayItem(allowedvalues, 0)->type) == 1)\r
-                     || ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 0))\r
+            else\r
             {\r
-                int size = cJSON_GetArraySize(allowedvalues);\r
-                int idx = 0;\r
-                std::vector<bool> allwdValues;\r
+                std::vector<int> allwdValues;\r
                 do\r
                 {\r
-                    if (cJSON_GetArrayItem(allowedvalues, idx)->type)\r
-                        allwdValues.push_back(true);\r
-                    else\r
-                        allwdValues.push_back(false);\r
+                    allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valueint);\r
                 }\r
                 while ( ++idx < size);\r
-                property->setAllowedValues(allwdValues);\r
+                property->setValueProperty(std::make_shared<ValueProperty>(allwdValues));\r
+                if (attType.empty())\r
+                    attType = "integer";\r
             }\r
         }\r
-        return property;\r
+        else if (((cJSON_GetArrayItem(allowedvalues, 0)->type) == 1)\r
+                 || ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 0))\r
+        {\r
+            int size = cJSON_GetArraySize(allowedvalues);\r
+            int idx = 0;\r
+            std::vector<bool> allwdValues;\r
+            do\r
+            {\r
+                if (cJSON_GetArrayItem(allowedvalues, idx)->type)\r
+                    allwdValues.push_back(true);\r
+                else\r
+                    allwdValues.push_back(false);\r
+            }\r
+            while ( ++idx < size);\r
+            property->setValueProperty(std::make_shared<ValueProperty>(allwdValues));\r
+            if (attType.empty())\r
+                attType = "boolean";\r
+        }\r
     }\r
 \r
-    void JsonSchema::readValues(cJSON *childProperties,  PropertiesPtr property ,\r
+    void JsonSchema::readValues(cJSON *childProperties,  PropertiesPtr &property ,\r
                                 const std::string &attType)\r
     {\r
         if (attType == "string")\r
@@ -292,31 +356,32 @@ namespace RAML
         {\r
             readInteger(childProperties, property);\r
         }\r
-        else if (attType == "array")\r
-        {\r
-            readArray(childProperties, property);\r
-        }\r
         else if (attType == "number")\r
         {\r
             readDouble(childProperties, property);\r
         }\r
+        else if (attType == "array")\r
+        {\r
+            readArray(childProperties, property);\r
+        }\r
     }\r
 \r
-    void JsonSchema::readString(cJSON *childProperties, PropertiesPtr property)\r
+    void JsonSchema::readString(cJSON *childProperties, PropertiesPtr &property)\r
     {\r
         cJSON *stringMax = cJSON_GetObjectItem(childProperties, "maxLength");\r
+        int min = INT_MIN, max = INT_MAX;\r
         if (stringMax)\r
         {\r
             cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");\r
             if (exclusiveMax)\r
             {\r
                 if (exclusiveMax->type == cJSON_True)\r
-                    property->setMax (--(stringMax->valueint));\r
+                    max = --(stringMax->valueint);\r
                 else\r
-                    property->setMax(stringMax->valueint);\r
+                    max = stringMax->valueint;\r
             }\r
             else\r
-                property->setMax(stringMax->valueint);\r
+                max = stringMax->valueint;\r
         }\r
         cJSON *stringMin = cJSON_GetObjectItem(childProperties, "minLength");\r
         if (stringMin)\r
@@ -325,109 +390,89 @@ namespace RAML
             if (exclusiveMin)\r
             {\r
                 if (exclusiveMin->type == cJSON_True)\r
-                    property->setMin( ++(stringMin->valueint));\r
+                    min = ++(stringMin->valueint);\r
                 else\r
-                    property->setMin(stringMin->valueint);\r
+                    min = stringMin->valueint;\r
             }\r
             else\r
-                property->setMin(stringMin->valueint);\r
+                min = stringMin->valueint;\r
         }\r
+        if (min != INT_MIN || max != INT_MAX)\r
+            property->setValueProperty(std::make_shared<ValueProperty>(min, max, 0));\r
+\r
         cJSON *stringFormat = cJSON_GetObjectItem(childProperties, "format");\r
         if (stringFormat)\r
         {\r
-            property->setFormat(stringFormat->valuestring);\r
+            property->setValueProperty(std::make_shared<ValueProperty>\r
+                                       (ValueProperty::Type::FORMAT, (stringFormat->valuestring)));\r
         }\r
+\r
         cJSON *stringPattern = cJSON_GetObjectItem(childProperties, "pattern");\r
         if (stringPattern)\r
         {\r
-            property->setPattern(stringPattern->valuestring);\r
+            property->setValueProperty(std::make_shared<ValueProperty>\r
+                                       (ValueProperty::Type::PATTERN, (stringPattern->valuestring)));\r
         }\r
     }\r
 \r
-    void JsonSchema::readArray(cJSON *childProperties,  PropertiesPtr property)\r
+    void JsonSchema::readInteger(cJSON *childProperties,  PropertiesPtr &property)\r
     {\r
-        cJSON *itemValues = cJSON_GetObjectItem(childProperties, "items");\r
-        if (itemValues)\r
-        {\r
-            if (itemValues->type == 5)\r
-            {\r
-                int item_size = cJSON_GetArraySize(itemValues);\r
-                int item_index = 0;\r
-                do\r
-                {\r
-                    cJSON *item = cJSON_GetArrayItem(itemValues, item_index);\r
-                    property->setItem(readItems(item));\r
-                }\r
-                while ( ++item_index < item_size);\r
-            }\r
-            else\r
-            {\r
-                property->setItem(readItems(itemValues));\r
-            }\r
-        }\r
-        cJSON *itemsMax = cJSON_GetObjectItem(childProperties, "maxItems");\r
-        if (itemsMax)\r
+        cJSON *Max = cJSON_GetObjectItem(childProperties, "maximum");\r
+        int min = INT_MIN, max = INT_MAX, multipleOf = INT_MAX;\r
+        if (Max)\r
         {\r
             cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");\r
             if (exclusiveMax)\r
             {\r
                 if (exclusiveMax->type == cJSON_True)\r
-                    property->setMax( --(itemsMax->valueint));\r
+                    max = --(Max->valueint);\r
                 else\r
-                    property->setMax(itemsMax->valueint);\r
+                    max = Max->valueint;\r
             }\r
             else\r
-                property->setMax(itemsMax->valueint);\r
+                max = Max->valueint;\r
         }\r
-        cJSON *itemsMin = cJSON_GetObjectItem(childProperties, "minLength");\r
-        if (itemsMin)\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->setMin( ++(itemsMin->valueint));\r
+                    min = ++(Min->valueint);\r
                 else\r
-                    property->setMin(itemsMin->valueint);\r
+                    min = Min->valueint;\r
             }\r
             else\r
-                property->setMin(itemsMin->valueint);\r
-        }\r
-        cJSON *uniqueItems = cJSON_GetObjectItem(childProperties, "uniqueItems");\r
-        if (uniqueItems)\r
-        {\r
-            property->setUnique(uniqueItems->type);\r
-        }\r
-        else\r
-        {\r
-            property->setUnique(cJSON_True);\r
+                min = Min->valueint;\r
         }\r
-        cJSON *additionalItems = cJSON_GetObjectItem(childProperties, "additionalItems");\r
-        if (additionalItems)\r
-        {\r
-            property->setAdditionalItems(additionalItems->type);\r
-        }\r
-        else\r
+        cJSON *MultipleOff = cJSON_GetObjectItem(childProperties, "multipleOf");\r
+        if (MultipleOff)\r
         {\r
-            property->setAdditionalItems(cJSON_True);\r
+            multipleOf = MultipleOff->valueint;\r
         }\r
+        if (min != INT_MIN || max != INT_MAX)\r
+            property->setValueProperty(std::make_shared<ValueProperty>(min, max, multipleOf));\r
+\r
     }\r
 \r
-    void JsonSchema::readInteger(cJSON *childProperties,  PropertiesPtr property)\r
+    void JsonSchema::readDouble(cJSON *childProperties,  PropertiesPtr &property)\r
     {\r
         cJSON *Max = cJSON_GetObjectItem(childProperties, "maximum");\r
+        double min = INT_MIN, max = INT_MAX;\r
+        int multipleOf = INT_MAX;\r
         if (Max)\r
         {\r
             cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");\r
             if (exclusiveMax)\r
             {\r
                 if (exclusiveMax->type == cJSON_True)\r
-                    property->setMax( --(Max->valueint));\r
+                    max = --(Max->valuedouble);\r
                 else\r
-                    property->setMax(Max->valueint);\r
+                    max = Max->valuedouble;\r
             }\r
             else\r
-                property->setMax(Max->valueint);\r
+                max = Max->valuedouble;\r
         }\r
         cJSON *Min = cJSON_GetObjectItem(childProperties, "minimum");\r
         if (Min)\r
@@ -436,423 +481,313 @@ namespace RAML
             if (exclusiveMin)\r
             {\r
                 if (exclusiveMin->type == cJSON_True)\r
-                    property->setMin( ++(Min->valueint));\r
+                    min = ++(Min->valuedouble);\r
                 else\r
-                    property->setMin(Min->valueint);\r
+                    min = Min->valuedouble;\r
             }\r
             else\r
-                property->setMin(Min->valueint);\r
+                min = Min->valuedouble;\r
         }\r
-        cJSON *multipleOf = cJSON_GetObjectItem(childProperties, "multipleOf");\r
-        if (multipleOf)\r
+\r
+        cJSON *MultipleOff = cJSON_GetObjectItem(childProperties, "multipleOf");\r
+        if (MultipleOff)\r
         {\r
-            property->setMultipleOf(multipleOf->valueint);\r
+            multipleOf = MultipleOff->valueint;\r
         }\r
+        if (min != INT_MIN || max != INT_MAX)\r
+            property->setValueProperty(std::make_shared<ValueProperty>(min, max, multipleOf));\r
 \r
     }\r
 \r
-    void JsonSchema::readDouble(cJSON *childProperties,  PropertiesPtr property)\r
+    void JsonSchema::readArray(cJSON *childProperties,  PropertiesPtr &property)\r
     {\r
-        cJSON *Max = cJSON_GetObjectItem(childProperties, "maximum");\r
-        if (Max)\r
+        cJSON *itemValues = cJSON_GetObjectItem(childProperties, "items");\r
+        if (itemValues)\r
+        {\r
+            if (itemValues->type == 5)\r
+            {\r
+                int item_size = cJSON_GetArraySize(itemValues);\r
+                int item_index = 0;\r
+                do\r
+                {\r
+                    cJSON *item = cJSON_GetArrayItem(itemValues, item_index);\r
+                    readItems(item, property);\r
+                    break; \r
+                }\r
+                while ( ++item_index < item_size);\r
+            }\r
+            else\r
+            {\r
+                readItems(itemValues, property);\r
+            }\r
+        }\r
+        cJSON *itemsMax = cJSON_GetObjectItem(childProperties, "maxItems");\r
+        int min = INT_MIN, max = INT_MAX;\r
+        bool unique = cJSON_True, addItems = cJSON_True;\r
+        if (itemsMax)\r
         {\r
             cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");\r
             if (exclusiveMax)\r
             {\r
                 if (exclusiveMax->type == cJSON_True)\r
-                    property->setMax( --(Max->valuedouble));\r
+                    max = --(itemsMax->valueint);\r
                 else\r
-                    property->setMax(Max->valuedouble);\r
+                    max = itemsMax->valueint;\r
             }\r
             else\r
-                property->setMax(Max->valuedouble);\r
+                max = itemsMax->valueint;\r
         }\r
-        cJSON *Min = cJSON_GetObjectItem(childProperties, "minimum");\r
-        if (Min)\r
+        cJSON *itemsMin = cJSON_GetObjectItem(childProperties, "minItems");\r
+        if (itemsMin)\r
         {\r
             cJSON *exclusiveMin = cJSON_GetObjectItem(childProperties, "exclusiveMinimum");\r
             if (exclusiveMin)\r
             {\r
                 if (exclusiveMin->type == cJSON_True)\r
-                    property->setMin( ++(Min->valuedouble));\r
+                    min = ++(itemsMin->valueint);\r
                 else\r
-                    property->setMin(Min->valuedouble);\r
+                    min = itemsMin->valueint;\r
             }\r
             else\r
-                property->setMin(Min->valuedouble);\r
+                min = itemsMin->valueint;\r
         }\r
-        cJSON *multipleOf = cJSON_GetObjectItem(childProperties, "multipleOf");\r
-        if (multipleOf)\r
+        cJSON *uniqueItems = cJSON_GetObjectItem(childProperties, "uniqueItems");\r
+        if (uniqueItems)\r
         {\r
-            property->setMultipleOf(multipleOf->valueint);\r
+            unique = uniqueItems->type;\r
         }\r
-\r
+        cJSON *additionalItems = cJSON_GetObjectItem(childProperties, "additionalItems");\r
+        if (additionalItems)\r
+        {\r
+            addItems = additionalItems->type;\r
+        }\r
+        property->setValueProperty(std::make_shared<ValueProperty>\r
+                                   (ValueProperty::Type::ARRAY, min, max, unique, addItems));\r
     }\r
 \r
-    DefinitionsPtr JsonSchema::readRef(std::string m_ref)\r
+    void JsonSchema::readItems(cJSON *item, PropertiesPtr &property)\r
     {\r
-        std::string delimiter1 = "#";\r
-        std::string delimiter2 = "/";\r
-        std::string fileName;\r
-        if (! m_ref.empty())\r
+        std::string type;\r
+        JsonParameters param;\r
+        cJSON *itemType = cJSON_GetObjectItem(item, "type");\r
+        if (itemType)\r
         {\r
-            std::size_t pos = m_ref.find(delimiter1);\r
-            if ( (pos = m_ref.find(delimiter1)) != std::string::npos)\r
-            {\r
-                fileName = m_ref.substr(0, pos);\r
-                m_ref.erase(0, pos);\r
-            }\r
-            m_ref.erase(0, delimiter1 .length());\r
-            std::string defName;\r
+            type = itemType->valuestring;\r
+        }\r
 \r
-            if (! m_ref.empty())\r
-            {\r
-                m_ref.erase(0, delimiter2 .length());\r
-                std::string keyName;\r
-                if ( (pos = m_ref.find(delimiter2)) != std::string::npos)\r
-                {\r
-                    keyName = m_ref.substr(0, pos);\r
-                    m_ref.erase(0, pos + delimiter2.length());\r
-                    if (keyName == "definitions")\r
-                    {\r
-                        if ( (pos = m_ref.find(delimiter2)) != std::string::npos)\r
-                        {\r
-                            defName = m_ref.substr(0, pos);\r
-                        }\r
-                        else if (! m_ref.empty())\r
-                        {\r
-                            defName = m_ref;\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-            if (!fileName.empty())\r
-            {\r
-                if (!(defName.empty()))\r
-                {\r
-                    cJSON *m_json = m_includeResolver->readToJson(fileName);\r
-                    JsonSchemaPtr Refparser = std::make_shared<JsonSchema>(m_json, m_includeResolver);\r
-                    DefinitionsPtr definition = Refparser->getDefinition(defName);\r
-                    if (definition == nullptr)\r
-                        throw JsonException("Definition Name Incorrect");\r
-                    return definition;\r
-                }\r
-            }\r
-            else\r
-            {\r
-                if (!(defName.empty()))\r
-                {\r
-                    if (getDefinition(defName) == nullptr)\r
-                        throw JsonException("Definition Name Incorrect");\r
-                    return getDefinition(defName);\r
-                }\r
-            }\r
+        cJSON *itemAllOf = cJSON_GetObjectItem(item, "allOf");\r
+        if (itemAllOf)\r
+        {\r
+            readAllOf(itemAllOf , param);\r
         }\r
-        throw JsonException("Definition Name Empty");\r
-        return nullptr;\r
-    }\r
-    void JsonSchema::readAllOf(cJSON *allofValues)\r
-    {\r
-        int size = cJSON_GetArraySize(allofValues);\r
-        int index = 0;\r
-        do\r
+        cJSON *itemReference = cJSON_GetObjectItem(item, "$ref");\r
+        if (itemReference)\r
         {\r
-            cJSON *childAllOf = cJSON_GetArrayItem(allofValues, index);\r
-            cJSON *jsonReference = cJSON_GetObjectItem(childAllOf, "$ref");\r
-            if (jsonReference)\r
+            readJsonRef(itemReference , param);\r
+        }\r
+\r
+        if (type == "object")\r
+        {\r
+            cJSON *itemProperties = cJSON_GetObjectItem(item, "properties");\r
+            if (itemProperties)\r
             {\r
-                readJsonRef(jsonReference );\r
+                cJSON *childProperties = itemProperties->child;\r
+                std::vector<Properties> propertyVector;\r
+                while (childProperties)\r
+                {\r
+                    std::string attName = childProperties->string;\r
+                    PropertiesPtr prop = std::make_shared<Properties>(attName);\r
+                    readProp(childProperties, attName);\r
+                    propertyVector.push_back(*prop);\r
+                    childProperties = childProperties->next;\r
+                }\r
+                property->setValue(propertyVector);\r
             }\r
-            cJSON *jsonRequiredValues = cJSON_GetObjectItem(childAllOf, "required");\r
-            if (jsonRequiredValues)\r
+\r
+            cJSON *itemRequiredValues = cJSON_GetObjectItem(item, "required");\r
+            if (itemRequiredValues)\r
             {\r
-                int len = cJSON_GetArraySize(jsonRequiredValues);\r
-                int idx = 0;\r
+                int size = cJSON_GetArraySize(itemRequiredValues);\r
+                int index = 0;\r
                 do\r
                 {\r
-                    setRequiredValue(cJSON_GetArrayItem(jsonRequiredValues, idx)->valuestring);\r
+                    property->setRequiredValue(cJSON_GetArrayItem(itemRequiredValues, index)->valuestring);\r
                 }\r
-                while ( ++idx < len);\r
+                while ( ++index < size);\r
             }\r
         }\r
-        while ( ++index < size);\r
-    }\r
-    void JsonSchema::readJsonRef(cJSON *jsonReference)\r
-    {\r
-        std::string m_ref = jsonReference->valuestring;\r
-        std::map<std::string, PropertiesPtr > properties;\r
-        std::vector<std::string> required;\r
-\r
-        std::string web = "http://";\r
-        std::string delimiter = "#";\r
-        std::size_t pos = m_ref.find(web);\r
 \r
-        if (pos == std::string::npos)   // If Web Link Is GIVEN TO READ\r
+        else if (param.getType() == "object")\r
         {\r
-            pos = m_ref.find(delimiter);\r
-            if ( pos ==  (m_ref.length() - 1) )\r
-            {\r
-                std::string fileName = m_ref.substr(0, pos);\r
-                cJSON *m_json = m_includeResolver->readToJson(fileName);\r
-                JsonSchemaPtr Refparser = std::make_shared<JsonSchema>(m_json, m_includeResolver);\r
-\r
-                properties = Refparser->getProperties();\r
-                required = Refparser->getRequiredValues();\r
-            }\r
-            else\r
-            {\r
-                DefinitionsPtr definition = readRef(m_ref);\r
-                properties = definition->getProperties();\r
-                required = definition->getRequiredValues();\r
-            }\r
-            for ( auto it : properties)\r
+            std::vector<Properties> propertyVector;\r
+            for (auto prop : param.getProperties())\r
             {\r
-                std:: string name = it.first;\r
-                addProperty(name, it.second);\r
+                propertyVector.push_back(*(prop.second));\r
             }\r
-            for (auto it : required )\r
+            property->setValue(propertyVector);\r
+\r
+            for (auto req : param.getRequired())\r
             {\r
-                setRequiredValue(it);\r
+                property->setRequiredValue(req);\r
             }\r
-\r
         }\r
-    }\r
-    void JsonSchema::readDefAllOf(cJSON *allofValues, DefinitionsPtr definition)\r
-    {\r
-        int size = cJSON_GetArraySize(allofValues);\r
-        int index = 0;\r
-        do\r
+        else\r
         {\r
-            cJSON *childAllOf = cJSON_GetArrayItem(allofValues, index);\r
-            cJSON *defReference = cJSON_GetObjectItem(childAllOf, "$ref");\r
-            if (defReference)\r
+            PropertiesPtr prop = std::make_shared<Properties>("property");\r
+\r
+            cJSON *defaultValue = cJSON_GetObjectItem(item, "default");\r
+            if (defaultValue)\r
             {\r
-                readDefRef(defReference , definition);\r
+                readDefaultValue(defaultValue, prop, type);\r
             }\r
-            cJSON *defRequiredValues = cJSON_GetObjectItem(allofValues, "required");\r
-            if (defRequiredValues)\r
+            cJSON *allowedvalues = cJSON_GetObjectItem(item, "enum");\r
+            if (allowedvalues)\r
             {\r
-                int len = cJSON_GetArraySize(defRequiredValues);\r
-                int idx = 0;\r
-                do\r
-                {\r
-                    definition->setRequiredValue(cJSON_GetArrayItem(defRequiredValues, idx)->valuestring);\r
-                }\r
-                while ( ++idx < len);\r
+                readAllowedValues(allowedvalues, prop, type);\r
             }\r
+            prop->setTypeString(type);\r
+            property->setValue(*prop);\r
         }\r
-        while ( ++index < size);\r
     }\r
-    void JsonSchema::readDefRef(cJSON *defReference, DefinitionsPtr definition)\r
+\r
+    void JsonSchema::readFile(std::string &fileName ,  JsonParameters &param)\r
     {\r
-        std::string m_ref = defReference->valuestring;\r
-        std::map<std::string, PropertiesPtr > properties;\r
-        std::vector<std::string> required;\r
-        std::string type;\r
+        cJSON *json = m_includeResolver->readToJson(fileName);\r
+        JsonSchemaPtr Refparser = std::make_shared<JsonSchema>(json, m_includeResolver);\r
 \r
-        std::string web = "http://";\r
-        std::string delimiter = "#";\r
-        std::size_t pos = m_ref.find(web);\r
+        param.addProperties(Refparser->getProperties());\r
+        param.addRequired(Refparser->getRequiredValues());\r
+        param.setType(Refparser->getType());\r
+    }\r
 \r
-        if (pos == std::string::npos)   // If Web Link Is GIVEN TO READ\r
-        {\r
-            pos = m_ref.find(delimiter);\r
-            if ( pos ==  (m_ref.length() - 1) )\r
-            {\r
-                std::string fileName = m_ref.substr(0, pos);\r
-                cJSON *m_json = m_includeResolver->readToJson(fileName);\r
-                JsonSchemaPtr Refparser = std::make_shared<JsonSchema>(m_json, m_includeResolver);\r
+    void JsonSchema::readFile(std::string &fileName , std::string &defName ,  JsonParameters &param)\r
+    {\r
+        cJSON *json = m_includeResolver->readToJson(fileName);\r
+        JsonSchemaPtr Refparser = std::make_shared<JsonSchema>(json, m_includeResolver);\r
 \r
-                properties = Refparser->getProperties();\r
-                required = Refparser->getRequiredValues();\r
-                type =    Refparser->getType();\r
-            }\r
-            else\r
-            {\r
-                DefinitionsPtr definitionRef = readRef(m_ref);\r
-                properties = definitionRef->getProperties();\r
-                required = definitionRef->getRequiredValues();\r
-                type =    definitionRef->getType();\r
-            }\r
-            for (auto it : properties)\r
-            {\r
-                definition->addProperty(it.first, it.second);\r
-            }\r
-            for ( auto it : required)\r
-            {\r
-                definition->setRequiredValue(it);\r
-            }\r
-            definition->setType(type);\r
-        }\r
+        DefinitionsPtr definition = Refparser->getDefinition(defName);\r
+        if (definition == nullptr)\r
+            throw JsonException("Definition Name Incorrect");\r
+\r
+        param.addProperties(definition->getProperties());\r
+        param.addRequired(definition->getRequiredValues());\r
+        param.setType(definition->getType());\r
     }\r
-    ItemsPtr JsonSchema::readItems(cJSON *item)\r
-    {\r
-        ItemsPtr newItem = std::make_shared<Items>();\r
-        cJSON *itemType = cJSON_GetObjectItem(item, "type");\r
-        if (itemType)\r
-        {\r
-            std::string type = itemType->valuestring;\r
-            newItem->setType(type);\r
-        }\r
 \r
-        cJSON *itemProperties = cJSON_GetObjectItem(item, "properties");\r
-        if (itemProperties)\r
+    void JsonSchema::readRef(std::string ref ,  JsonParameters &param)\r
+    {\r
+        std::string delimiter1 = "#";\r
+        std::string delimiter2 = "/";\r
+        std::string fileName;\r
+        if (! ref.empty())\r
         {\r
-            cJSON *childProperties = itemProperties->child;\r
-            while (childProperties)\r
+            std::size_t pos = ref.find(delimiter1);\r
+            if ( (pos = ref.find(delimiter1)) != std::string::npos)\r
             {\r
-                std::string attName = childProperties->string;\r
-\r
-                newItem->addProperty(attName, readProp(childProperties, attName));\r
-                childProperties = childProperties->next;\r
+                fileName = ref.substr(0, pos);\r
+                ref.erase(0, pos);\r
             }\r
-        }\r
+            ref.erase(0, delimiter1 .length());\r
+            std::string defName;\r
 \r
-        cJSON *allowedvalues = cJSON_GetObjectItem(item, "enum");\r
-        if (allowedvalues)\r
-        {\r
-            if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 4)\r
+            if (! ref.empty())\r
             {\r
-                int size = cJSON_GetArraySize(allowedvalues);\r
-                int idx = 0;\r
-                std::vector<std::string> allwdValues;\r
-                do\r
+                ref.erase(0, delimiter2 .length());\r
+                std::string keyName;\r
+                if ( (pos = ref.find(delimiter2)) != std::string::npos)\r
                 {\r
-                    allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuestring);\r
+                    keyName = ref.substr(0, pos);\r
+                    ref.erase(0, pos + delimiter2.length());\r
+                    if (keyName == "definitions")\r
+                    {\r
+                        if ( (pos = ref.find(delimiter2)) != std::string::npos)\r
+                        {\r
+                            defName = ref.substr(0, pos);\r
+                        }\r
+                        else if (! ref.empty())\r
+                        {\r
+                            defName = ref;\r
+                        }\r
+                    }\r
                 }\r
-                while ( ++idx < size);\r
-                newItem->setAllowedValues(allwdValues);\r
             }\r
-            else if ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 3)\r
+            if (!fileName.empty())\r
             {\r
-                int size = cJSON_GetArraySize(allowedvalues);\r
-                int idx = 0;\r
-                if (newItem->getType() == "number")\r
+                if (!(defName.empty()))\r
                 {\r
-                    std::vector<double> allwdValues;\r
-                    do\r
-                    {\r
-                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuedouble);\r
-                    }\r
-                    while ( ++idx < size);\r
-                    newItem->setAllowedValues(allwdValues);\r
+                    readFile(fileName, defName, param);\r
                 }\r
                 else\r
                 {\r
-                    std::vector<int> allwdValues;\r
-                    do\r
-                    {\r
-                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valueint);\r
-                    }\r
-                    while ( ++idx < size);\r
-                    newItem->setAllowedValues(allwdValues);\r
+                    throw JsonException("Definition Name Empty");\r
                 }\r
             }\r
-            else if (((cJSON_GetArrayItem(allowedvalues, 0)->type) == 1)\r
-                     || ((cJSON_GetArrayItem(allowedvalues, 0)->type) == 0))\r
+            else\r
             {\r
-                int size = cJSON_GetArraySize(allowedvalues);\r
-                int idx = 0;\r
-                std::vector<bool> allwdValues;\r
-                do\r
+                if (!(defName.empty()))\r
                 {\r
-                    if (cJSON_GetArrayItem(allowedvalues, idx)->type)\r
-                        allwdValues.push_back(true);\r
-                    else\r
-                        allwdValues.push_back(false);\r
+                    if (getDefinition(defName) == nullptr)\r
+                        throw JsonException("Definition Name Incorrect");\r
+                    param.addProperties(getDefinition(defName)->getProperties());\r
+                    param.addRequired(getDefinition(defName)->getRequiredValues());\r
+                    param.setType(getDefinition(defName)->getType());\r
+                }\r
+                else\r
+                {\r
+                    throw JsonException("Definition Name Empty");\r
                 }\r
-                while ( ++idx < size);\r
-                newItem->setAllowedValues(allwdValues);\r
             }\r
         }\r
-        cJSON *itemRequiredValues = cJSON_GetObjectItem(item, "required");\r
-        if (itemRequiredValues)\r
-        {\r
-            int size = cJSON_GetArraySize(itemRequiredValues);\r
-            int index = 0;\r
-            do\r
-            {\r
-                newItem->setRequiredValue(cJSON_GetArrayItem(itemRequiredValues, index)->valuestring);\r
-            }\r
-            while ( ++index < size);\r
-        }\r
-        cJSON *itemReference = cJSON_GetObjectItem(item, "$ref");\r
-        if (itemReference)\r
-        {\r
-            readItemRef(itemReference , newItem);\r
-        }\r
-        cJSON *itemAllOf = cJSON_GetObjectItem(item, "allOf");\r
-        if (itemAllOf)\r
-        {\r
-            readItemAllOf(itemAllOf , newItem);\r
-        }\r
-        return newItem;\r
     }\r
 \r
-    void JsonSchema::readItemRef(cJSON *itemReference, ItemsPtr item)\r
+    void JsonSchema::readJsonRef(cJSON *jsonReference , JsonParameters &param)\r
     {\r
-        std::string m_ref = itemReference->valuestring;\r
-        std::map<std::string, PropertiesPtr > properties;\r
-        std::vector<std::string> required;\r
-        std::string type;\r
+        std::string ref = jsonReference->valuestring;\r
 \r
         std::string web = "http://";\r
         std::string delimiter = "#";\r
-        std::size_t pos = m_ref.find(web);\r
+        std::size_t pos = ref.find(web);\r
 \r
         if (pos == std::string::npos)   // If Web Link Is GIVEN TO READ\r
         {\r
-            pos = m_ref.find(delimiter);\r
-            if ( pos ==  (m_ref.length() - 1 ) )\r
+            pos = ref.find(delimiter);\r
+            if ( pos ==  (ref.length() - 1) )\r
             {\r
-                std::string fileName = m_ref.substr(0, pos);\r
-                cJSON *m_json = m_includeResolver->readToJson(fileName);\r
-                JsonSchemaPtr Refparser = std::make_shared<JsonSchema>(m_json, m_includeResolver);\r
-\r
-                properties = Refparser->getProperties();\r
-                required = Refparser->getRequiredValues();\r
-                type =    Refparser->getType();\r
+                std::string fileName = ref.substr(0, pos);\r
+                readFile(fileName, param);\r
             }\r
             else\r
             {\r
-                DefinitionsPtr definitionRef = readRef(m_ref);\r
-                properties = definitionRef->getProperties();\r
-                required = definitionRef->getRequiredValues();\r
-                type =    definitionRef->getType();\r
+                readRef(ref, param);\r
             }\r
-            for ( auto it : properties)\r
-            {\r
-                std:: string name = it.first;\r
-                item->addProperty(name, it.second);\r
-            }\r
-            for ( auto it : required)\r
-            {\r
-                item->setRequiredValue(it);\r
-            }\r
-            item->setType(type);\r
         }\r
     }\r
 \r
-    void JsonSchema::readItemAllOf(cJSON *allofValues, ItemsPtr item)\r
+    void JsonSchema::readAllOf(cJSON *allofValues ,  JsonParameters &allParams)\r
     {\r
         int size = cJSON_GetArraySize(allofValues);\r
         int index = 0;\r
         do\r
         {\r
+            JsonParameters param;\r
+\r
             cJSON *childAllOf = cJSON_GetArrayItem(allofValues, index);\r
-            cJSON *itemReference = cJSON_GetObjectItem(childAllOf, "$ref");\r
-            if (itemReference)\r
+            cJSON *jsonReference = cJSON_GetObjectItem(childAllOf, "$ref");\r
+            if (jsonReference)\r
             {\r
-                readItemRef(itemReference, item);\r
+                readJsonRef(jsonReference, param);\r
+                allParams.addProperties(param.getProperties());\r
+                allParams.addRequired(param.getRequired());\r
+                allParams.setType(param.getType());\r
             }\r
-            cJSON *itemRequiredValues = cJSON_GetObjectItem(allofValues, "required");\r
-            if (itemRequiredValues)\r
+            cJSON *jsonRequiredValues = cJSON_GetObjectItem(childAllOf, "required");\r
+            if (jsonRequiredValues)\r
             {\r
-                int len = cJSON_GetArraySize(itemRequiredValues);\r
+                int len = cJSON_GetArraySize(jsonRequiredValues);\r
                 int idx = 0;\r
                 do\r
                 {\r
-                    item->setRequiredValue(cJSON_GetArrayItem(itemRequiredValues, idx)->valuestring);\r
+                    allParams.addRequired(cJSON_GetArrayItem(jsonRequiredValues, idx)->valuestring);\r
                 }\r
                 while ( ++idx < len);\r
             }\r
index c52a145..a9fe422 100755 (executable)
 #include <vector>\r
 #include <map>\r
 #include "Properties.h"\r
-#include "Items.h"\r
 #include "Definitions.h"\r
 #include "cJSON.h"\r
-#include "Helpers.h"\r
-#include "AllowedValues.h"\r
 #include <memory>\r
 \r
 #include "IncludeResolver.h"\r
@@ -52,14 +49,15 @@ namespace RAML
             /**\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
@@ -68,7 +66,8 @@ namespace RAML
                   * @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
@@ -96,7 +95,7 @@ namespace RAML
                  *\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
@@ -110,7 +109,7 @@ namespace RAML
                  *\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
@@ -120,7 +119,7 @@ namespace RAML
                  *\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
@@ -252,46 +251,55 @@ namespace RAML
                 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 readInteger( cJSON *childProperties,  PropertiesPtr property);\r
-            void readDouble( 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
+\r
+            void readFile(std::string &fileName , JsonParameters &param);\r
+            void readFile(std::string &fileName , std::string &defName , JsonParameters &param);\r
+            void readRef(std::string ref , JsonParameters &param);\r
+            void readJsonRef(cJSON *jsonReference , JsonParameters &param);\r
+            void readAllOf(cJSON *allofValues ,  JsonParameters &allParams);\r
 \r
         private:\r
             std::map<std::string, PropertiesPtr > m_properties;\r
@@ -304,8 +312,9 @@ namespace RAML
             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
diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Properties.cpp b/service/simulator/ramlparser/raml/jsonSchemaParser/Properties.cpp
new file mode 100755 (executable)
index 0000000..bc29606
--- /dev/null
@@ -0,0 +1,410 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+/**\r
+ * @file   Properties.cpp\r
+ *\r
+ * @brief   This file provides data Model for Json Schema Properties.\r
+ */\r
+\r
+#include "Properties.h"\r
+#include <boost/lexical_cast.hpp>\r
+#include <boost/variant/static_visitor.hpp>\r
+#include "RamlExceptions.h"\r
+\r
+namespace RAML\r
+{\r
+    template <typename T>\r
+    struct TypeConverter {};\r
+\r
+    template <>\r
+    struct TypeConverter<int>\r
+    {\r
+        constexpr static VariantType type =\r
+            VariantType::INTEGER;\r
+    };\r
+\r
+    template <>\r
+    struct TypeConverter<double>\r
+    {\r
+        constexpr static VariantType type =\r
+            VariantType::DOUBLE;\r
+    };\r
+\r
+    template <>\r
+    struct TypeConverter<bool>\r
+    {\r
+        constexpr static VariantType type =\r
+            VariantType::BOOLEAN;\r
+    };\r
+\r
+    template <>\r
+    struct TypeConverter<std::string>\r
+    {\r
+        constexpr static VariantType type =\r
+            VariantType::STRING;\r
+    };\r
+\r
+    template <>\r
+    struct TypeConverter<Properties>\r
+    {\r
+        constexpr static VariantType type =\r
+            VariantType::PROPERTY;\r
+    };\r
+\r
+    template <typename T>\r
+    struct TypeDetails\r
+    {\r
+        constexpr static VariantType type =\r
+            TypeConverter<T>::type;\r
+        constexpr static VariantType baseType =\r
+            TypeConverter<T>::type;\r
+        constexpr static int depth = 0;\r
+    };\r
+\r
+    template <typename T>\r
+    struct TypeDetails<std::vector<T>>\r
+    {\r
+        constexpr static VariantType type =\r
+            VariantType::ARRAY;\r
+        constexpr static VariantType baseType =\r
+            TypeDetails<T>::baseType;\r
+        constexpr static int depth = 1 + TypeDetails<T>::depth;\r
+    };\r
+\r
+    class PropertyTypeVisitor : public boost::static_visitor<>\r
+    {\r
+        public:\r
+            PropertyTypeVisitor() : m_type(VariantType::UNKNOWN),\r
+                m_baseType(VariantType::UNKNOWN), m_depth(0) {}\r
+\r
+            template <typename T>\r
+            void operator ()(const T &)\r
+            {\r
+                m_type = TypeDetails<T>::type;\r
+                m_baseType = TypeDetails<T>::baseType;\r
+                m_depth = TypeDetails<T>::depth;\r
+            }\r
+\r
+            VariantType m_type;\r
+            VariantType m_baseType;\r
+            int m_depth;\r
+    };\r
+\r
+    Properties::TypeInfo Properties::getType() const\r
+    {\r
+        if (m_value)\r
+        {\r
+            RAML::PropertyTypeVisitor typeVisitor;\r
+            boost::apply_visitor(typeVisitor, *(m_value.get()));\r
+            Properties::TypeInfo typeInfo(typeVisitor.m_type, typeVisitor.m_baseType,\r
+                                          typeVisitor.m_depth);\r
+            return typeInfo;\r
+        }\r
+        else if (!m_typeString.empty()) //to read properties even if default value is not present\r
+        {\r
+            if (m_typeString == "string")\r
+                return Properties::TypeInfo(VariantType::STRING, VariantType::STRING, 0);\r
+            else if (m_typeString == "integer")\r
+                return Properties::TypeInfo(VariantType::INTEGER, VariantType::INTEGER, 0);\r
+            else if (m_typeString == "number")\r
+                return Properties::TypeInfo(VariantType::DOUBLE, VariantType::DOUBLE, 0);\r
+            else if (m_typeString == "boolean")\r
+                return Properties::TypeInfo(VariantType::BOOLEAN, VariantType::BOOLEAN, 0);\r
+        }\r
+        return Properties::TypeInfo();\r
+    }\r
+\r
+    void Properties::setTypeString(const std::string &type)\r
+    {\r
+        m_typeString = type;\r
+    }\r
+\r
+    Properties::TypeInfo::TypeInfo(\r
+        VariantType type = VariantType::UNKNOWN,\r
+        VariantType baseType = VariantType::UNKNOWN,\r
+        int depth = 0)\r
+        :   m_type (type), m_baseType(baseType), m_depth(depth) {}\r
+\r
+    VariantType Properties::TypeInfo::type() const\r
+    {\r
+        return m_type;\r
+    }\r
+\r
+    VariantType Properties::TypeInfo::baseType() const\r
+    {\r
+        return m_baseType;\r
+    }\r
+\r
+    int Properties::TypeInfo::depth() const\r
+    {\r
+        return m_depth;\r
+    }\r
+\r
+    bool Properties::TypeInfo::operator==(\r
+        const Properties::TypeInfo &rhs ) const\r
+    {\r
+        if (m_type == rhs.type() && m_baseType == rhs.baseType()\r
+            && m_depth == rhs.depth())\r
+            return true;\r
+        return false;\r
+    }\r
+\r
+    bool Properties::TypeInfo::operator!=(\r
+        const Properties::TypeInfo &rhs ) const\r
+    {\r
+        if (m_type != rhs.type() || m_baseType != rhs.baseType()\r
+            || m_depth != rhs.depth())\r
+            return true;\r
+        return false;\r
+    }\r
+\r
+    ValueVariant Properties::getValue() const\r
+    {\r
+        if (!isDefaultValue())\r
+            throw JsonException("Reading Empty Property Value");\r
+        return *m_value;\r
+    }\r
+\r
+    std::string Properties::getName() const\r
+    {\r
+        return m_name;\r
+    }\r
+\r
+    void Properties::setName(const std::string &name)\r
+    {\r
+        m_name = name;\r
+    }\r
+    std::string Properties::getDescription() const\r
+    {\r
+        return m_description;\r
+    }\r
+\r
+    void Properties::setDescription(const std::string &description)\r
+    {\r
+        m_description = description;\r
+    }\r
+    std::vector<std::shared_ptr<ValueProperty> > const &Properties::getValueProperties()\r
+    const\r
+    {\r
+        return m_valueProperty;\r
+    }\r
+    void Properties::setValueProperty(const std::shared_ptr<ValueProperty> &value)\r
+    {\r
+        m_valueProperty.push_back(value);\r
+    }\r
+    std::vector<std::string> const &Properties::getRequiredValues() const\r
+    {\r
+        return m_required;\r
+    }\r
+    void Properties::setRequiredValue(const std::string &reqValue)\r
+    {\r
+        auto it = m_required.begin();\r
+        for (; it != m_required.end(); ++it)\r
+        {\r
+            if (*it == reqValue)\r
+                break;\r
+        }\r
+        if (m_required.end() == it)\r
+        {\r
+            m_required.push_back(reqValue);\r
+        }\r
+    }\r
+    ValueProperty::ValueProperty()\r
+        :   m_type(ValueProperty::Type::UNKNOWN),\r
+            m_min(INT_MIN),\r
+            m_max(INT_MAX),\r
+            m_multipleOf(INT_MAX),\r
+            m_minItems(INT_MIN),\r
+            m_maxItems(INT_MAX),\r
+            m_unique(false),\r
+            m_additionalItems(false) {}\r
+\r
+    ValueProperty::ValueProperty(double min, double max, int multipleOf)\r
+        :   m_type(ValueProperty::Type::RANGE),\r
+            m_min(min),\r
+            m_max(max),\r
+            m_multipleOf(multipleOf),\r
+            m_minItems(INT_MIN),\r
+            m_maxItems(INT_MAX),\r
+            m_unique(false),\r
+            m_additionalItems(false) {}\r
+\r
+    ValueProperty::ValueProperty(\r
+        const std::vector<int> &valueSet)\r
+        :   m_type(ValueProperty::Type::VALUE_SET),\r
+            m_min(INT_MIN),\r
+            m_max(INT_MAX),\r
+            m_multipleOf(INT_MAX),\r
+            m_valueSet(valueSet.begin(), valueSet.end()),\r
+            m_minItems(INT_MIN),\r
+            m_maxItems(INT_MAX),\r
+            m_unique(false),\r
+            m_additionalItems(false)  {}\r
+\r
+    ValueProperty::ValueProperty(\r
+        const std::vector<double> &valueSet)\r
+        :   m_type(ValueProperty::Type::VALUE_SET),\r
+            m_min(INT_MIN),\r
+            m_max(INT_MAX),\r
+            m_multipleOf(INT_MAX),\r
+            m_valueSet(valueSet.begin(), valueSet.end()),\r
+            m_minItems(INT_MIN),\r
+            m_maxItems(INT_MAX),\r
+            m_unique(false),\r
+            m_additionalItems(false)  {}\r
+\r
+    ValueProperty::ValueProperty(\r
+        const std::vector<bool> &valueSet)\r
+        :   m_type(ValueProperty::Type::VALUE_SET),\r
+            m_min(INT_MIN),\r
+            m_max(INT_MAX),\r
+            m_multipleOf(INT_MAX),\r
+            m_valueSet(valueSet.begin(), valueSet.end()),\r
+            m_minItems(INT_MIN),\r
+            m_maxItems(INT_MAX),\r
+            m_unique(false),\r
+            m_additionalItems(false)  {}\r
+\r
+    ValueProperty::ValueProperty(\r
+        const std::vector<std::string> &valueSet)\r
+        :   m_type(ValueProperty::Type::VALUE_SET),\r
+            m_min(INT_MIN),\r
+            m_max(INT_MAX),\r
+            m_multipleOf(INT_MAX),\r
+            m_valueSet(valueSet.begin(), valueSet.end()),\r
+            m_minItems(INT_MIN),\r
+            m_maxItems(INT_MAX),\r
+            m_unique(false),\r
+            m_additionalItems(false)  {}\r
+\r
+    ValueProperty::ValueProperty(\r
+        const std::vector<ValueVariant> &valueSet)\r
+        :   m_type(ValueProperty::Type::VALUE_SET),\r
+            m_min(INT_MIN),\r
+            m_max(INT_MAX),\r
+            m_multipleOf(INT_MAX),\r
+            m_valueSet(valueSet.begin(), valueSet.end()),\r
+            m_minItems(INT_MIN),\r
+            m_maxItems(INT_MAX),\r
+            m_unique(false),\r
+            m_additionalItems(false)  {}\r
+\r
+    ValueProperty::ValueProperty(Type type, std::string value)\r
+        :   m_min(INT_MIN),\r
+            m_max(INT_MAX),\r
+            m_multipleOf(INT_MAX),\r
+            m_minItems(INT_MIN),\r
+            m_maxItems(INT_MAX),\r
+            m_unique(false),\r
+            m_additionalItems(false)\r
+    {\r
+        if (type == ValueProperty::Type::PATTERN)\r
+        {\r
+            m_type = ValueProperty::Type::PATTERN;\r
+            m_pattern = value;\r
+        }\r
+        else if (type == ValueProperty::Type::FORMAT)\r
+        {\r
+            m_type = ValueProperty::Type::FORMAT;\r
+            m_format = value;\r
+        }\r
+        else\r
+        {\r
+            m_type = ValueProperty::Type::UNKNOWN;\r
+        }\r
+    }\r
+\r
+    ValueProperty::ValueProperty(Type type, int minItems, int maxItems, bool unique,\r
+                                 bool additionalItems)\r
+        :   m_type(ValueProperty::Type::UNKNOWN),\r
+            m_min(INT_MIN),\r
+            m_max(INT_MAX),\r
+            m_multipleOf(INT_MAX),\r
+            m_minItems(INT_MIN),\r
+            m_maxItems(INT_MAX),\r
+            m_unique(false),\r
+            m_additionalItems(false)\r
+    {\r
+        if (type == ValueProperty::Type::ARRAY)\r
+        {\r
+            m_type = ValueProperty::Type::ARRAY;\r
+            m_minItems = minItems;\r
+            m_maxItems = maxItems;\r
+            m_unique = unique;\r
+            m_additionalItems = additionalItems;\r
+        }\r
+        else\r
+        {\r
+            m_type = ValueProperty::Type::UNKNOWN;\r
+        }\r
+    }\r
+\r
+    ValueProperty::Type ValueProperty::type() const\r
+    {\r
+        return m_type;\r
+    }\r
+\r
+    double ValueProperty::min() const\r
+    {\r
+        return m_min;\r
+    }\r
+\r
+    double ValueProperty::max() const\r
+    {\r
+        return m_max;\r
+    }\r
+\r
+    int ValueProperty::multipleOf() const\r
+    {\r
+        return m_multipleOf;\r
+    }\r
+\r
+    std::string ValueProperty::pattern() const\r
+    {\r
+        return m_pattern;\r
+    }\r
+\r
+    std::string ValueProperty::format() const\r
+    {\r
+        return m_format;\r
+    }\r
+\r
+    int ValueProperty::valueSetSize() const\r
+    {\r
+        return m_valueSet.size();\r
+    }\r
+\r
+    std::vector<ValueVariant> ValueProperty::valueSet() const\r
+    {\r
+        return m_valueSet;\r
+    }\r
+\r
+    void ValueProperty::valueArray(int &minItems, int &maxItems, bool &unique,\r
+                                   bool &additionalItems) const\r
+    {\r
+        minItems = m_minItems;\r
+        maxItems = m_maxItems;\r
+        unique = m_unique;\r
+        additionalItems = m_additionalItems;\r
+    }\r
+\r
+\r
+}\r
index c4dda1d..af2ae55 100755 (executable)
 #include <boost/variant.hpp>\r
 #include <boost/lexical_cast.hpp>\r
 #include <limits>\r
-#include "Items.h"\r
-#include "AllowedValues.h"\r
 #include "cJSON.h"\r
 #include <memory>\r
 \r
 namespace RAML\r
 {\r
+    class Properties;\r
+\r
+    /** ValueVariant - Boost Variant to hold type of property*/\r
+    typedef boost::variant <\r
+    int,\r
+    double,\r
+    bool,\r
+    std::string,\r
+    Properties,\r
+    std::vector<Properties>\r
+\r
+    > ValueVariant;\r
+\r
+    /** VariantType - enumeration for variant types*/\r
+    enum class VariantType\r
+    {\r
+        UNKNOWN,\r
+        INTEGER,\r
+        DOUBLE,\r
+        BOOLEAN,\r
+        STRING,\r
+        PROPERTY,\r
+        ARRAY\r
+    };\r
+    /**\r
+        * @class   ValueProperty\r
+        * @brief   This class provides data Model for Json Schema Value Property.\r
+        */\r
+    class ValueProperty\r
+    {\r
+        public:\r
+            /** Type - enumeration for ValueProperty types*/\r
+            enum class Type\r
+            {\r
+                UNKNOWN,\r
+                RANGE,\r
+                VALUE_SET,\r
+                PATTERN,\r
+                FORMAT,\r
+                ARRAY\r
+            };\r
+\r
+            /**\r
+                             * Constructor of ValueProperty.\r
+                             */\r
+            ValueProperty();\r
+            /**\r
+                             * Copy Constructor of ValueProperty.\r
+                             *\r
+                             * @param ValueProperty.\r
+                             */\r
+            ValueProperty(const ValueProperty &) = default;\r
+            /**\r
+                             * Assignment operator for  ValueProperty.\r
+                             *\r
+                             * @param ValueProperty.\r
+                             */\r
+            ValueProperty &operator=(const ValueProperty &) = default;\r
+            /**\r
+                             * Copy Constructor of ValueProperty.\r
+                             *\r
+                             * @param ValueProperty.\r
+                             */\r
+            ValueProperty(ValueProperty &&) = default;\r
+            /**\r
+                             * Assignment operator for  ValueProperty.\r
+                             *\r
+                             * @param ValueProperty.\r
+                             */\r
+            ValueProperty &operator=(ValueProperty &&) = default;\r
+\r
+            /**\r
+                             * explicit Constructor of ValueProperty for Type RANGE.\r
+                             *\r
+                             * @param min - minimum value of property.\r
+                             * @param max- maximum value of property.\r
+                             * @param multipleOf- multipleOf value of property.\r
+                             */\r
+            explicit ValueProperty(double min, double max, int multipleOf);\r
+            /**\r
+                             * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+                             *\r
+                             * @param valueSet - allowed values in the Properties.\r
+                             */\r
+            explicit ValueProperty(const std::vector<int> &valueSet);\r
+            /**\r
+                             * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+                             *\r
+                             * @param valueSet - allowed values in the Properties.\r
+                             */\r
+            explicit ValueProperty(const std::vector<double> &valueSet);\r
+            /**\r
+                             * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+                             *\r
+                             * @param valueSet - allowed values in the Properties.\r
+                             */\r
+            explicit ValueProperty(const std::vector<bool> &valueSet);\r
+            /**\r
+                             * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+                             *\r
+                             * @param valueSet - allowed values in the Properties.\r
+                             */\r
+            explicit ValueProperty(const std::vector<std::string> &valueSet);\r
+            /**\r
+                             * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+                             *\r
+                             * @param valueSet - allowed values in the Properties.\r
+                             */\r
+            explicit ValueProperty(const std::vector<ValueVariant> &valueSet);\r
+            /**\r
+                             * explicit Constructor of ValueProperty for Type PATTERN or FORMAT.\r
+                             *\r
+                             * @param type - ValueProperty Type.\r
+                             * @param value - value for the pattern or format.\r
+                             */\r
+            explicit ValueProperty(Type type, std::string value);\r
+            /**\r
+                             * explicit Constructor of ValueProperty for Type ARRAY.\r
+                             *\r
+                             * @param type - ValueProperty Type.\r
+                             * @param minItems - minimum elements in the Array property.\r
+                             * @param maxItems - maximum elements in the Array property.\r
+                             * @param unique - unique elements in the Array property.\r
+                             * @param additionalItems - additional elements in the Array property.\r
+                             */\r
+            explicit ValueProperty(Type type, int minItems, int maxItems, bool unique, bool additionalItems);\r
+\r
+            /**\r
+                             * This method is for getting type of ValueProperty.\r
+                             *\r
+                             * @return Type of ValueProperty\r
+                             */\r
+            Type type() const;\r
+            /**\r
+                             * This method is for getting minimum value of ValueProperty.\r
+                             *\r
+                             * @return min value of ValueProperty\r
+                             */\r
+            double min() const;\r
+            /**\r
+                             * This method is for getting maximum value of ValueProperty.\r
+                             *\r
+                             * @return max value of ValueProperty\r
+                             */\r
+            double max() const;\r
+            /**\r
+                             * This method is for getting multipleOf value of ValueProperty.\r
+                             *\r
+                             * @return multipleOf value of ValueProperty\r
+                             */\r
+            int multipleOf() const;\r
+            /**\r
+                             * This method is for getting pattern value of ValueProperty.\r
+                             *\r
+                             * @return pattern value of ValueProperty\r
+                             */\r
+            std::string pattern() const;\r
+            /**\r
+                             * This method is for getting format value of ValueProperty.\r
+                             *\r
+                             * @return format value of ValueProperty\r
+                             */\r
+            std::string format() const;\r
+            /**\r
+                             * This method is for getting valueSet of ValueProperty.\r
+                             *\r
+                             * @return valueSet of ValueProperty\r
+                             */\r
+            int valueSetSize() const;\r
+            /**\r
+                             * This method is for getting valueSet of ValueProperty.\r
+                             *\r
+                             * @return valueSet of ValueProperty\r
+                             */\r
+            std::vector<ValueVariant> valueSet() const;\r
+            /**\r
+                             * This method is for getting valueArray of ValueProperty.\r
+                             *\r
+                             * @param minItems - reference to get minimum elements in the Array property.\r
+                             * @param maxItems - reference to get maximum elements in the Array property.\r
+                             * @param unique - reference to get unique elements in the Array property.\r
+                             * @param additionalItems - reference to get additional elements in the Array property.\r
+                             */\r
+            void valueArray(int &minItems, int &maxItems, bool &unique, bool &additionalItems) const;\r
+\r
+        private:\r
+            Type m_type;\r
+            double m_min;\r
+            double m_max;\r
+            int m_multipleOf;\r
+            std::vector<ValueVariant> m_valueSet;\r
+            std::string m_pattern;\r
+            std::string m_format;\r
+            int m_minItems;\r
+            int m_maxItems;\r
+            bool m_unique;\r
+            bool m_additionalItems;\r
+    };\r
+\r
     /**\r
      * @class   Properties\r
      * @brief   This class provides data Model for Json Schema Properties.\r
@@ -48,420 +245,240 @@ namespace RAML
     {\r
         public:\r
             /**\r
-                  * Constructor of Properties.\r
-                  */\r
-            Properties(): m_min(INT_MAX), m_max(INT_MAX),\r
-                m_multipleOf(INT_MAX), m_unique(false), m_additionalItems(false) {}\r
+                 * @class   TypeInfo\r
+                 * @brief   This class provides type information of Json Properties.\r
+                 */\r
+            class TypeInfo\r
+            {\r
+                public:\r
+                    /**\r
+                                     * Constructor of TypeInfo.\r
+                                     *\r
+                                     * @param VariantType - type of property.\r
+                                     * @param VariantType - type of parent property.\r
+                                     * @param int - depth of property.\r
+                                     */\r
+                    TypeInfo(VariantType, VariantType, int);\r
+                    /**\r
+                                     * Copy Constructor of TypeInfo.\r
+                                     *\r
+                                     * @param TypeInfo.\r
+                                     */\r
+                    TypeInfo(const TypeInfo &) = default;\r
+                    /**\r
+                                     * Assignment operator for  TypeInfo.\r
+                                     *\r
+                                     * @param TypeInfo.\r
+                                     */\r
+                    TypeInfo &operator=(const TypeInfo &) = default;\r
+                    /**\r
+                                     * Copy Constructor of TypeInfo.\r
+                                     *\r
+                                     * @param TypeInfo.\r
+                                     */\r
+                    TypeInfo(TypeInfo &&) = default;\r
+                    /**\r
+                                     * Assignment operator for  TypeInfo.\r
+                                     *\r
+                                     * @param TypeInfo.\r
+                                     */\r
+                    TypeInfo &operator=(TypeInfo &&) = default;\r
+                    /**\r
+                                     * Constructor of TypeInfo.\r
+                                     */\r
+                    TypeInfo() = default;\r
+\r
+                    /**\r
+                                     * This method is for getting type of properties.\r
+                                     *\r
+                                     * @return VariantType of Property\r
+                                     */\r
+                    VariantType type() const;\r
+                    /**\r
+                                     * This method is for getting base or parent type of properties.\r
+                                     *\r
+                                     * @return VariantType of parent Property\r
+                                     */\r
+                    VariantType baseType() const;\r
+                    /**\r
+                                     * This method is for getting depth of properties.\r
+                                     *\r
+                                     * @return depth as int\r
+                                     */\r
+                    int depth() const;\r
+                    /**\r
+                                     *  operator for TypeInfo to check equality.\r
+                                     *\r
+                                     * @param TypeInfo.\r
+                                     */\r
+                    bool operator ==(const TypeInfo &) const;\r
+                    /**\r
+                                     *  operator for TypeInfo to check inequality.\r
+                                     *\r
+                                     * @param TypeInfo.\r
+                                     */\r
+                    bool operator !=(const TypeInfo &) const;\r
+\r
+                private:\r
+                    VariantType m_type;\r
+                    VariantType m_baseType;\r
+                    int m_depth;\r
+            };\r
 \r
             /**\r
                   * Constructor of Properties.\r
                   *\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),\r
-                m_unique(false), m_additionalItems(false) {}\r
-\r
-            /**\r
-                 * This method is for getting Name from Properties.\r
-                 *\r
-                 * @return Properties name as string\r
-                 */\r
-            inline std::string getName(void) const\r
-            {\r
-                return m_name;\r
-            }\r
-\r
-            /**\r
-                 * This method is for setting name to Properties\r
-                 *\r
-                 * @param name - Properties name as string.\r
-                 */\r
-            inline void setName(const std::string &name)\r
-            {\r
-                m_name = name;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting Value from Properties.\r
-                 *\r
-                 * @return Properties Value\r
-                 */\r
-            template <typename T>\r
-            T getValue() const\r
-            {\r
-                return boost::get<T>(m_value);\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting Value from Properties.\r
-                 *\r
-                 * @return Properties Value\r
-                 */\r
-            ValueVariant &getValue()\r
-            {\r
-                return m_value;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting ValueVariant type from Properties.\r
-                 *\r
-                 * @return Properties Value type as Int\r
-                 */\r
-            int getValueType() const\r
-            {\r
-                return m_value.which();\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting ValueVariant type from Properties.\r
-                 *\r
-                 * @return Properties VariantType type\r
-                 */\r
-            VariantType getVariantType() const\r
-            {\r
-                if (m_value.which() == 3)\r
-                    return VariantType::STRING;\r
-                else if (m_value.which() == 2)\r
-                    return VariantType::BOOL;\r
-                else if (m_value.which() == 1)\r
-                    return VariantType::DOUBLE;\r
-                else\r
-                    return VariantType::INT;\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting Value type as Integer from Properties.\r
-                 *\r
-                 * @return Properties Value type as Integer\r
-                 */\r
-            int getValueInt()\r
-            {\r
-                return boost::lexical_cast<int> (m_value);\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting Value type as String from Properties.\r
-                 *\r
-                 * @return Properties Value type as String\r
-                 */\r
-            std::string getValueString()\r
-            {\r
-                return boost::lexical_cast<std::string> (m_value);\r
-            }\r
-\r
+            Properties(const std::string &name) : m_name(name) {}\r
             /**\r
-                 * This method is for getting Value type as double from Properties.\r
-                 *\r
-                 * @return Properties Value type as double\r
-                 */\r
-            double getValueDouble()\r
-            {\r
-                return boost::lexical_cast<double> (m_value);\r
-            }\r
-\r
-            /**\r
-                 * This method is for getting Value type as bool from Properties.\r
-                 *\r
-                 * @return Properties Value type as bool\r
-                 */\r
-            bool getValueBool()\r
-            {\r
-                return boost::lexical_cast<bool> (m_value);\r
-            }\r
-\r
-            /**\r
-                 * This method is for setting Value to Properties\r
-                 *\r
-                 * @param value - Properties Value.\r
-                 */\r
-            template <typename T>\r
-            void setValue(const T &value)\r
-            {\r
-                m_value = value;\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 getRange(double &min, double &max, int &multipleOf) const\r
-            {\r
-                min = m_min;\r
-                max = m_max;\r
-                multipleOf = m_multipleOf;\r
-            }\r
-\r
-            /**\r
-                 * This method is for setting Minimum to Properties.\r
-                 *\r
-                 * @param min - Minimum value of Properties.\r
-                 */\r
-            inline void setMin(double min)\r
-            {\r
-                m_min = 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 setMax(double max)\r
-            {\r
-                m_max = max;\r
-            }\r
-            /**\r
-                 * This method is for setting multipleOf to Properties\r
-                 *\r
-                 * @param multipleOf - multipleOf value of Properties.\r
-                 */\r
-            inline void setMultipleOf(const int &multipleOf)\r
-            {\r
-                m_multipleOf = multipleOf;\r
-            }\r
-\r
+                  * Constructor of Properties.\r
+                  */\r
+            Properties() = default;\r
             /**\r
-                 * This method is for setting AllowedValues to Properties\r
-                 *\r
-                 * @param values - list of AllowedValues of Properties.\r
-                 */\r
-            template <typename T>\r
-            bool setAllowedValues(const std::vector<T> &values)\r
-            {\r
-                ValueVariant temp = values.at(0);\r
-                if (temp.which() != m_value.which())\r
-                {\r
-                    return false;\r
-                }\r
-\r
-                m_allowedValues.addValues(values);\r
-                return true;\r
-            }\r
-\r
+                     * Copy Constructor of Properties.\r
+                     *\r
+                     * @param Properties.\r
+                     */\r
+            Properties(const Properties &) = default;\r
             /**\r
-                 * This method is for getting size of AllowedValues from Properties.\r
-                 *\r
-                 * @return  size of AllowedValues\r
-                 */\r
-            inline int getAllowedValuesSize() const\r
-            {\r
-                return m_allowedValues.size();\r
-            }\r
-\r
+                     * Assignment operator for  Properties.\r
+                     *\r
+                     * @param Properties.\r
+                     */\r
+            Properties &operator=(const Properties &) = default;\r
             /**\r
-                 * This method is for getting AllowedValues from Properties.\r
-                 *\r
-                 * @return list of AllowedValues of Properties.\r
-                 */\r
-            inline std::vector<ValueVariant> getAllowedValues()\r
-            {\r
-                return m_allowedValues.getValues();\r
-            }\r
-\r
+                     * Copy Constructor of Properties.\r
+                     *\r
+                     * @param Properties.\r
+                     */\r
+            Properties(Properties &&) = default;\r
             /**\r
-                 * This method is for getting AllowedValues as integer from Properties.\r
-                 *\r
-                 * @return list of AllowedValues as integer\r
-                 */\r
-            inline std::vector<int> getAllowedValuesInt()\r
-            {\r
-                return m_allowedValues.getValuesInt();\r
-            }\r
+                     * Assignment operator for  Properties.\r
+                     *\r
+                     * @param Properties.\r
+                     */\r
+            Properties &operator=(Properties &&) = default;\r
 \r
             /**\r
-                 * This method is for getting AllowedValues as String from Properties.\r
+                 * This method is for getting TypeInfo of Properties.\r
                  *\r
-                 * @return list of AllowedValues as String\r
+                 * @return Properties TypeInfo\r
                  */\r
-            inline std::vector<std::string> getAllowedValuesString()\r
-            {\r
-                return m_allowedValues.getValuesString();\r
-            }\r
+            TypeInfo getType() const;\r
 \r
             /**\r
-                 * This method is for getting AllowedValues as Double from Properties.\r
+                 * This method is for setting type of Properties.\r
                  *\r
-                 * @return list of AllowedValues as Double\r
+                 * @param type -Propertie's Type\r
                  */\r
-            inline std::vector<double> getAllowedValuesDouble()\r
-            {\r
-                return m_allowedValues.getValuesDouble();\r
-            }\r
+            void setTypeString(const std::string &type);\r
 \r
             /**\r
-                 * This method is for getting AllowedValues as Bool from Properties.\r
+                 * This method is for getting Name from Properties.\r
                  *\r
-                 * @return list of AllowedValues as Bool\r
+                 * @return Properties name as string\r
                  */\r
-            inline std::vector<bool> getAllowedValuesBool()\r
-            {\r
-                return m_allowedValues.getValuesBool();\r
-            }\r
-\r
+            std::string getName() const;\r
             /**\r
-                 * This method is for setting Description to Properties\r
+                 * This method is for setting name to Properties\r
                  *\r
-                 * @param description - Description as string.\r
+                 * @param name - Properties name as string.\r
                  */\r
-            inline void setDescription(const std::string &description)\r
-            {\r
-                m_description = description;\r
-            }\r
-\r
+            void setName(const std::string &name);\r
             /**\r
                  * This method is for getting Description from Properties.\r
                  *\r
                  * @return Description as string\r
                  */\r
-            inline std::string getDescription()\r
-            {\r
-                return m_description;\r
-            }\r
+            std::string getDescription() const;\r
 \r
             /**\r
-                 * This method is for setting Type to Properties\r
+                 * This method is for setting Description to Properties\r
                  *\r
-                 * @param type - Type as string.\r
+                 * @param description - Description as string.\r
                  */\r
-            void setType(const std::string &type)\r
-            {\r
-                m_type = type;\r
-            }\r
+            void setDescription(const std::string &description);\r
 \r
             /**\r
-                 * This method is for getting Type from Properties.\r
+                 * This method is for setting Value to Properties.\r
                  *\r
-                 * @return Type as string\r
+                 * @param value -  Value of Properties\r
                  */\r
-            std::string getType()\r
+            template <typename T>\r
+            void setValue(const T &value)\r
             {\r
-                return m_type;\r
+                m_value = std::make_shared<ValueVariant>(value);\r
             }\r
 \r
             /**\r
-                 * This method is for setting Pattern to Properties\r
+                 * This method is for getting Value from Properties.\r
                  *\r
-                 * @param pattern - Pattern as string.\r
+                 * @return Properties Value\r
                  */\r
-            void setPattern(const std::string &pattern)\r
-            {\r
-                m_pattern = pattern;\r
-            }\r
-\r
+            ValueVariant getValue() const;\r
 \r
             /**\r
-                 * This method is for getting Pattern from Properties.\r
+                 * This method is for getting Value from Properties.\r
                  *\r
-                 * @return Pattern as string\r
+                 * @return Properties Value\r
                  */\r
-            std::string getPattern()\r
+            template <typename T>\r
+            T getValue() const\r
             {\r
-                return m_pattern;\r
+                return boost::get<T>(m_value);\r
             }\r
 \r
             /**\r
-                 * This method is for setting Format to Properties\r
+                 * This method is for checking if default Value exists in the Properties.\r
                  *\r
-                 * @param format - Format as string.\r
+                 * @return true if present and false if not present\r
                  */\r
-            void setFormat(const std::string &format)\r
-            {\r
-                m_format = format;\r
-            }\r
-\r
+            bool isDefaultValue() const { return ((m_value != nullptr) ? true : false); }\r
             /**\r
-                 * This method is for getting Format from Properties.\r
+                 * This method is for getting ValueProperty from Properties.\r
                  *\r
-                 * @return Format as string\r
+                 * @return vector of pointer to ValueProperty\r
                  */\r
-            std::string getFormat()\r
-            {\r
-                return m_format;\r
-            }\r
+            std::vector<std::shared_ptr<ValueProperty> > const &getValueProperties() const;\r
 \r
             /**\r
-                 * This method is for setting Items to Properties\r
+                 * This method is for setting ValueProperty to Properties\r
                  *\r
-                 * @param item - pointer to Items\r
+                 * @param value - pointer to ValueProperty\r
                  */\r
-            void setItem(const ItemsPtr &item)\r
-            {\r
-                m_items.push_back(item);\r
-            }\r
+            void setValueProperty(const std::shared_ptr<ValueProperty> &value);\r
 \r
-            /**\r
-                 * This method is for getting Items from Properties.\r
-                 *\r
-                 * @return list of pointer to Items\r
-                 */\r
-            std::vector<ItemsPtr> const &getItems() const\r
-            {\r
-                return m_items;\r
-            }\r
 \r
             /**\r
-                 * This method is for setting Unique to Properties\r
+                 * This method is for getting RequiredValue from Properties.\r
                  *\r
-                 * @param value - Unique as bool\r
+                 * @return list of RequiredValue as string\r
                  */\r
-            void setUnique( int value)\r
-            {\r
-                if (value == cJSON_True) m_unique = true;\r
-                else m_unique = false;\r
-            }\r
+            std::vector<std::string> const &getRequiredValues() const;\r
 \r
             /**\r
-                 * This method is for getting isUnique from Properties.\r
+                 * This method is for setting RequiredValue to Properties\r
                  *\r
-                 * @return isUnique as bool\r
+                 * @param reqValue - RequiredValue as string.\r
                  */\r
-            bool getUnique()\r
-            {\r
-                return m_unique;\r
-            }\r
-\r
-            /**\r
-                 * This method is for setting AdditionalItems to Properties\r
-                 *\r
-                 * @param value - AdditionalItems as bool\r
-                 */\r
-            void setAdditionalItems(int value)\r
-            {\r
-                if (value == cJSON_True) m_additionalItems = true;\r
-                else m_additionalItems = false;\r
-            }\r
+            void setRequiredValue(const std::string &reqValue);\r
 \r
-            /**\r
-                 * This method is for getting AdditionalItems from Properties.\r
-                 *\r
-                 * @return AdditionalItems as bool\r
-                 */\r
-            bool getAdditionalItems()\r
-            {\r
-                return m_additionalItems;\r
-            }\r
         private:\r
+            TypeInfo m_type;\r
+            std::string m_typeString;\r
             std::string m_name;\r
-            ValueVariant m_value;\r
-            double m_min;\r
-            double m_max;\r
-            int m_multipleOf;\r
-            AllowedValues m_allowedValues;\r
-            std::string m_type;\r
-            std::string m_pattern;\r
-            std::string m_format;\r
             std::string m_description;\r
-            bool m_unique;\r
-            bool m_additionalItems;\r
-            std::vector<ItemsPtr > m_items;\r
+            std::shared_ptr<ValueVariant> m_value;\r
+            std::vector<std::shared_ptr<ValueProperty> > m_valueProperty;\r
+            std::vector<std::string> m_required;\r
     };\r
 \r
     /** PropertiesPtr - shared Ptr to Properties.*/\r
     typedef std::shared_ptr<Properties> PropertiesPtr;\r
 \r
+    /** ValuePropertyPtr - shared Ptr to ValueProperty.*/\r
+    typedef std::shared_ptr<ValueProperty> ValuePropertyPtr;\r
+\r
 }\r
 #endif\r
index b181433..67f2f3e 100755 (executable)
@@ -107,6 +107,158 @@ ResponseModelSP RequestModelBuilder::createResponseModel(int code,
     responseModel->setRepSchema(repSchema);
     return responseModel;
 }
+template <typename T>
+void RequestModelBuilder::buildValueProperty(SimulatorResourceModel::Attribute &attribute,
+        const std::vector<RAML::ValuePropertyPtr> &valueProperties, T)
+{
+    for (auto &vp : valueProperties)
+    {
+        switch (vp->type())
+        {
+            case RAML::ValueProperty::Type::RANGE :
+                {
+                    double min = vp->min();
+                    double max = vp->max();
+                    int multipleof = vp->multipleOf();
+                    if (min != INT_MIN && max != INT_MAX)
+                    {
+                        SimulatorResourceModel::AttributeProperty attrProp(min, max);
+                        attribute.setProperty(attrProp);
+                    }
+                    break;
+                }
+            case RAML::ValueProperty::Type::VALUE_SET :
+                {
+                    std::vector<T> allowedValues;
+                    for (auto allow : vp->valueSet())
+                        allowedValues.push_back(boost::get<T>(allow));
+                    SimulatorResourceModel::AttributeProperty attrProp(allowedValues);
+                    attribute.setProperty(attrProp);
+                    break;
+                }
+            default:
+                break;
+        }
+    }
+
+}
+SimulatorResourceModel::Attribute RequestModelBuilder::buildAttribute(
+    std::shared_ptr<RAML::Properties> propertyElement)
+{
+    std::string propName = propertyElement->getName();
+
+    // Build representation attribute
+    SimulatorResourceModel::Attribute attribute(propName);
+    switch (propertyElement->getType().type())
+    {
+        case RAML::VariantType::INTEGER:
+            {
+                int attributeValue = 0;
+                if (propertyElement->isDefaultValue())
+                    attributeValue = boost::get<int>(propertyElement->getValue());
+                attribute.setValue(attributeValue);
+                int type = 0;
+                buildValueProperty(attribute, (propertyElement->getValueProperties()), type);
+            }
+            break;
+
+        case RAML::VariantType::DOUBLE:
+            {
+                double attributeValue = 0;
+                if (propertyElement->isDefaultValue())
+                    attributeValue = boost::get<double>(propertyElement->getValue());
+                attribute.setValue(attributeValue);
+                double type = 0;
+                buildValueProperty(attribute, (propertyElement->getValueProperties()), type);
+            }
+            break;
+
+        case RAML::VariantType::BOOLEAN:
+            {
+                bool attributeValue = false;
+                if (propertyElement->isDefaultValue())
+                    attributeValue = boost::get<bool>(propertyElement->getValue());
+                attribute.setValue(attributeValue);
+                bool type = false;
+                buildValueProperty(attribute, (propertyElement->getValueProperties()), type);
+            }
+            break;
+
+        case RAML::VariantType::STRING:
+            {
+                std::string attributeValue = "";
+                if (propertyElement->isDefaultValue())
+                    attributeValue = boost::get<std::string>(propertyElement->getValue());
+                attribute.setValue(attributeValue);
+                std::string type = "";
+                buildValueProperty(attribute, (propertyElement->getValueProperties()), type);
+            }
+            break;
+        case RAML::VariantType::PROPERTY:
+            {
+                RAML::Properties arrayProperty = boost::get<RAML::Properties>(propertyElement->getValue());
+                SimulatorResourceModel::Attribute arrayAttribute = buildAttribute(
+                            std::make_shared<RAML::Properties>(arrayProperty));
+
+                switch (arrayAttribute.getType().type())
+                {
+                    case SimulatorResourceModel::ValueType::INTEGER :
+                        {
+                            std::vector<int> arrValue;
+                            arrValue.push_back(boost::get<int>(arrayAttribute.getValue()));
+                            attribute.setValue(arrValue);
+                            int type;
+                            buildValueProperty(attribute, (arrayProperty.getValueProperties()), type);
+                            break;
+                        }
+                    case SimulatorResourceModel::ValueType::DOUBLE :
+                        {
+                            std::vector<double> arrValue;
+                            arrValue.push_back(boost::get<double>(arrayAttribute.getValue()));
+                            attribute.setValue(arrValue);
+                            double type;
+                            buildValueProperty(attribute, (arrayProperty.getValueProperties()), type);
+                            break;
+                        }
+                    case SimulatorResourceModel::ValueType::BOOLEAN :
+                        {
+                            std::vector<bool> arrValue;
+                            arrValue.push_back(boost::get<bool>(arrayAttribute.getValue()));
+                            attribute.setValue(arrValue);
+                            bool type;
+                            buildValueProperty(attribute, (arrayProperty.getValueProperties()), type);
+                            break;
+                        }
+                    case SimulatorResourceModel::ValueType::STRING :
+                        {
+                            std::vector<std::string> arrValue;
+                            arrValue.push_back(boost::get<std::string>(arrayAttribute.getValue()));
+                            attribute.setValue(arrValue);
+                            std::string type;
+                            buildValueProperty(attribute, (arrayProperty.getValueProperties()), type);
+                            break;
+                        }
+                }
+            }
+            break;
+        case RAML::VariantType::ARRAY:
+            {
+
+                std::vector<SimulatorResourceModel> arrayResModel;
+                SimulatorResourceModel arrayItem;
+                std::vector<RAML::Properties> arrayProperty = boost::get<std::vector<RAML::Properties> >
+                        (propertyElement->getValue());
+                for (auto val : arrayProperty)
+                {
+                    arrayItem.add(buildAttribute(std::make_shared<RAML::Properties>(val)));
+                }
+                arrayResModel.push_back(arrayItem);
+                attribute.setValue(arrayResModel);
+            }
+            break;
+    }
+    return attribute;
+}
 
 SimulatorResourceModelSP RequestModelBuilder::createRepSchema(const RAML::RequestResponseBodyPtr
         &rep)
@@ -134,79 +286,7 @@ SimulatorResourceModelSP RequestModelBuilder::createRepSchema(const RAML::Reques
             || "p" == propName || "n" == propName || "id" == propName)
             continue;
 
-        int valueType = propertyEntry.second->getValueType();
-        switch (valueType)
-        {
-            case 0: // Integer
-                {
-                    // Add the attribute with value
-                    repSchema->add(propertyEntry.second->getName(), propertyEntry.second->getValue<int>());
-
-                    // Convert supported values
-                    std::vector<int> allowedValues = propertyEntry.second->getAllowedValuesInt();
-                    if (allowedValues.size() > 0)
-                    {
-                        SimulatorResourceModel::AttributeProperty attrProp(allowedValues);
-                        repSchema->setAttributeProperty(propName, attrProp);
-                    }
-                }
-                break;
-
-            case 1: // Double
-                {
-                    // Add the attribute with value
-                    repSchema->add(propertyEntry.second->getName(), propertyEntry.second->getValue<double>());
-
-                    // Convert suppoted values
-                    std::vector<double> allowedValues = propertyEntry.second->getAllowedValuesDouble();
-                    if (allowedValues.size() > 0)
-                    {
-                        SimulatorResourceModel::AttributeProperty attrProp(allowedValues);
-                        repSchema->setAttributeProperty(propName, attrProp);
-                    }
-                }
-                break;
-
-            case 2: // Boolean
-                {
-                    // Add the attribute with value
-                    repSchema->add(propertyEntry.second->getName(), propertyEntry.second->getValue<bool>());
-                    // Convert supported values
-                    std::vector<bool> allowedValues = propertyEntry.second->getAllowedValuesBool();
-                    if (allowedValues.size() > 0)
-                    {
-                        SimulatorResourceModel::AttributeProperty attrProp(allowedValues);
-                        repSchema->setAttributeProperty(propName, attrProp);
-                    }
-                }
-                break;
-
-            case 3: // String
-                {
-                    // Add the attribute with value
-                    repSchema->add(propertyEntry.second->getName(),
-                                   propertyEntry.second->getValue<std::string>());
-
-                    // Convert suppored values
-                    std::vector<std::string> allowedValues = propertyEntry.second->getAllowedValuesString();
-                    if (allowedValues.size() > 0)
-                    {
-                        SimulatorResourceModel::AttributeProperty attrProp(allowedValues);
-                        repSchema->setAttributeProperty(propName, attrProp);
-                    }
-                }
-                break;
-        }
-
-        // Set the range property if its present
-        double min, max;
-        int multipleof;
-        propertyEntry.second->getRange(min, max, multipleof);
-        if (min != INT_MIN && max != INT_MAX)
-        {
-            SimulatorResourceModel::AttributeProperty attrProp(min, max);
-            repSchema->setAttributeProperty(propName, attrProp);
-        }
+        repSchema->add(buildAttribute(propertyEntry.second));
     }
 
     return repSchema;
old mode 100644 (file)
new mode 100755 (executable)
index f212252..de4baf1
@@ -35,6 +35,11 @@ class RequestModelBuilder
         ResponseModelSP createResponseModel(int code, const RAML::ResponsePtr &response);
         SimulatorResourceModelSP createRepSchema(const RAML::RequestResponseBodyPtr &rep);
         RequestType getRequestType(RAML::ActionType actionType);
+        SimulatorResourceModel::Attribute buildAttribute(
+            std::shared_ptr<RAML::Properties> propertyElement);
+        template <typename T>
+        void buildValueProperty(SimulatorResourceModel::Attribute &attribute,
+                                const std::vector<RAML::ValuePropertyPtr> &valueProperties, T);
 
         std::shared_ptr<RAML::Raml> m_raml;
 };
old mode 100644 (file)
new mode 100755 (executable)
index 321d425..709f049
@@ -103,7 +103,41 @@ std::shared_ptr<SimulatorCollectionResource> SimulatorResourceFactory::createCol
     collectionResource->setResourceType(resourceType);\r
     return std::shared_ptr<SimulatorCollectionResource>(collectionResource);\r
 }\r
+template <typename T>\r
+void SimulatorResourceFactory::buildValueProperty(SimulatorResourceModel::Attribute &attribute,\r
+        const std::vector<RAML::ValuePropertyPtr> &valueProperties, T)\r
+{\r
+    for (auto &vp : valueProperties)\r
+    {\r
+        switch (vp->type())\r
+        {\r
+            case RAML::ValueProperty::Type::RANGE :\r
+                {\r
+                    double min = vp->min();\r
+                    double max = vp->max();\r
+                    int multipleof = vp->multipleOf();\r
+                    if (min != INT_MIN && max != INT_MAX)\r
+                    {\r
+                        SimulatorResourceModel::AttributeProperty attrProp(min, max);\r
+                        attribute.setProperty(attrProp);\r
+                    }\r
+                    break;\r
+                }\r
+            case RAML::ValueProperty::Type::VALUE_SET :\r
+                {\r
+                    std::vector<T> allowedValues;\r
+                    for (auto allow : vp->valueSet())\r
+                        allowedValues.push_back(boost::get<T>(allow));\r
+                    SimulatorResourceModel::AttributeProperty attrProp(allowedValues);\r
+                    attribute.setProperty(attrProp);\r
+                    break;\r
+                }\r
+            default:\r
+                break;\r
+        }\r
+    }\r
 \r
+}\r
 SimulatorResourceModel::Attribute SimulatorResourceFactory::buildAttribute(\r
     std::shared_ptr<RAML::Properties> propertyElement)\r
 {\r
@@ -111,103 +145,115 @@ SimulatorResourceModel::Attribute SimulatorResourceFactory::buildAttribute(
 \r
     // Build representation attribute\r
     SimulatorResourceModel::Attribute attribute(propName);\r
-    switch (propertyElement->getVariantType())\r
+    switch (propertyElement->getType().type())\r
     {\r
-        case RAML::VariantType::INT:\r
+        case RAML::VariantType::INTEGER:\r
             {\r
-                attribute.setValue(propertyElement->getValue<int>());\r
-\r
-                // Convert suppoted values\r
-                std::vector<int> allowedValues = propertyElement->getAllowedValuesInt();\r
-                if (allowedValues.size() > 0)\r
-                {\r
-                    SimulatorResourceModel::AttributeProperty attrProp(allowedValues);\r
-                    attribute.setProperty(attrProp);\r
-                }\r
+                int attributeValue = 0;\r
+                if (propertyElement->isDefaultValue())\r
+                    attributeValue = boost::get<int>(propertyElement->getValue());\r
+                attribute.setValue(attributeValue);\r
+                int type = 0;\r
+                buildValueProperty(attribute, (propertyElement->getValueProperties()), type);\r
             }\r
             break;\r
 \r
         case RAML::VariantType::DOUBLE:\r
             {\r
-                attribute.setValue(propertyElement->getValue<double>());\r
-\r
-                // Convert suppoted values\r
-                std::vector<double> allowedValues = propertyElement->getAllowedValuesDouble();\r
-                if (allowedValues.size() > 0)\r
-                {\r
-                    SimulatorResourceModel::AttributeProperty attrProp(allowedValues);\r
-                    attribute.setProperty(attrProp);\r
-                }\r
+                double attributeValue = 0;\r
+                if (propertyElement->isDefaultValue())\r
+                    attributeValue = boost::get<double>(propertyElement->getValue());\r
+                attribute.setValue(attributeValue);\r
+                double type = 0;\r
+                buildValueProperty(attribute, (propertyElement->getValueProperties()), type);\r
             }\r
             break;\r
 \r
-        case RAML::VariantType::BOOL:\r
+        case RAML::VariantType::BOOLEAN:\r
             {\r
-                attribute.setValue(propertyElement->getValue<bool>());\r
-\r
-                std::vector<bool> allowedValues = {true, false};\r
-                SimulatorResourceModel::AttributeProperty attrProp(allowedValues);\r
-                attribute.setProperty(attrProp);\r
+                bool attributeValue = false;\r
+                if (propertyElement->isDefaultValue())\r
+                    attributeValue = boost::get<bool>(propertyElement->getValue());\r
+                attribute.setValue(attributeValue);\r
+                bool type = false;\r
+                buildValueProperty(attribute, (propertyElement->getValueProperties()), type);\r
             }\r
             break;\r
 \r
         case RAML::VariantType::STRING:\r
             {\r
-                attribute.setValue(propertyElement->getValue<std::string>());\r
+                std::string attributeValue = "";\r
+                if (propertyElement->isDefaultValue())\r
+                    attributeValue = boost::get<std::string>(propertyElement->getValue());\r
+                attribute.setValue(attributeValue);\r
+                std::string type = "";\r
+                buildValueProperty(attribute, (propertyElement->getValueProperties()), type);\r
+            }\r
+            break;\r
+        case RAML::VariantType::PROPERTY:\r
+            {\r
+                RAML::Properties arrayProperty = boost::get<RAML::Properties>(propertyElement->getValue());\r
+                SimulatorResourceModel::Attribute arrayAttribute = buildAttribute(\r
+                            std::make_shared<RAML::Properties>(arrayProperty));\r
 \r
-                // Convert suppoted values\r
-                std::vector<std::string> allowedValues = propertyElement->getAllowedValuesString();\r
-                if (allowedValues.size() > 0)\r
+                switch (arrayAttribute.getType().type())\r
                 {\r
-                    SimulatorResourceModel::AttributeProperty attrProp(allowedValues);\r
-                    attribute.setProperty(attrProp);\r
+                    case SimulatorResourceModel::ValueType::INTEGER :\r
+                        {\r
+                            std::vector<int> arrValue;\r
+                            arrValue.push_back(boost::get<int>(arrayAttribute.getValue()));\r
+                            attribute.setValue(arrValue);\r
+                            int type;\r
+                            buildValueProperty(attribute, (arrayProperty.getValueProperties()), type);\r
+                            break;\r
+                        }\r
+                    case SimulatorResourceModel::ValueType::DOUBLE :\r
+                        {\r
+                            std::vector<double> arrValue;\r
+                            arrValue.push_back(boost::get<double>(arrayAttribute.getValue()));\r
+                            attribute.setValue(arrValue);\r
+                            double type;\r
+                            buildValueProperty(attribute, (arrayProperty.getValueProperties()), type);\r
+                            break;\r
+                        }\r
+                    case SimulatorResourceModel::ValueType::BOOLEAN :\r
+                        {\r
+                            std::vector<bool> arrValue;\r
+                            arrValue.push_back(boost::get<bool>(arrayAttribute.getValue()));\r
+                            attribute.setValue(arrValue);\r
+                            bool type;\r
+                            buildValueProperty(attribute, (arrayProperty.getValueProperties()), type);\r
+                            break;\r
+                        }\r
+                    case SimulatorResourceModel::ValueType::STRING :\r
+                        {\r
+                            std::vector<std::string> arrValue;\r
+                            arrValue.push_back(boost::get<std::string>(arrayAttribute.getValue()));\r
+                            attribute.setValue(arrValue);\r
+                            std::string type;\r
+                            buildValueProperty(attribute, (arrayProperty.getValueProperties()), type);\r
+                            break;\r
+                        }\r
                 }\r
             }\r
             break;\r
-    }\r
-\r
-    // Set the range property if its present\r
-    double min, max;\r
-    int multipleof;\r
-    propertyElement->getRange(min, max, multipleof);\r
-    if (min != INT_MIN && max != INT_MAX)\r
-    {\r
-        SimulatorResourceModel::AttributeProperty attrProp(min, max);\r
-        attribute.setProperty(attrProp);\r
-    }\r
-    return attribute;\r
-}\r
-\r
-SimulatorResourceModel SimulatorResourceFactory::buildResourceModel(\r
-    std::shared_ptr<RAML::Items> item)\r
-{\r
-    SimulatorResourceModel itemModel;\r
-    for ( auto &propElement : item->getProperties())\r
-    {\r
-        if (!propElement.second)\r
-            continue;\r
-\r
-        std::string propName = propElement.second->getName();\r
-        if ("p" == propName || "n" == propName || "id" == propName)\r
-        {\r
-            continue;\r
-        }\r
-\r
-        if ("array" == propElement.second->getType())\r
-        {\r
-            std::vector<SimulatorResourceModel> arrayResModel;\r
-            for ( auto &propertyItem : propElement.second->getItems())\r
+        case RAML::VariantType::ARRAY:\r
             {\r
-                arrayResModel.push_back(buildResourceModel(propertyItem));\r
+\r
+                std::vector<SimulatorResourceModel> arrayResModel;\r
+                SimulatorResourceModel arrayItem;\r
+                std::vector<RAML::Properties> arrayProperty = boost::get<std::vector<RAML::Properties> >\r
+                        (propertyElement->getValue());\r
+                for (auto val : arrayProperty)\r
+                {\r
+                    arrayItem.add(buildAttribute(std::make_shared<RAML::Properties>(val)));\r
+                }\r
+                arrayResModel.push_back(arrayItem);\r
+                attribute.setValue(arrayResModel);\r
             }\r
-            itemModel.add(propName, arrayResModel);\r
-        }\r
-        else\r
-        {\r
-            itemModel.add(buildAttribute(propElement.second));\r
-        }\r
+            break;\r
     }\r
-    return itemModel;\r
+    return attribute;\r
 }\r
 \r
 RAML::RequestResponseBodyPtr SimulatorResourceFactory::getRAMLResponseBody(\r
@@ -261,25 +307,27 @@ SimulatorResourceModel SimulatorResourceFactory::buildModelFromResponseBody(
         // Resource type\r
         if ("rt" == propName || "resourceType" == propName)\r
         {\r
-            resourceType = propertyElement.second->getValueString();\r
+            resourceType = boost::get<std::string>(propertyElement.second->getValue());\r
             continue;\r
         }\r
 \r
+        // TODO: Is "if" required to be part of resource representation?\r
         // Interface type\r
         if ("if" == propName)\r
         {\r
-            if ("string" == propertyElement.second->getType())\r
+            if (RAML::VariantType::STRING == propertyElement.second->getType().type())\r
             {\r
-                interfaceType.push_back(propertyElement.second->getValueString());\r
+                interfaceType.push_back(boost::get<std::string>(propertyElement.second->getValue()));\r
             }\r
-            else if ("array" == propertyElement.second->getType())\r
+            else if (RAML::VariantType::ARRAY == propertyElement.second->getType().type())\r
             {\r
-                for (auto &item : propertyElement.second->getItems())\r
+                RAML::Properties ifProperty = boost::get<RAML::Properties>(propertyElement.second->getValue());\r
+                for (auto vp : ifProperty.getValueProperties())\r
                 {\r
-                    if ("string" == item->getType())\r
+                    if (vp->type() == RAML::ValueProperty::Type::VALUE_SET)\r
                     {\r
-                        interfaceType = item->getAllowedValuesString();\r
-                        break;\r
+                        for (auto allow : vp->valueSet())\r
+                            interfaceType.push_back(boost::get<std::string>(allow));\r
                     }\r
                 }\r
             }\r
@@ -292,30 +340,7 @@ SimulatorResourceModel SimulatorResourceFactory::buildModelFromResponseBody(
             continue;\r
         }\r
 \r
-        // Add the attribute to resource model\r
-        if ("array" == propertyElement.second->getType())\r
-        {\r
-            std::vector<SimulatorResourceModel> arrayResModel;\r
-            for ( auto &propertyItem : propertyElement.second->getItems())\r
-            {\r
-                arrayResModel.push_back(buildResourceModel(propertyItem));\r
-            }\r
-            resModel.add(propName, arrayResModel);\r
-        }\r
-        else\r
-        {\r
-            resModel.add(buildAttribute(propertyElement.second));\r
-        }\r
-    }\r
-\r
-    if ("array" == resourceProperties->getType())\r
-    {\r
-        std::vector<SimulatorResourceModel> arrayResModel;\r
-        for ( auto &propertyItem : resourceProperties->getItems())\r
-        {\r
-            arrayResModel.push_back(buildResourceModel(propertyItem));\r
-        }\r
-        resModel.add("links", arrayResModel);\r
+        resModel.add(buildAttribute(propertyElement.second));\r
     }\r
 \r
     return resModel;\r
index 84ff428..d79d849 100755 (executable)
@@ -29,7 +29,8 @@ namespace RAML
 {
     class RamlResource;
     class Properties;
-    class Items;
+    class JsonSchema;
+    class RamlParser;
 }
 
 class SimulatorResourceFactory
@@ -87,9 +88,11 @@ class SimulatorResourceFactory
             const std::string &name, const std::string &uri, const std::string &resourceType);
 
     private:
+        template <typename T>
+        void buildValueProperty(SimulatorResourceModel::Attribute &attribute,
+                                const std::vector<RAML::ValuePropertyPtr> &valueProperties, T);
         SimulatorResourceModel::Attribute buildAttribute(
             std::shared_ptr<RAML::Properties> propertyElement);
-        SimulatorResourceModel buildResourceModel(std::shared_ptr<RAML::Items> item);
         SimulatorResourceModel buildModelFromResponseBody(
             RAML::RequestResponseBodyPtr responseBody, std::string &resourceType,
             std::vector<std::string> &interfaceType);