From: Abitha Shankar Date: Fri, 18 Sep 2015 07:14:43 +0000 (+0530) Subject: Adding Raml and JsonSchema Parser changes for X-Git-Tag: 1.0.0-RC1~9^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=30b2db59da6a03ee44cfc6e218278f8d3c6ff53e;p=contrib%2Fiotivity.git Adding Raml and JsonSchema Parser changes for 1. Doxygen comments. 2. Klocwork fixes. 3 prevent issue fixes. 4. added smart pointer implemetation for JsonSchema Parser. Change-Id: I8a6ff026fb9b03932ab7c15a19631143e0c653fa Signed-off-by: Abitha Shankar Reviewed-on: https://gerrit.iotivity.org/gerrit/2563 Reviewed-by: Madan Lanka Tested-by: Madan Lanka --- diff --git a/service/simulator/ramlparser/SConscript b/service/simulator/ramlparser/SConscript index 0a4aa6e..38fe308 100755 --- a/service/simulator/ramlparser/SConscript +++ b/service/simulator/ramlparser/SConscript @@ -1,6 +1,6 @@ #****************************************************************** # -# Copyright 2014 Samsung Electronics All Rights Reserved. +# Copyright 2015 Samsung Electronics All Rights Reserved. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # diff --git a/service/simulator/ramlparser/example/SConscript b/service/simulator/ramlparser/example/SConscript index f26a3c4..41ee9a0 100755 --- a/service/simulator/ramlparser/example/SConscript +++ b/service/simulator/ramlparser/example/SConscript @@ -1,3 +1,22 @@ +#****************************************************************** +# +# Copyright 2015 Samsung Electronics All Rights Reserved. +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= import os Import('env') lib_env = env.Clone() diff --git a/service/simulator/ramlparser/example/raml_parser.cpp b/service/simulator/ramlparser/example/raml_parser.cpp index 9ff56f7..2ebc47f 100755 --- a/service/simulator/ramlparser/example/raml_parser.cpp +++ b/service/simulator/ramlparser/example/raml_parser.cpp @@ -1,6 +1,27 @@ +/****************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + #include "RamlParser.h" #include #include +#include //#define PRINT_PARAMS //#define PRINT_PROTOCOLS @@ -207,7 +228,7 @@ void printResource(const RamlResourcePtr &resource) } } -void printProperties(Properties *prop) +void printProperties(const PropertiesPtr &prop) { #ifdef PRINT_JSON_PROPERTIES std::cout << "-------------------------------" << std::endl; @@ -304,108 +325,115 @@ int main(int argc, char *argv[]) char *value = argv[1]; std::string s(value); - RamlParser *ramlParser = new RamlParser(s); - RamlPtr m_raml = ramlParser->getRamlPtr(); + try + { + std::shared_ptr ramlParser = std::make_shared(s); + RamlPtr m_raml = ramlParser->getRamlPtr(); #ifdef PRINT_RAML - std::cout << "#############################################" << std::endl; - std::cout << "Test Raml Parser" << std::endl; - std::cout << "#############################################" << std::endl; + std::cout << "#############################################" << std::endl; + std::cout << "Test Raml Parser" << std::endl; + std::cout << "#############################################" << std::endl; - std::cout << "Title : " << m_raml->getTitle() << std::endl; - std::cout << "Version : " << m_raml->getVersion() << std::endl; + std::cout << "Title : " << m_raml->getTitle() << std::endl; + std::cout << "Version : " << m_raml->getVersion() << std::endl; #ifdef PRINT_PROTOCOLS - std::cout << "Protocols : " ; - for (auto it : m_raml->getProtocols()) - { - std::cout << it << " "; - } + std::cout << "Protocols : " ; + for (auto it : m_raml->getProtocols()) + { + std::cout << it << " "; + } - std::cout << std::endl; + std::cout << std::endl; #endif #ifdef PRINT_BASEURI - std::cout << "BaseUri : " << m_raml->getBaseUri() << std::endl; + std::cout << "BaseUri : " << m_raml->getBaseUri() << std::endl; - std::cout << "BaseUriParameters : " << std::endl; - for (auto it : m_raml->getBaseUriParameters()) - { - std::cout << "-----------------------------" << std::endl; - std::cout << it.first << " : " << std::endl; - std::cout << "-----------------------------" << std::endl; - UriParameter uriParameter = *it.second; - printParameters((AbstractParam)uriParameter); - } + std::cout << "BaseUriParameters : " << std::endl; + for (auto it : m_raml->getBaseUriParameters()) + { + std::cout << "-----------------------------" << std::endl; + std::cout << it.first << " : " << std::endl; + std::cout << "-----------------------------" << std::endl; + UriParameter uriParameter = *it.second; + printParameters((AbstractParam)uriParameter); + } #endif #ifdef PRINT_SCHEMAS - std::cout << "#############################################" << std::endl; - std::cout << "Schemas" << std::endl; - std::cout << "-----------------------------" << std::endl; - for (auto it : m_raml->getSchemas()) - { - std::cout << it.first << " : " << it.second->getSchema() << std::endl; - } + std::cout << "#############################################" << std::endl; + std::cout << "Schemas" << std::endl; + std::cout << "-----------------------------" << std::endl; + for (auto it : m_raml->getSchemas()) + { + std::cout << it.first << " : " << it.second->getSchema() << std::endl; + } #endif - std::cout << "MediaType : " << m_raml->getMediaType() << std::endl; - std::cout << "#############################################" << std::endl; + std::cout << "MediaType : " << m_raml->getMediaType() << std::endl; + std::cout << "#############################################" << std::endl; #ifdef PRINT_DOCUMENTATION - std::cout << "#############################################" << std::endl; + std::cout << "#############################################" << std::endl; - std::cout << "Documentation" << std::endl; - std::cout << "-----------------------------" << std::endl; - for (auto it : m_raml->getDocumentation()) - { - std::cout << it->getTitle() << " : " << it->getContent() << std::endl; - } - std::cout << "#############################################" << std::endl; + std::cout << "Documentation" << std::endl; + std::cout << "-----------------------------" << std::endl; + for (auto it : m_raml->getDocumentation()) + { + std::cout << it->getTitle() << " : " << it->getContent() << std::endl; + } + std::cout << "#############################################" << std::endl; #endif - std::cout << "Resources" << std::endl; - for (auto it : m_raml->getResources()) - { - std::cout << "-----------------------------" << std::endl; - std::cout << "ResourceName :" << it.first << std::endl; - printResource(it.second); - } + std::cout << "Resources" << std::endl; + for (auto it : m_raml->getResources()) + { + std::cout << "-----------------------------" << std::endl; + std::cout << "ResourceName :" << it.first << std::endl; + printResource(it.second); + } #ifdef PRINT_TYPES - std::cout << "#############################################" << std::endl; + std::cout << "#############################################" << std::endl; - std::cout << "ResourceTypes " << std::endl; - for (auto it : m_raml->getResourceTypes()) - { - std::cout << "------------" << it.first << "-----------------" << std::endl; - printResource(it.second); - } + std::cout << "ResourceTypes " << std::endl; + for (auto it : m_raml->getResourceTypes()) + { + std::cout << "------------" << it.first << "-----------------" << std::endl; + printResource(it.second); + } #endif #ifdef PRINT_TRAITS - std::cout << "#############################################" << std::endl; + std::cout << "#############################################" << std::endl; - std::cout << "Traits " << std::endl; - for (auto it : m_raml->getTraits()) - { - std::cout << "-------------" << it.first << "----------------" << std::endl; - printAction(it.second); - } + std::cout << "Traits " << std::endl; + for (auto it : m_raml->getTraits()) + { + std::cout << "-------------" << it.first << "----------------" << std::endl; + printAction(it.second); + } #endif #endif #ifdef PRINT_JSON - for (auto it : m_raml->getResources()) - { - for (auto tt : it.second->getActions()) + for (auto it : m_raml->getResources()) { - for (auto tu : tt.second->getResponses()) + for (auto tt : it.second->getActions()) { - for (auto tv : tu.second->getResponseBody()) + for (auto tu : tt.second->getResponses()) { - auto pro = tv.second->getSchema()->getProperties(); - printJsonSchema(pro); - break; + for (auto tv : tu.second->getResponseBody()) + { + auto pro = tv.second->getSchema()->getProperties(); + printJsonSchema(pro); + break; + } } } } - } #endif + } + catch (RamlException &e) + { + std::cout << e.what() << std::endl; + } } diff --git a/service/simulator/ramlparser/raml/IncludeResolver.h b/service/simulator/ramlparser/raml/IncludeResolver.h index f659200..2bd5ab2 100755 --- a/service/simulator/ramlparser/raml/IncludeResolver.h +++ b/service/simulator/ramlparser/raml/IncludeResolver.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file IncludeResolver.h + * + * @brief This file provides APIs for resolving included files. + */ + #ifndef INCLUDE_RESOLVER_H #define INCLUDE_RESOLVER_H @@ -30,28 +36,84 @@ namespace RAML { + /** + * @class IncludeResolver + * @brief This class provides a set of APIs for resolving included files. + */ class IncludeResolver { - public: + /** FileType - enumeration for Included File types*/ enum class FileType { NODE, JSON, FILE, NOTAG , ERROR }; - public: + /** + * This method is for reading a file specified in YamlNode and parse it to + * getting the created RootNode from RAML file. + * + * @param yamlFile - Reference to YamlNode specifying the FileName. + * + * @return pointer to root node from the Parsed file. + */ YAML::Node readToYamlNode(const YAML::Node &yamlFile ); + + /** + * This method is for reading a file specified in YamlNode and parse the specified Json file. + * + * @param jsonFile - Reference to YamlNode specifying the FileName. + * + * @return cJSON pointer to CJson object. + */ cJSON *readToJson(const YAML::Node &jsonFile ); + + /** + * This method is for reading a file specified in YamlNode and parse the content of file. + * + * @param file - Reference to YamlNode specifying the FileName. + * + * @return contents of the file. + */ std::string readFromFile(const YAML::Node &file ); + + /** + * This method is checking the file type specified in YamlNode. + * + * @param yamlNode - Reference to YamlNode specifying the FileName. + * + * @return FileType type of file. + */ FileType getFileType(const YAML::Node &yamlNode ); + + /** + * This method is for reading a file specified and parse the content of file. + * + * @param jsonFileName - FileName of Json file to be read. + * + * @return pointer to CJson object. + */ cJSON *readToJson(const std::string &jsonFileName); + /** + * Constructor of IncludeResolver. + */ IncludeResolver() {} + + /** + * Constructor of IncludeResolver. + * + * @param path - configuration file path. + * + */ IncludeResolver(const std::string &path) : m_path(path) {} + private: std::string m_path; }; + + /** IncludeResolverPtr - shared Ptr to IncludeResolver.*/ typedef std::shared_ptr IncludeResolverPtr; } diff --git a/service/simulator/ramlparser/raml/RamlErrorCodes.h b/service/simulator/ramlparser/raml/RamlErrorCodes.h index bb43a69..5e8eb34 100755 --- a/service/simulator/ramlparser/raml/RamlErrorCodes.h +++ b/service/simulator/ramlparser/raml/RamlErrorCodes.h @@ -18,13 +18,19 @@ * ******************************************************************/ +/** + * @file RamlErrorCodes.h + * + * @brief This file provides list of error codes while parsing Raml file. + */ + #ifndef RAML_ERROR_CODES_H_ #define RAML_ERROR_CODES_H_ +/** RamlParserResult - This enum provides list of error codes from RamlParser*/ typedef enum { RAML_PARSER_OK = 0, - RAML_FILE_PATH_REQUIRED, RAML_PARSER_ERROR = 255 } RamlParserResult; diff --git a/service/simulator/ramlparser/raml/RamlExceptions.cpp b/service/simulator/ramlparser/raml/RamlExceptions.cpp index 63f67dd..55a223b 100755 --- a/service/simulator/ramlparser/raml/RamlExceptions.cpp +++ b/service/simulator/ramlparser/raml/RamlExceptions.cpp @@ -23,13 +23,14 @@ namespace RAML { const char *RamlException::what() const noexcept { - if (m_mark.is_null()) - { - return m_message.c_str(); - } + return m_message.c_str(); + } + + RamlException::RamlException(const YAML::Mark &mark, const std::string &message): m_mark(mark) + { std::stringstream output; output << "Error at line " << m_mark.line + 1 << ", column " - << m_mark.column + 1 << ": " << m_message; - return output.str().c_str(); + << m_mark.column + 1 << ": " << message; + m_message = output.str(); } } diff --git a/service/simulator/ramlparser/raml/RamlExceptions.h b/service/simulator/ramlparser/raml/RamlExceptions.h index c6f884b..c646196 100755 --- a/service/simulator/ramlparser/raml/RamlExceptions.h +++ b/service/simulator/ramlparser/raml/RamlExceptions.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file RamlExceptions.h + * + * @brief This file provides exception handling while parsing RAML and Json Schema. + */ + #ifndef RAML_EXCEPTIONS_H_ #define RAML_EXCEPTIONS_H_ @@ -27,12 +33,33 @@ namespace RAML { + /** + * @class RamlException + * @brief This is the base exception of all type of exception thrown from RamlParser module. + */ class RamlException : public std::exception { public: + /** + * Constructor of RamlException. + * + * @param message - String describing the error messsage. + */ RamlException(const std::string &message) : m_message(message) {} - RamlException(const YAML::Mark &mark, const std::string &message): m_message(message), - m_mark(mark) {} + + /** + * Constructor of RamlException. + * + * @param mark - line and column information of exception thrown. + * @param message - String describing the error messsage. + */ + RamlException(const YAML::Mark &mark, const std::string &message); + + /** + * API to get error message describing exception reason. + * + * @return Null terminated string. + */ virtual const char *what() const noexcept; virtual ~RamlException() throw() {} @@ -41,31 +68,88 @@ namespace RAML YAML::Mark m_mark; }; + /** + * @class RamlParserException + * @brief This exception will be thrown to indicate Parser Exception. + */ class RamlParserException : public RamlException { public: + /** + * Constructor of RamlParserException. + * + * @param message - String describing the error messsage. + */ RamlParserException(const std::string &message): RamlException(message) {} + + /** + * Constructor of RamlParserException. + * + * @param mark - line and column information of exception thrown. + * @param message - String describing the error messsage. + */ RamlParserException(const YAML::Mark &mark, const std::string &message): RamlException(mark, message) {} }; + /** + * @class RamlRepresentationException + * @brief This exception will be thrown to indicate invalid Raml Representation case. + */ class RamlRepresentationException : public RamlException { public: + /** + * Constructor of RamlRepresentationException. + * + * @param message - String describing the error messsage. + */ RamlRepresentationException(const std::string &message): RamlException(message) {} + + /** + * Constructor of RamlRepresentationException. + * + * @param mark - line and column information of exception thrown. + * @param message - String describing the error messsage. + */ RamlRepresentationException(const YAML::Mark &mark, const std::string &message): RamlException(mark, message) {} }; + /** + * @class RamlBadFile + * @brief This exception will be thrown to indicate RAMl BadFile. + */ class RamlBadFile : public RamlException { public: + /** + * Constructor of RamlBadFile. + * + * @param message - String describing the error messsage. + */ RamlBadFile(const std::string &message) : RamlException(message) {} + + /** + * Constructor of RamlBadFile. + * + * @param mark - line and column information of exception thrown. + * @param message - String describing the error messsage. + */ RamlBadFile(const YAML::Mark &mark, const std::string &message): RamlException(mark, message) {} }; + /** + * @class JsonException + * @brief This exception will be thrown to indicate invalid Json file. + */ class JsonException : public RamlException { public: + /** + * Constructor of JsonException. + * + * @param message - String describing the error messsage. + */ JsonException(const std::string &message) : RamlException(message) {} }; diff --git a/service/simulator/ramlparser/raml/RamlParser.h b/service/simulator/ramlparser/raml/RamlParser.h index 50f3501..3949234 100755 --- a/service/simulator/ramlparser/raml/RamlParser.h +++ b/service/simulator/ramlparser/raml/RamlParser.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file RamlParser.h + * + * @brief This file provides APIs for parsing Raml file. + */ + #ifndef RAML_PARSER_H #define RAML_PARSER_H @@ -35,6 +41,10 @@ namespace RAML { + /** + * @class RamlParser + * @brief This class provides a set of APIs for parsing Raml file. + */ class RamlParser { private: @@ -45,9 +55,38 @@ namespace RAML void setTraits(const std::map &resource); public: + /** + * This method is for getting the created and Parsed RAML object from RAML file. + * + * @param result - Reference to RamlParserResult. + * + * @return pointer to Raml shared object parsed. + */ virtual RamlPtr getRamlPtr(RamlParserResult &result); + + /** + * This method is for getting the created and Parsed RAML object from RAML file. + * + * @return pointer to Raml shared object parsed. + */ virtual RamlPtr getRamlPtr(); - RamlParser(): m_ramlPtr(std::make_shared()), m_ramlParserResult(RAML_FILE_PATH_REQUIRED) {} + + /** + * Constructor of RamlParser. + * + * NOTE: Constructor would initialize the RamlParserResult with File Path Required + */ + RamlParser(): m_ramlPtr(std::make_shared()), + m_ramlParserResult(RAML_FILE_PATH_REQUIRED) {} + + /** + * Constructor of RamlParser. + * + * @param path - RAML configuration file path. + * + * NOTE: Constructor would throw RamlBadFile when invalid arguments passed, and + * RamlException if any other error occured. + */ RamlParser(const std::string &path): m_ramlParserResult(RAML_PARSER_ERROR) { if (path.length() > 0) diff --git a/service/simulator/ramlparser/raml/Utils.h b/service/simulator/ramlparser/raml/Utils.h index c69470e..0895f36 100755 --- a/service/simulator/ramlparser/raml/Utils.h +++ b/service/simulator/ramlparser/raml/Utils.h @@ -18,6 +18,11 @@ * ******************************************************************/ +/** + * @file Utils.h + * + * @brief This file provides utilities for RamlParser. + */ #ifndef UTILS_H #define UTILS_H @@ -29,89 +34,163 @@ namespace RAML { namespace Keys { + /** Title - Raml title key.*/ const std::string Title = "title"; + /** Version - Raml Version key.*/ const std::string Version = "version"; + /** BaseUri - Raml BaseUri key.*/ const std::string BaseUri = "baseUri"; + /** Protocols - Raml Protocols key.*/ const std::string Protocols = "protocols"; + /** MediaType - Raml MediaType key.*/ const std::string MediaType = "mediaType"; + /** Schemas - Raml Schemas key.*/ const std::string Schemas = "schemas"; + /** ResourceTypes - Raml ResourceTypes key.*/ const std::string ResourceTypes = "resourceTypes"; + /** Traits - Raml Traits key.*/ const std::string Traits = "traits"; + /** IsTrait - Raml is key.*/ const std::string IsTrait = "is"; + /** Resource - Raml Resource key.*/ const std::string Resource = "/"; - const std::vector ActionType = {"get", "post", "put", "delete", "head", "patch", "options", "trace"}; + /** ActionType - Raml allowed ActionType key.*/ + const std::vector ActionType = {"get", "post", "put", "delete", + "head", "patch", "options", "trace" + }; + /** Responses - Raml Responses key.*/ const std::string Responses = "responses"; + /** Body - Raml Body key.*/ const std::string Body = "body"; + /** Schema - Raml Schema key.*/ const std::string Schema = "schema"; + /** Example - Raml Example key.*/ const std::string Example = "example"; + /** BaseUriParameters - Raml BaseUriParameters key.*/ const std::string BaseUriParameters = "baseUriParameters"; + /** UriParameters - Raml UriParameters key.*/ const std::string UriParameters = "uriParameters"; + /** Headers - Raml title Headers.*/ const std::string Headers = "headers"; + /** QueryParameters - Raml QueryParameters key.*/ const std::string QueryParameters = "queryParameters"; + /** FormParameters - Raml FormParameters key.*/ const std::string FormParameters = "formParameters"; + /** DisplayName - Raml DisplayName key.*/ const std::string DisplayName = "displayName"; + /** Description - Raml Description key.*/ const std::string Description = "description"; + /** Type - Raml Type key.*/ const std::string Type = "type"; + /** Enum - Raml Enum key.*/ const std::string Enum = "enum"; + /** Pattern - Raml Pattern key.*/ const std::string Pattern = "pattern"; + /** MinLength - Raml MinLength key.*/ const std::string MinLength = "minLength"; + /** MaxLength - Raml MaxLength key.*/ const std::string MaxLength = "maxLength"; + /** Minimum - Raml Minimum key.*/ const std::string Minimum = "minimum"; + /** Maximum - Raml Maximum key.*/ const std::string Maximum = "maximum"; + /** Repeat - Raml Repeat key.*/ const std::string Repeat = "repeat"; + /** Required - Raml Required key.*/ const std::string Required = "required"; + /** Default - Raml Default key.*/ const std::string Default = "default"; + /** Title - Raml title key.*/ + /** Documentation - Raml Documentation key.*/ const std::string Documentation = "documentation"; + /** Content - Raml Content key.*/ const std::string Content = "content"; + /** Json - Raml Json key.*/ const std::string Json = "json"; + /** AllowedRamlYamlTypes - Raml AllowedRamlYamlTypes key.*/ const std::vector AllowedRamlYamlTypes = {"raml", "yaml", "yml"}; } + /** + * This macro is reading yamlNode as String. + * + * @param yamlNode - reference to yamlNode + * + * @return value as string + */ #define READ_NODE_AS_STRING(yamlNode) \ ({ \ (yamlNode).as(); \ }) + /** + * This macro is reading yamlNode as int. + * + * @param yamlNode - reference to yamlNode + * + * @return value as int + */ #define READ_NODE_AS_INT(yamlNode) \ ({ \ (yamlNode).as(); \ }) + /** + * This macro is reading yamlNode as long. + * + * @param yamlNode - reference to yamlNode + * + * @return value as long + */ #define READ_NODE_AS_LONG(yamlNode) \ ({ \ (yamlNode).as(); \ }) + /** + * This macro is reading yamlNode as bool. + * + * @param yamlNode - reference to yamlNode + * + * @return value as bool + */ #define READ_NODE_AS_BOOL(yamlNode) \ ({ \ (yamlNode).as(); \ }) + /** + * This macro is getting ActionType + * + * @param key - string + * + * @return ActionType + */ #define GET_ACTION_TYPE(key) \ ({ \ - ActionType actionType; \ + ActionType actionType = ActionType::GET; \ if (key == "get" ) \ - actionType = ActionType::GET; \ + actionType = ActionType::GET; \ else if (key == "post" ) \ - actionType = ActionType::POST; \ + actionType = ActionType::POST; \ else if (key == "put" ) \ - actionType = ActionType::PUT; \ + actionType = ActionType::PUT; \ else if (key == "delete" ) \ - actionType = ActionType::DELETE; \ + actionType = ActionType::DELETE; \ else if (key == "head" ) \ - actionType = ActionType::HEAD; \ + actionType = ActionType::HEAD; \ else if (key == "patch" ) \ - actionType = ActionType::PATCH; \ + actionType = ActionType::PATCH; \ else if (key == "options" ) \ - actionType = ActionType::OPTIONS; \ + actionType = ActionType::OPTIONS; \ else if (key == "trace" ) \ - actionType = ActionType::TRACE; \ + actionType = ActionType::TRACE; \ actionType; \ }) diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h b/service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h index dc23371..b0946ae 100755 --- a/service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h +++ b/service/simulator/ramlparser/raml/jsonSchemaParser/AllowedValues.h @@ -17,6 +17,13 @@ * limitations under the License. * ******************************************************************/ + +/** + * @file AllowedValues.h + * + * @brief This file provides data Model for Json Schema AllowedValues. + */ + #ifndef ALLOWED_VALUES_H_ #define ALLOWED_VALUES_H_ @@ -29,9 +36,18 @@ namespace RAML { + /** + * @class AllowedValues + * @brief This class provides data Model for Json Schema AllowedValues. + */ class AllowedValues { public: + /** + * This method is for setting AllowedValues + * + * @param value - Allowed Value to set. + */ template void addValue(const T &value) { @@ -39,6 +55,11 @@ namespace RAML m_values.push_back(temp); } + /** + * This method is for setting AllowedValues + * + * @param values - list of Allowed Values to set. + */ template void addValues(const std::vector &values) { @@ -49,19 +70,41 @@ namespace RAML } } + /** + * This method is for getting AllowedValues + * + * @param index - Allowed Values at index to be fetched + */ inline ValueVariant &at(int index) { return m_values.at(index); } + + /** + * This method is for getting size of AllowedValues + * + * @return size of Allowed Values list + */ inline int size() const { return m_values.size(); } + /** + * This method is for getting AllowedValues. + * + * @return list of AllowedValues + */ inline std::vector getValues() { return m_values; } + + /** + * This method is for getting AllowedValues as integer. + * + * @return list of AllowedValues as integer. + */ inline std::vector getValuesInt() { std::vector values; @@ -71,6 +114,12 @@ namespace RAML } return values; } + + /** + * This method is for getting AllowedValues as string. + * + * @return list of AllowedValues as string. + */ inline std::vector getValuesString() { std::vector values; @@ -81,6 +130,36 @@ namespace RAML return values; } + /** + * This method is for getting AllowedValues as Double. + * + * @return list of AllowedValues as Double. + */ + inline std::vector getValuesDouble() + { + std::vector values; + for (auto value : m_values) + { + values.push_back(boost::lexical_cast (value)); + } + return values; + } + + /** + * This method is for getting AllowedValues as Bool. + * + * @return list of AllowedValues as Bool. + */ + inline std::vector getValuesBool() + { + std::vector values; + for (auto value : m_values) + { + values.push_back(boost::lexical_cast (value)); + } + return values; + } + private: std::vector m_values; }; diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.h index a1ec9f3..401e448 100755 --- a/service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.h +++ b/service/simulator/ramlparser/raml/jsonSchemaParser/Definitions.h @@ -17,6 +17,13 @@ * limitations under the License. * ******************************************************************/ + +/** + * @file Definitions.h + * + * @brief This file provides data Model for Json Schema Definitions. + */ + #ifndef DEFINITIONS_H_ #define DEFINITIONS_H_ @@ -24,72 +31,154 @@ #include #include #include "Properties.h" +#include namespace RAML { + /** + * @class Definitions + * @brief This class provides data Model for Json Schema Definitions. + */ class Definitions { public: + /** + * Constructor of Definitions. + */ Definitions() = default; + + /** + * Constructor of Definitions. + * + * @param name - Definitions name as string. + */ Definitions(const std::string &name) : m_defName(name) {} + /** + * This method is for getting Name from Definitions. + * + * @return Definitions name as string + */ inline std::string getName(void) const { return m_defName; } + + /** + * This method is for setting name to Definitions + * + * @param name - Definitions name as string. + */ inline void setName(const std::string &name) { m_defName = name; } + + /** + * This method is for getting Type from Definitions. + * + * @return Definitions Type as string + */ inline std::string getType(void) const { return m_type; } + + /** + * This method is for setting Type to Definitions + * + * @param type - Definitions Type as string. + */ inline void setType(const std::string &type) { m_type = type; } - void addProperty(const std::string &propName, Properties *property) + + /** + * This method is for getting RequiredValue from Definitions. + * + * @return list of RequiredValue as string + */ + std::vector const &getRequiredValues() const { - if (m_properties.end() == m_properties.find(propName)) - { - m_properties[propName] = property; - } + return m_required; } + + /** + * This method is for setting RequiredValue to Definitions + * + * @param reqValue - RequiredValue as string. + */ void setRequiredValue(const std::string &reqValue) { - if (m_required.end() == std::find(m_required.begin(), m_required.end(), reqValue)) + auto it = m_required.begin(); + for (; it != m_required.end(); ++it) + { + if (*it == reqValue) + break; + } + if (m_required.end() != it) { m_required.push_back(reqValue); } } - std::vector getRequiredValues() const - { - return m_required; - } + + /** + * This method is for getting size of Properties from Definitions. + * + * @return size of Properties map + */ int propertiesSize() const { return m_properties.size(); } - inline bool getproperty(const std::string &propName, Properties *value) + /** + * This method is for getting Properties from Definitions. + * + * @param propName - name of property as string. + * + * @return pointer to Properties. + */ + inline PropertiesPtr getproperty(const std::string &propName ) { if (m_properties.end() != m_properties.find(propName)) { - value = m_properties[propName]; - return true; + return m_properties[propName]; } - return false; + return nullptr; } - inline std::map getProperties() + + /** + * This method is for getting Properties from Definitions. + * + * @return map of Property name and pointer to Properties + */ + inline std::map const &getProperties() { return m_properties; } + + /** + * This method is for setting Properties to Definitions + * + * @param propName - Definitions Type as string. + * @param property - pointer to Properties. + */ + void addProperty(const std::string &propName, const PropertiesPtr &property) + { + if (m_properties.end() == m_properties.find(propName)) + { + m_properties[propName] = property; + } + } private: - std::map m_properties; + std::map m_properties; std::string m_defName; std::string m_type; std::vector m_required; }; + + /** DefinitionsPtr - shared Ptr to Definitions.*/ typedef std::shared_ptr DefinitionsPtr; } diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h index 9e25072..d5ceb68 100755 --- a/service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h +++ b/service/simulator/ramlparser/raml/jsonSchemaParser/Helpers.h @@ -17,6 +17,13 @@ * limitations under the License. * ******************************************************************/ + +/** + * @file Helpers.h + * + * @brief This file provides helper definitions for Json Schema parser. + */ + #ifndef HELPERS_H_ #define HELPERS_H_ @@ -29,7 +36,7 @@ namespace RAML { - + /** ValueVariant - Boost Variant to hold type of int, string, double and bool*/ typedef boost::variant < int, double, @@ -37,5 +44,12 @@ namespace RAML std::string > ValueVariant; + /** VariantType - enumeration for variant types*/ + enum class VariantType + { + INT, DOUBLE, BOOL, STRING + }; + + } #endif diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Items.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Items.h index b5353bd..b0a0e50 100755 --- a/service/simulator/ramlparser/raml/jsonSchemaParser/Items.h +++ b/service/simulator/ramlparser/raml/jsonSchemaParser/Items.h @@ -17,6 +17,13 @@ * limitations under the License. * ******************************************************************/ + +/** + * @file Items.h + * + * @brief This file provides data Model for Json Schema Array Items. + */ + #ifndef ITEMS_H_ #define ITEMS_H_ @@ -26,82 +33,173 @@ #include "Properties.h" #include "Helpers.h" #include "AllowedValues.h" +#include namespace RAML { class Properties; class AllowedValues; + /** + * @class Items + * @brief This class provides data Model for Json Schema Array Items. + */ class Items { public: + /** + * Constructor of Items. + */ Items() {} - void addProperty(const std::string &propName, Properties *property) + + /** + * This method is for setting Properties to Items + * + * @param propName - Properties name as string. + * @param property - pointer to Properties. + */ + void addProperty(const std::string &propName, const std::shared_ptr &property) { if (m_properties.end() == m_properties.find(propName)) { m_properties[propName] = property; } } - bool getproperty(const std::string &propName, Properties *value) + + /** + * This method is for getting Properties from Items. + * + * @param propName - Properties name as string. + * + * @return pointer to Properties to put the value got + */ + std::shared_ptr getproperty(const std::string &propName) { if (m_properties.end() != m_properties.find(propName)) { - value = m_properties[propName]; - return true; + return m_properties[propName]; } - return false; + return nullptr; } - std::map getProperties() + + /** + * This method is for getting Properties from Items. + * + * @return map of Properties name as string and pointer to Properties + */ + std::map > const &getProperties() { return m_properties; } + + /** + * This method is for setting Type to Items + * + * @param type - Type as string. + */ void setType(const std::string &type) { m_type = type; } + + /** + * This method is for getting Type from Items. + * + * @return Type as string + */ std::string getType() { return m_type; } + + /** + * This method is for setting RequiredValue to Items + * + * @param reqValue - RequiredValue as string. + */ void setRequiredValue(const std::string &reqValue) { - if (m_required.end() == std::find(m_required.begin(), m_required.end(), reqValue)) + auto it = m_required.begin(); + for (; it != m_required.end(); ++it) + { + if (*it == reqValue) + break; + } + if (m_required.end() != it) { m_required.push_back(reqValue); } } - std::vector getRequiredValues() + + /** + * This method is for getting RequiredValue from Items. + * + * @return list of RequiredValue as string + */ + std::vector const &getRequiredValues() { return m_required; } + + /** + * This method is for setting AllowedValues to Items + * + * @param values -list of AllowedValues. + */ template bool setAllowedValues(const std::vector &values) { m_allowedValues.addValues(values); return true; } + + /** + * This method is for getting size of AllowedValues from Items. + * + * @return size of AllowedValues + */ inline int getAllowedValuesSize() const { return m_allowedValues.size(); } + + /** + * This method is for getting AllowedValues from Items. + * + * @return list of AllowedValues + */ inline std::vector getAllowedValues() { return m_allowedValues.getValues(); } + + /** + * This method is for getting AllowedValues as Integer from Items. + * + * @return list of AllowedValues as Integer + */ inline std::vector getAllowedValuesInt() { return m_allowedValues.getValuesInt(); } + + /** + * This method is for getting AllowedValues as String from Items. + * + * @return list of AllowedValues as String + */ inline std::vector getAllowedValuesString() { return m_allowedValues.getValuesString(); } private: - std::map m_properties; + std::map > m_properties; std::string m_type; std::vector m_required; AllowedValues m_allowedValues; }; + + /** ItemsPtr - shared Ptr to Items.*/ + typedef std::shared_ptr ItemsPtr; } #endif diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.cpp b/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.cpp index f4939ca..9425b0b 100755 --- a/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.cpp +++ b/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.cpp @@ -88,15 +88,13 @@ namespace RAML do { cJSON *item = cJSON_GetArrayItem(jsonItems, item_index); - Items *newItem = readItems(item); - setItem(newItem); + setItem(readItems(item)); } while ( ++item_index < item_size); } else { - Items *newItem = readItems(jsonItems); - setItem(newItem); + setItem(readItems(jsonItems)); } } } @@ -129,9 +127,9 @@ namespace RAML } } - Definitions *JsonSchema::readDef(cJSON *childDefinitions, const std::string &defName) + DefinitionsPtr JsonSchema::readDef(cJSON *childDefinitions, const std::string &defName) { - Definitions *definition = new Definitions(defName); + DefinitionsPtr definition = std::make_shared(defName); cJSON *defType = cJSON_GetObjectItem(childDefinitions, "type"); if (defType) @@ -174,9 +172,9 @@ namespace RAML return definition; } - Properties *JsonSchema::readProp(cJSON *childProperties, const std::string &attName ) + PropertiesPtr JsonSchema::readProp(cJSON *childProperties, const std::string &attName ) { - Properties *property = new Properties(attName); + PropertiesPtr property = std::make_shared(attName); cJSON *propertyUpdateFrequency = cJSON_GetObjectItem(childProperties, "update_frequency"); if (propertyUpdateFrequency) @@ -288,7 +286,7 @@ namespace RAML return property; } - void JsonSchema::readValues(cJSON *childProperties, Properties *property , + void JsonSchema::readValues(cJSON *childProperties, PropertiesPtr property , const std::string &attType) { if (attType == "string") @@ -309,7 +307,7 @@ namespace RAML } } - void JsonSchema::readString(cJSON *childProperties, Properties *property) + void JsonSchema::readString(cJSON *childProperties, PropertiesPtr property) { cJSON *stringMax = cJSON_GetObjectItem(childProperties, "maxLength"); if (stringMax) @@ -351,7 +349,7 @@ namespace RAML } } - void JsonSchema::readArray(cJSON *childProperties, Properties *property) + void JsonSchema::readArray(cJSON *childProperties, PropertiesPtr property) { cJSON *itemValues = cJSON_GetObjectItem(childProperties, "items"); if (itemValues) @@ -363,15 +361,13 @@ namespace RAML do { cJSON *item = cJSON_GetArrayItem(itemValues, item_index); - Items *newItem = readItems(item); - property->setItem(newItem); + property->setItem(readItems(item)); } while ( ++item_index < item_size); } else { - Items *newItem = readItems(itemValues); - property->setItem(newItem); + property->setItem(readItems(itemValues)); } } cJSON *itemsMax = cJSON_GetObjectItem(childProperties, "maxItems"); @@ -422,7 +418,7 @@ namespace RAML } } - void JsonSchema::readNumber(cJSON *childProperties, Properties *property) + void JsonSchema::readNumber(cJSON *childProperties, PropertiesPtr property) { cJSON *Max = cJSON_GetObjectItem(childProperties, "maximum"); if (Max) @@ -459,7 +455,7 @@ namespace RAML } } - Definitions *JsonSchema::readRef(std::string m_ref) + DefinitionsPtr JsonSchema::readRef(std::string m_ref) { std::string delimiter1 = "#"; std::string delimiter2 = "/"; @@ -501,8 +497,8 @@ namespace RAML if (!(defName.empty())) { cJSON *m_json = m_includeResolver->readToJson(fileName); - JsonSchema *Refparser = new JsonSchema(m_json, m_includeResolver); - Definitions *definition = Refparser->getDefinition(defName); + JsonSchemaPtr Refparser = std::make_shared(m_json, m_includeResolver); + DefinitionsPtr definition = Refparser->getDefinition(defName); if (definition == nullptr) throw JsonException("Definition Name Incorrect"); return definition; @@ -518,6 +514,8 @@ namespace RAML } } } + throw JsonException("Definition Name Empty"); + return nullptr; } void JsonSchema::readAllOf(cJSON *allofValues) { @@ -548,7 +546,7 @@ namespace RAML void JsonSchema::readJsonRef(cJSON *jsonReference) { std::string m_ref = jsonReference->valuestring; - std::map properties; + std::map properties; std::vector required; std::string web = "http://"; @@ -562,14 +560,14 @@ namespace RAML { std::string fileName = m_ref.substr(0, pos); cJSON *m_json = m_includeResolver->readToJson(fileName); - JsonSchema *Refparser = new JsonSchema(m_json, m_includeResolver); + JsonSchemaPtr Refparser = std::make_shared(m_json, m_includeResolver); properties = Refparser->getProperties(); required = Refparser->getRequiredValues(); } else { - Definitions *definition = readRef(m_ref); + DefinitionsPtr definition = readRef(m_ref); properties = definition->getProperties(); required = definition->getRequiredValues(); } @@ -585,7 +583,7 @@ namespace RAML } } - void JsonSchema::readDefAllOf(cJSON *allofValues, Definitions *definition) + void JsonSchema::readDefAllOf(cJSON *allofValues, DefinitionsPtr definition) { int size = cJSON_GetArraySize(allofValues); int index = 0; @@ -611,10 +609,10 @@ namespace RAML } while ( ++index < size); } - void JsonSchema::readDefRef(cJSON *defReference, Definitions *definition) + void JsonSchema::readDefRef(cJSON *defReference, DefinitionsPtr definition) { std::string m_ref = defReference->valuestring; - std::map properties; + std::map properties; std::vector required; std::string type; @@ -629,7 +627,7 @@ namespace RAML { std::string fileName = m_ref.substr(0, pos); cJSON *m_json = m_includeResolver->readToJson(fileName); - JsonSchema *Refparser = new JsonSchema(m_json, m_includeResolver); + JsonSchemaPtr Refparser = std::make_shared(m_json, m_includeResolver); properties = Refparser->getProperties(); required = Refparser->getRequiredValues(); @@ -637,7 +635,7 @@ namespace RAML } else { - Definitions *definitionRef = readRef(m_ref); + DefinitionsPtr definitionRef = readRef(m_ref); properties = definitionRef->getProperties(); required = definitionRef->getRequiredValues(); type = definitionRef->getType(); @@ -653,9 +651,9 @@ namespace RAML definition->setType(type); } } - Items *JsonSchema::readItems(cJSON *item) + ItemsPtr JsonSchema::readItems(cJSON *item) { - Items *newItem = new Items(); + ItemsPtr newItem = std::make_shared(); cJSON *itemType = cJSON_GetObjectItem(item, "type"); if (itemType) { @@ -670,9 +668,8 @@ namespace RAML while (childProperties) { std::string attName = childProperties->string; - Properties *property = readProp(childProperties, attName); - newItem->addProperty(attName, property); + newItem->addProperty(attName, readProp(childProperties, attName)); childProperties = childProperties->next; } } @@ -755,13 +752,13 @@ namespace RAML { readItemAllOf(itemAllOf , newItem); } - return (newItem); + return newItem; } - void JsonSchema::readItemRef(cJSON *itemReference, Items *item) + void JsonSchema::readItemRef(cJSON *itemReference, ItemsPtr item) { std::string m_ref = itemReference->valuestring; - std::map properties; + std::map properties; std::vector required; std::string type; @@ -776,7 +773,7 @@ namespace RAML { std::string fileName = m_ref.substr(0, pos); cJSON *m_json = m_includeResolver->readToJson(fileName); - JsonSchema *Refparser = new JsonSchema(m_json, m_includeResolver); + JsonSchemaPtr Refparser = std::make_shared(m_json, m_includeResolver); properties = Refparser->getProperties(); required = Refparser->getRequiredValues(); @@ -784,7 +781,7 @@ namespace RAML } else { - Definitions *definitionRef = readRef(m_ref); + DefinitionsPtr definitionRef = readRef(m_ref); properties = definitionRef->getProperties(); required = definitionRef->getRequiredValues(); type = definitionRef->getType(); @@ -802,7 +799,7 @@ namespace RAML } } - void JsonSchema::readItemAllOf(cJSON *allofValues, Items *item) + void JsonSchema::readItemAllOf(cJSON *allofValues, ItemsPtr item) { int size = cJSON_GetArraySize(allofValues); int index = 0; diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.h b/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.h index 16ddfdc..fb300ba 100755 --- a/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.h +++ b/service/simulator/ramlparser/raml/jsonSchemaParser/JsonSchema.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file JsonSchema.h + * + * @brief This file provides data Model for Json Schema file. + */ + #ifndef JSON_SCHEMA_H_ #define JSON_SCHEMA_H_ @@ -30,49 +36,114 @@ #include "cJSON.h" #include "Helpers.h" #include "AllowedValues.h" +#include #include "IncludeResolver.h" namespace RAML { + /** + * @class JsonSchema + * @brief This class provides data Model for Json Schema file. + */ class JsonSchema { public: + /** + * Constructor of JsonSchema. + */ JsonSchema() : m_cjson(NULL), m_includeResolver(NULL) {} + + /** + * Constructor of JsonSchema. + * + * @param includeResolver - Reference to IncludeResolver for reading external files + */ JsonSchema(const IncludeResolverPtr &includeResolver) : m_cjson(NULL), m_includeResolver(includeResolver) {} + + /** + * Constructor of JsonSchema. + * + * @param cjson - pointer to cjson + * @param includeResolver - Reference to IncludeResolver for reading external files + */ JsonSchema(cJSON *cjson , const IncludeResolverPtr &includeResolver) : m_cjson(cjson), m_includeResolver(includeResolver) { readJson(); } + + /** + * This method is for setting cJson pointer to JsonSchema. + * + * @param cjson -pointer to cJson + */ void setcJson(cJSON *cjson) {m_cjson = cjson; readJson(); } + + /** + * This method is for getting size of Properties from JsonSchema. + * + * @return size of Properties + */ int size() const { return m_properties.size(); } - inline bool getProperty(const std::string &name, Properties *value) + + /** + * This method is for getting Properties from JsonSchema. + * + * @param name -name of property as string + * + * @return pointer to Properties + */ + inline PropertiesPtr getProperty(const std::string &name) { if (m_properties.end() != m_properties.find(name)) { - value = m_properties[name]; - return true; + return m_properties[name]; } - return false; + return nullptr; } - inline std::map getProperties() + + /** + * This method is for getting Properties from JsonSchema. + * + * @return map of Properties name and pointer to Properties + */ + inline std::map const &getProperties() { return m_properties; } - inline std::map getDefinitions() + + /** + * This method is for getting Definitions from JsonSchema. + * + * @return map of Definitions name and pointer to Definitions + */ + inline std::map const &getDefinitions() { return m_definition; } - void addProperty(const std::string &name, Properties *property) + + /** + * This method is for setting Properties to JsonSchema. + * + * @param name -name of property as string + * @param property -pointer to Properties + */ + void addProperty(const std::string &name, const PropertiesPtr &property) { if (m_properties.end() == m_properties.find(name)) { m_properties[name] = property; } } + + /** + * This method is for setting RequiredValue to JsonSchema. + * + * @param reqValue -name of RequiredValue as string + */ void setRequiredValue(const std::string &reqValue) { if (m_required.end() == std::find(m_required.begin(), m_required.end(), reqValue)) @@ -80,18 +151,39 @@ namespace RAML m_required.push_back(reqValue); } } - std::vector getRequiredValues() + + /** + * This method is for getting RequiredValues from JsonSchema. + * + * @return vector of RequiredValues as string + */ + std::vector const &getRequiredValues() { return m_required; } - void addDefinition(const std::string &defName, Definitions *definition) + + /** + * This method is for setting Definitions to JsonSchema. + * + * @param defName -name of Definitions as string + * @param definition -pointer to Definitions + */ + void addDefinition(const std::string &defName, const DefinitionsPtr &definition) { if (m_definition.end() == m_definition.find(defName)) { m_definition[defName] = definition; } } - Definitions *getDefinition(const std::string &defName) + + /** + * This method is for getting Definitions from JsonSchema. + * + * @param defName -Definition name as string + * + * @return pointer to Definitions + */ + DefinitionsPtr getDefinition(const std::string &defName) { if (m_definition.end() != m_definition.find(defName)) { @@ -99,61 +191,110 @@ namespace RAML } return nullptr; } + + /** + * This method is for getting Type from JsonSchema. + * + * @return JsonSchema Type as string + */ std::string getType() { return m_type; } + + /** + * This method is for getting Id from JsonSchema. + * + * @return JsonSchema Id as string + */ std::string getId() { return m_id; } + + /** + * This method is for getting Schema from JsonSchema. + * + * @return Schema as string + */ std::string getSchema() { return m_schema; } + + /** + * This method is for getting Description from JsonSchema. + * + * @return JsonSchema Description as string + */ std::string getDescription() { return m_description; } + + /** + * This method is for getting Title from JsonSchema. + * + * @return JsonSchema Title as string + */ std::string getTitle() { return m_title; } + /** + * This method is for getting AdditionalProperties from JsonSchema. + * + * @return AdditionalProperties as bool + */ bool getAdditionalProperties() { return m_additionalProperties; } - void setItem(Items *item) + + /** + * This method is for setting Items to JsonSchema. + * + * @param item -pointer to Items + */ + void setItem(const ItemsPtr &item) { m_items.push_back(item); } - std::vector getItems() + + /** + * This method is for getting Items from JsonSchema. + * + * @return vector of Items + */ + std::vector const &getItems() { return m_items; } + private: void readJson(); - Definitions *readDef(cJSON *childDefinitions, const std::string &defName); - Properties *readProp(cJSON *childProperties, const std::string &attName ); - void readValues( cJSON *childProperties, Properties *property , const std::string &attType); - void readString( cJSON *childProperties, Properties *property); - void readArray( cJSON *childProperties, Properties *property); - void readNumber( cJSON *childProperties, Properties *property); - Definitions *readRef(std::string m_ref); + DefinitionsPtr readDef(cJSON *childDefinitions, const std::string &defName); + PropertiesPtr readProp(cJSON *childProperties, const std::string &attName ); + void readValues( cJSON *childProperties, PropertiesPtr property , + const std::string &attType); + void readString( cJSON *childProperties, PropertiesPtr property); + void readArray( cJSON *childProperties, PropertiesPtr property); + void readNumber( cJSON *childProperties, PropertiesPtr property); + DefinitionsPtr readRef(std::string m_ref); void readJsonRef(cJSON *jsonReference); - void readDefRef(cJSON *defReference, Definitions *definition); + void readDefRef(cJSON *defReference, DefinitionsPtr definition); void readAllOf(cJSON *allofValues); - void readDefAllOf(cJSON *allofValues, Definitions *definition); - Items *readItems(cJSON *item); - void readItemRef(cJSON *itemReference, Items *item); - void readItemAllOf(cJSON *allofValues, Items *item); + void readDefAllOf(cJSON *allofValues, DefinitionsPtr definition); + ItemsPtr readItems(cJSON *item); + void readItemRef(cJSON *itemReference, ItemsPtr item); + void readItemAllOf(cJSON *allofValues, ItemsPtr item); private: - std::map m_properties; - std::map m_definition; + std::map m_properties; + std::map m_definition; std::string m_id; std::string m_schema; std::string m_title; @@ -162,9 +303,11 @@ namespace RAML std::string m_type; cJSON *m_cjson; std::vector m_required; - std::vector m_items; + std::vector m_items; IncludeResolverPtr m_includeResolver; }; + + /** JsonSchemaPtr - shared Ptr to JsonSchema.*/ typedef std::shared_ptr JsonSchemaPtr; } diff --git a/service/simulator/ramlparser/raml/jsonSchemaParser/Properties.h b/service/simulator/ramlparser/raml/jsonSchemaParser/Properties.h index b8fbbc7..61daf5e 100755 --- a/service/simulator/ramlparser/raml/jsonSchemaParser/Properties.h +++ b/service/simulator/ramlparser/raml/jsonSchemaParser/Properties.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file Properties.h + * + * @brief This file provides data Model for Json Schema Properties. + */ + #ifndef PROPERTIES_H_ #define PROPERTIES_H_ @@ -30,73 +36,199 @@ #include "Items.h" #include "AllowedValues.h" #include "cJSON.h" +#include namespace RAML { + /** + * @class Properties + * @brief This class provides data Model for Json Schema Properties. + */ class Properties { public: - Properties(): m_min(INT_MAX), m_max(INT_MAX), m_multipleOf(INT_MAX) {} + /** + * Constructor of Properties. + */ + Properties(): m_min(INT_MAX), m_max(INT_MAX), m_multipleOf(INT_MAX), m_updateInterval(0), + m_unique(false), m_additionalItems(false) {} + + /** + * Constructor of Properties. + * + * @param name - Properties name as string. + */ Properties(const std::string &name) : m_name(name), m_min(INT_MAX), m_max(INT_MAX), - m_multipleOf(INT_MAX) {} + m_multipleOf(INT_MAX), m_updateInterval(0), m_unique(false), m_additionalItems(false) {} + /** + * This method is for getting Name from Properties. + * + * @return Properties name as string + */ inline std::string getName(void) const { return m_name; } + + /** + * This method is for setting name to Properties + * + * @param name - Properties name as string. + */ inline void setName(const std::string &name) { m_name = name; } + + /** + * This method is for getting Value from Properties. + * + * @return Properties Value + */ template T getValue() const { - T val = T(); return boost::get(m_value); } + /** + * This method is for getting Value from Properties. + * + * @return Properties Value + */ ValueVariant &getValue() { return m_value; } + /** + * This method is for getting ValueVariant type from Properties. + * + * @return Properties Value type as Int + */ int getValueType() const { return m_value.which(); } + + /** + * This method is for getting ValueVariant type from Properties. + * + * @return Properties VariantType type + */ + VariantType getVariantType() const + { + if (m_value.which() == 3) + return VariantType::STRING; + else if (m_value.which() == 2) + return VariantType::BOOL; + else if (m_value.which() == 1) + return VariantType::DOUBLE; + else + return VariantType::INT; + } + + /** + * This method is for getting Value type as Integer from Properties. + * + * @return Properties Value type as Integer + */ int getValueInt() { return boost::lexical_cast (m_value); } + + /** + * This method is for getting Value type as String from Properties. + * + * @return Properties Value type as String + */ std::string getValueString() { return boost::lexical_cast (m_value); } + /** + * This method is for getting Value type as double from Properties. + * + * @return Properties Value type as double + */ + double getValueDouble() + { + return boost::lexical_cast (m_value); + } + + /** + * This method is for getting Value type as bool from Properties. + * + * @return Properties Value type as bool + */ + bool getValueBool() + { + return boost::lexical_cast (m_value); + } + + /** + * This method is for setting Value to Properties + * + * @param value - Properties Value. + */ template void setValue(const T &value) { m_value = value; } + + /** + * This method is for getting Range from Properties. + * + * @param min - reference to hold Minimum value of Properties. + * @param max - reference to hold Maximum value of Properties. + * @param multipleOf - reference to hold multipleOf value of Properties. + */ inline void getRange(int &min, int &max, int &multipleOf) const { min = m_min; max = m_max; multipleOf = m_multipleOf; } + + /** + * This method is for setting Minimum to Properties + * + * @param min - Minimum value of Properties. + */ inline void setMin(const int &min) { m_min = min; } + + /** + * This method is for setting Maximum to Properties + * + * @param max - Maximum value of Properties. + */ inline void setMax(const int &max) { m_max = max; } + + /** + * This method is for setting multipleOf to Properties + * + * @param multipleOf - multipleOf value of Properties. + */ inline void setMultipleOf(const int &multipleOf) { m_multipleOf = multipleOf; } + /** + * This method is for setting AllowedValues to Properties + * + * @param values - list of AllowedValues of Properties. + */ template bool setAllowedValues(const std::vector &values) { @@ -109,87 +241,225 @@ namespace RAML m_allowedValues.addValues(values); return true; } + + /** + * This method is for getting size of AllowedValues from Properties. + * + * @return size of AllowedValues + */ inline int getAllowedValuesSize() const { return m_allowedValues.size(); } + + /** + * This method is for getting AllowedValues from Properties. + * + * @return list of AllowedValues of Properties. + */ inline std::vector getAllowedValues() { return m_allowedValues.getValues(); } + + /** + * This method is for getting AllowedValues as integer from Properties. + * + * @return list of AllowedValues as integer + */ inline std::vector getAllowedValuesInt() { return m_allowedValues.getValuesInt(); } + + /** + * This method is for getting AllowedValues as String from Properties. + * + * @return list of AllowedValues as String + */ inline std::vector getAllowedValuesString() { return m_allowedValues.getValuesString(); } + + /** + * This method is for getting AllowedValues as Double from Properties. + * + * @return list of AllowedValues as Double + */ + inline std::vector getAllowedValuesDouble() + { + return m_allowedValues.getValuesDouble(); + } + + /** + * This method is for getting AllowedValues as Bool from Properties. + * + * @return list of AllowedValues as Bool + */ + inline std::vector getAllowedValuesBool() + { + return m_allowedValues.getValuesBool(); + } + + /** + * This method is for setting Description to Properties + * + * @param description - Description as string. + */ inline void setDescription(const std::string &description) { m_description = description; } + + /** + * This method is for getting Description from Properties. + * + * @return Description as string + */ inline std::string getDescription() { return m_description; } + + /** + * This method is for getting UpdateFrequency from Properties. + * + * @return UpdateFrequency as int + */ inline int getUpdateFrequencyTime() { return m_updateInterval; } + + /** + * This method is for setting UpdateFrequency to Properties + * + * @param interval - UpdateFrequency as int. + */ inline void setUpdateFrequencyTime(int interval) { m_updateInterval = interval; } + + /** + * This method is for setting Type to Properties + * + * @param type - Type as string. + */ void setType(const std::string &type) { m_type = type; } + + /** + * This method is for getting Type from Properties. + * + * @return Type as string + */ std::string getType() { return m_type; } + + /** + * This method is for setting Pattern to Properties + * + * @param pattern - Pattern as string. + */ void setPattern(const std::string &pattern) { m_pattern = pattern; } + + + /** + * This method is for getting Pattern from Properties. + * + * @return Pattern as string + */ std::string getPattern() { return m_pattern; } + + /** + * This method is for setting Format to Properties + * + * @param format - Format as string. + */ void setFormat(const std::string &format) { m_format = format; } + + /** + * This method is for getting Format from Properties. + * + * @return Format as string + */ std::string getFormat() { return m_format; } - void setItem(Items *item) + + /** + * This method is for setting Items to Properties + * + * @param item - pointer to Items + */ + void setItem(const ItemsPtr &item) { m_items.push_back(item); } - std::vector getItems() + + /** + * This method is for getting Items from Properties. + * + * @return list of pointer to Items + */ + std::vector const &getItems() const { return m_items; } + + /** + * This method is for setting Unique to Properties + * + * @param value - Unique as bool + */ void setUnique( int value) { if (value == cJSON_True) m_unique = true; else m_unique = false; } + /** + * This method is for getting isUnique from Properties. + * + * @return isUnique as bool + */ bool getUnique() { return m_unique; } + /** + * This method is for setting AdditionalItems to Properties + * + * @param value - AdditionalItems as bool + */ void setAdditionalItems(int value) { if (value == cJSON_True) m_additionalItems = true; else m_additionalItems = false; } + /** + * This method is for getting AdditionalItems from Properties. + * + * @return AdditionalItems as bool + */ bool getAdditionalItems() { return m_additionalItems; @@ -197,8 +467,8 @@ namespace RAML private: std::string m_name; ValueVariant m_value; - int m_max; int m_min; + int m_max; int m_multipleOf; AllowedValues m_allowedValues; int m_updateInterval; @@ -208,8 +478,10 @@ namespace RAML std::string m_description; bool m_unique; bool m_additionalItems; - std::vector m_items; + std::vector m_items; }; + + /** PropertiesPtr - shared Ptr to Properties.*/ typedef std::shared_ptr PropertiesPtr; } diff --git a/service/simulator/ramlparser/raml/model/AbstractParam.h b/service/simulator/ramlparser/raml/model/AbstractParam.h index 7aea032..dd33564 100755 --- a/service/simulator/ramlparser/raml/model/AbstractParam.h +++ b/service/simulator/ramlparser/raml/model/AbstractParam.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file AbstractParam.h + * + * @brief This file provides data Model for RAML AbstractParam. + */ + #ifndef ABSTRACT_PARAM_H #define ABSTRACT_PARAM_H @@ -30,53 +36,209 @@ namespace RAML { + /** + * @class AbstractParam + * @brief This class provides data Model for RAML AbstractParam. + */ class AbstractParam { public: + /** + * This method is for getting DefaultValue from AbstractParam. + * + * @return DefaultValue as string. + */ virtual std::string getDefaultValue() const; + + /** + * This method is for setting DefaultValue to AbstractParam. + * + * @param defaultValue - DefaultValue as string + */ virtual void setDefaultValue(const std::string &defaultValue); + /** + * This method is for getting Description from AbstractParam. + * + * @return Description as string. + */ virtual std::string getDescription() const; + + /** + * This method is for setting Description to AbstractParam. + * + * @param description - Description as string + */ virtual void setDescription(const std::string &description); + /** + * This method is for getting DisplayName from AbstractParam. + * + * @return DisplayName as string. + */ virtual std::string getDisplayName() const; + + /** + * This method is for setting DisplayName to AbstractParam. + * + * @param displayName - DisplayName as string + */ virtual void setDisplayName(const std::string &displayName); + /** + * This method is for getting Enumeration from AbstractParam. + * + * @return list of enumeration as string. + */ virtual std::list getEnumeration() const; + + /** + * This method is for setting Enumeration to AbstractParam. + * + * @param enumeration - Enumeration as string + */ virtual void setEnumeration(const std::string &enumeration); + /** + * This method is for getting Example from AbstractParam. + * + * @return Example as string. + */ virtual std::string getExample() const; + + /** + * This method is for setting Example to AbstractParam. + * + * @param example - Example as string + */ virtual void setExample(const std::string &example); + /** + * This method is for getting MaxLength from AbstractParam. + * + * @return MaxLength as int. + */ virtual int getMaxLength() const; + + /** + * This method is for setting MaxLength to AbstractParam. + * + * @param maxLength - MaxLength as int + */ virtual void setMaxLength(int maxLength); + /** + * This method is for getting Maximum from AbstractParam. + * + * @return Maximum as int. + */ virtual int getMaximum() const; + + /** + * This method is for setting Maximum to AbstractParam. + * + * @param maximum - Maximum as int + */ virtual void setMaximum(int maximum); + /** + * This method is for getting MinLength from AbstractParam. + * + * @return MinLength as int. + */ virtual int getMinLength() const; + + /** + * This method is for setting MinLength to AbstractParam. + * + * @param minLength - MinLength as int + */ virtual void setMinLength(int minLength); + /** + * This method is for getting Minimum from AbstractParam. + * + * @return Minimum as int. + */ virtual int getMinimum() const; + + /** + * This method is for setting Minimum to AbstractParam. + * + * @param minimum - Minimum as int + */ virtual void setMinimum(int minimum); + /** + * This method is for getting Pattern from AbstractParam. + * + * @return Pattern as string. + */ virtual std::string getPattern() const; + + /** + * This method is for setting Pattern to AbstractParam. + * + * @param pattern - Pattern as string + */ virtual void setPattern(const std::string &pattern) ; + /** + * This method is for getting Type from AbstractParam. + * + * @return Type as string. + */ virtual std::string getType() const; + + /** + * This method is for setting Type to AbstractParam. + * + * @param type - Type as string + */ virtual void setType(const std::string &type); + /** + * This method is for getting isRepeat from AbstractParam. + * + * @return isRepeat as bool. + */ virtual bool isRepeat() const; + + /** + * This method is for setting Repeat to AbstractParam. + * + * @param repeat - Repeat as bool + */ virtual void setRepeat(bool repeat); + /** + * This method is for getting isRequired from AbstractParam. + * + * @return isRequired as bool. + */ virtual bool isRequired() const; + + /** + * This method is for setting Required to AbstractParam. + * + * @param required - Required as bool + */ virtual void setRequired(bool required); + /** + * Constructor of AbstractParam. + */ + AbstractParam() : m_minimum(0), m_maximum(0), m_minLength(0), m_maxLength(0), + m_repeat(false), m_required(false) {} - AbstractParam() : m_maximum(0), m_minimum(0), m_minLength(0), m_maxLength(0), m_repeat(false), - m_required(false) {} - AbstractParam(const YAML::Node &yamlNode) : m_maximum(0), m_minimum(0), m_minLength(0), - m_maxLength(0), m_repeat(false), m_required(false) + /** + * Constructor of AbstractParam. + * + * @param yamlNode - Reference to YamlNode for reading the AbstractParam + * + */ + AbstractParam(const YAML::Node &yamlNode) : m_minimum(0), m_maximum(0), + m_minLength(0), m_maxLength(0), m_repeat(false), m_required(false) { readParameters(yamlNode); } @@ -89,10 +251,10 @@ namespace RAML std::string m_displayName; std::list m_enumeration; std::string m_example; - int m_maxLength; + int m_minimum; int m_maximum; int m_minLength; - int m_minimum; + int m_maxLength; std::string m_pattern; bool m_repeat; bool m_required; diff --git a/service/simulator/ramlparser/raml/model/Action.cpp b/service/simulator/ramlparser/raml/model/Action.cpp index 15c826a..2ff29ee 100755 --- a/service/simulator/ramlparser/raml/model/Action.cpp +++ b/service/simulator/ramlparser/raml/model/Action.cpp @@ -128,7 +128,8 @@ namespace RAML for ( YAML::const_iterator tt = responseNode.begin(); tt != responseNode.end(); ++tt ) { std::string responseCode = READ_NODE_AS_STRING(tt->first); - setResponse(responseCode, std::make_shared(tt->second, m_includeResolver)); + setResponse(responseCode, std::make_shared(tt->second, + m_includeResolver)); } } else if (key == Keys::Headers) @@ -144,7 +145,8 @@ namespace RAML YAML::Node paramNode = it->second; for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt ) { - setQueryParameter(READ_NODE_AS_STRING(tt->first), std::make_shared(tt->second)); + setQueryParameter(READ_NODE_AS_STRING(tt->first), + std::make_shared(tt->second)); } } else if (key == Keys::Protocols) @@ -160,7 +162,8 @@ namespace RAML YAML::Node paramNode = it->second; for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt ) { - setBaseUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared(tt->second)); + setBaseUriParameter(READ_NODE_AS_STRING(tt->first), + std::make_shared(tt->second)); } } else if (key == Keys::Body) @@ -170,7 +173,8 @@ namespace RAML for ( YAML::const_iterator tt = responseBody.begin(); tt != responseBody.end(); ++tt ) { std::string type = READ_NODE_AS_STRING(tt->first); - setRequestBody(type, std::make_shared(type, tt->second, m_includeResolver)); + setRequestBody(type, std::make_shared(type, tt->second, + m_includeResolver)); } } else if (key == Keys::IsTrait) diff --git a/service/simulator/ramlparser/raml/model/Action.h b/service/simulator/ramlparser/raml/model/Action.h index 348b476..6ee2abb 100755 --- a/service/simulator/ramlparser/raml/model/Action.h +++ b/service/simulator/ramlparser/raml/model/Action.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file Action.h + * + * @brief This file provides data Model for RAML Action. + */ + #ifndef ACTION_H #define ACTION_H @@ -35,44 +41,196 @@ namespace RAML { + /** + * @class Action + * @brief This class provides data Model for RAML Action. + */ class Action { public: + /** + * This method is for getting Type from Action. + * + * @return Type as string. + */ virtual ActionType getType() const; + + /** + * This method is for setting Type to Action. + * + * @param type - Type as string + */ virtual void setType(const ActionType &type); + + /** + * This method is for getting Description from Action. + * + * @return Description as string. + */ virtual std::string getDescription() const; + + /** + * This method is for setting Description to Action. + * + * @param description - Description as string + */ virtual void setDescription(const std::string &description); + + /** + * This method is for getting Header from Action. + * + * @return map of Header name and Pointer to Header. + */ virtual std::map const &getHeaders() const; + + /** + * This method is for setting Header to Action. + * + * @param headerName - Header name as string + * @param header - Pointer to Header + */ virtual void setHeader(const std::string &headerName, const HeaderPtr &header); + + /** + * This method is for getting QueryParameter from Action. + * + * @return map of QueryParameter name and Pointer to QueryParameter. + */ virtual std::map const &getQueryParameters()const; + + /** + * This method is for setting QueryParameter to Action. + * + * @param paramName - QueryParameter name as string + * @param queryParameter - Pointer to QueryParameter + */ virtual void setQueryParameter(const std::string ¶mName, const QueryParameterPtr &queryParameter); + /** + * This method is for getting RequestResponseBody from Action. + * + * @param bodyType - bodyType name as string + * + * @return Pointer to RequestResponseBody + */ virtual RequestResponseBodyPtr getRequestBody(const std::string &bodyType); + + /** + * This method is for getting RequestResponseBody from Action. + * + * @return map of RequestResponseBody name and Pointer to RequestResponseBody. + */ virtual std::map const &getRequestBody() const; + + /** + * This method is for setting RequestResponseBody to Action. + * + * @param typeName - RequestResponseBody name as string + */ virtual void setRequestBody(const std::string &typeName); - virtual void setRequestBody(const std::string &typeName , const RequestResponseBodyPtr &body); + /** + * This method is for setting Type to Action. + * + * @param typeName - RequestResponseBody name as string + * @param body - Pointer to RequestResponseBody + */ + virtual void setRequestBody(const std::string &typeName , + const RequestResponseBodyPtr &body); + + /** + * This method is for getting Response from Action. + * + * @param responseCode - Response code as string + * + * @return Pointer to Response + */ virtual ResponsePtr getResponse(const std::string &responseCode); + + /** + * This method is for getting Response from Action. + * + * @return map of response code and Pointer to Response + */ virtual std::map const &getResponses() const; + + /** + * This method is for setting Response to Action. + * + * @param responseCode - responseCode as string + * @param response - Pointer to Response + */ virtual void setResponse(const std::string &responseCode, const ResponsePtr &response); + + /** + * This method is for getting Protocols from Action. + * + * @return list of Protocols as string. + */ virtual std::list const &getProtocols() const; + + /** + * This method is for setting Protocols to Action. + * + * @param protocol - protocol as string + */ virtual void setProtocol(const std::string &protocol); + + /** + * This method is for getting BaseUriParameter from Action. + * + * @return map of BaseUriParameter name and pointer to UriParameter. + */ virtual std::map< std::string, UriParameterPtr > const &getBaseUriParameters() const; + + /** + * This method is for setting BaseUriParameter to Action. + * + * @param paramName - BaseUriParameter name as string + * @param baseUriParameter - pointer to UriParameter. + */ virtual void setBaseUriParameter(const std::string ¶mName , const UriParameterPtr &baseUriParameter); + + /** + * This method is for getting Traits from Action. + * + * @return list of traits as string. + */ virtual std::list const &getTraits() const; - virtual void setTrait(const std::string &trait); + /** + * This method is for setting Trait to Action. + * + * @param trait - trait as string + */ + virtual void setTrait(const std::string &trait); + /** + * Constructor of Action. + */ Action(): m_includeResolver(NULL) { } + + /** + * Constructor of Action. + * + * @param actionType - type of action in ActionType enum + * @param yamlNode - Reference to YamlNode for reading the Action + * @param includeResolver - Reference to IncludeResolver for reading external files + * + */ Action(const ActionType actionType, const YAML::Node &yamlNode, const IncludeResolverPtr &includeResolver) : m_includeResolver(includeResolver) { readAction(actionType, yamlNode); } - Action(const Action &action) = default; + + /** + * copy Constructor of Action. + */ + Action(const Action &) = default; private: virtual void readAction(const ActionType actionType, const YAML::Node &yamlNode); @@ -92,6 +250,7 @@ namespace RAML IncludeResolverPtr m_includeResolver; }; + /** ActionPtr - shared Ptr to Action.*/ typedef std::shared_ptr ActionPtr; } #endif diff --git a/service/simulator/ramlparser/raml/model/ActionType.h b/service/simulator/ramlparser/raml/model/ActionType.h index a653390..b529a54 100755 --- a/service/simulator/ramlparser/raml/model/ActionType.h +++ b/service/simulator/ramlparser/raml/model/ActionType.h @@ -18,11 +18,18 @@ * ******************************************************************/ +/** + * @file ActionType.h + * + * @brief This file provides data Model for RAML ActionType. + */ + #ifndef ACTION_TYPE_H #define ACTION_TYPE_H namespace RAML { + /** ActionType - This class provides data Model for RAML ActionType. */ enum class ActionType { GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS, TRACE, NONE diff --git a/service/simulator/ramlparser/raml/model/DocumentationItem.h b/service/simulator/ramlparser/raml/model/DocumentationItem.h index c708e52..dfc0ba8 100755 --- a/service/simulator/ramlparser/raml/model/DocumentationItem.h +++ b/service/simulator/ramlparser/raml/model/DocumentationItem.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file DocumentationItem.h + * + * @brief This file provides data Model for RAML DocumentationItem. + */ + #ifndef DOCUMENTATION_ITEM_H #define DOCUMENTATION_ITEM_H @@ -26,18 +32,56 @@ namespace RAML { + /** + * @class DocumentationItem + * @brief This class provides data Model for RAML DocumentationItem. + */ class DocumentationItem { public: + /** + * This method is for getting Title from DocumentationItem. + * + * @return title as string. + */ virtual std::string getTitle() const; + + /** + * This method is for setting Title to DocumentationItem. + * + * @param title - title as string + */ virtual void setTitle(const std::string &title); + + /** + * This method is for getting Content from DocumentationItem. + * + * @return content as string + */ virtual std::string getContent() const; + + /** + * This method is for setting Content to DocumentationItem. + * + * @param content - content as string + */ virtual void setContent(const std::string &content); + /** + * Constructor of DocumentationItem. + */ DocumentationItem(); - DocumentationItem(const std::string &title , const std::string &content) : m_title(title), - m_content(content) {} + + /** + * Constructor of Action. + * + * @param title - title of Documentation Item + * @param content - content of Documentation Item + * + */ + DocumentationItem(const std::string &title , const std::string &content) + : m_title(title), m_content(content) {} private: std::string m_title; std::string m_content; diff --git a/service/simulator/ramlparser/raml/model/FormParameter.h b/service/simulator/ramlparser/raml/model/FormParameter.h index 61d15f1..df416ce 100755 --- a/service/simulator/ramlparser/raml/model/FormParameter.h +++ b/service/simulator/ramlparser/raml/model/FormParameter.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file FormParameter.h + * + * @brief This file provides data Model for RAML FormParameter. + */ + #ifndef FORM_PARAMETER_H #define FORM_PARAMETER_H @@ -25,12 +31,28 @@ namespace RAML { + /** + * @class FormParameter + * @brief This class provides data Model for RAML FormParameter. + */ class FormParameter: public AbstractParam { public: + /** + * Constructor of FormParameter. + * + * @param yamlNode - Reference to YamlNode for reading the FormParameter + * + */ FormParameter(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {} + + /** + * Constructor of FormParameter. + */ FormParameter() {} }; + + /** FormParameterPtr - shared Ptr to FormParameter.*/ typedef std::shared_ptr FormParameterPtr; } diff --git a/service/simulator/ramlparser/raml/model/Header.h b/service/simulator/ramlparser/raml/model/Header.h index 3aca86b..c09cb99 100755 --- a/service/simulator/ramlparser/raml/model/Header.h +++ b/service/simulator/ramlparser/raml/model/Header.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file Header.h + * + * @brief This file provides data Model for RAML Header. + */ + #ifndef HEADER_PARAMETER_H #define HEADER_PARAMETER_H @@ -25,12 +31,28 @@ namespace RAML { + /** + * @class Header + * @brief This class provides data Model for RAML Header. + */ class Header: public AbstractParam { public: + /** + * Constructor of Header. + * + * @param yamlNode - Reference to YamlNode for reading the Header + * + */ Header(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {} + + /** + * Constructor of Header. + */ Header() {} }; + + /** HeaderPtr - shared Ptr to Header.*/ typedef std::shared_ptr
HeaderPtr; } diff --git a/service/simulator/ramlparser/raml/model/QueryParameter.h b/service/simulator/ramlparser/raml/model/QueryParameter.h index 1850614..ca2ab5d 100755 --- a/service/simulator/ramlparser/raml/model/QueryParameter.h +++ b/service/simulator/ramlparser/raml/model/QueryParameter.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file QueryParameter.h + * + * @brief This file provides data Model for RAML QueryParameter. + */ + #ifndef QUERY_PARAMETER_H #define QUERY_PARAMETER_H @@ -25,12 +31,28 @@ namespace RAML { + /** + * @class QueryParameter + * @brief This class provides data Model for RAML QueryParameter. + */ class QueryParameter: public AbstractParam { public: + /** + * Constructor of QueryParameter. + * + * @param yamlNode - Reference to YamlNode for reading the QueryParameter + * + */ QueryParameter(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {} + + /** + * Constructor of QueryParameter. + */ QueryParameter() {} }; + + /** QueryParameterPtr - shared Ptr to QueryParameter.*/ typedef std::shared_ptr QueryParameterPtr; } diff --git a/service/simulator/ramlparser/raml/model/Raml.cpp b/service/simulator/ramlparser/raml/model/Raml.cpp index 4e68999..d7dc0c4 100755 --- a/service/simulator/ramlparser/raml/model/Raml.cpp +++ b/service/simulator/ramlparser/raml/model/Raml.cpp @@ -62,7 +62,8 @@ namespace RAML { return m_baseUriParameters; } - void Raml::setBaseUriParameter(const std::string ¶mName, const UriParameterPtr &uriParameter) + void Raml::setBaseUriParameter(const std::string ¶mName, + const UriParameterPtr &uriParameter) { m_baseUriParameters[paramName] = uriParameter; } @@ -151,7 +152,8 @@ namespace RAML YAML::Node paramNode = it->second; for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt ) { - setBaseUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared(tt->second)); + setBaseUriParameter(READ_NODE_AS_STRING(tt->first), + std::make_shared(tt->second)); } } else if (key == Keys::Protocols) @@ -198,14 +200,18 @@ namespace RAML std::pair schema; IncludeResolver::FileType fileType = m_includeResolver->getFileType(tt->second); - if ((fileType == IncludeResolver::FileType::JSON) || (fileType == IncludeResolver::FileType::FILE)) + if ((fileType == IncludeResolver::FileType::JSON) || + (fileType == IncludeResolver::FileType::FILE)) { - setSchema(key, std::make_shared(m_includeResolver->readFromFile(tt->second), - m_includeResolver)); + setSchema(key, + std::make_shared(m_includeResolver->readFromFile(tt->second), + m_includeResolver)); } else { - setSchema(key, std::make_shared(READ_NODE_AS_STRING(tt->second), m_includeResolver)); + setSchema(key, + std::make_shared(READ_NODE_AS_STRING(tt->second), + m_includeResolver)); } } } @@ -213,7 +219,8 @@ namespace RAML else if (key.compare(0, Keys::Resource.length(), Keys::Resource) == 0) { - setResource(key, std::make_shared(key, it->second, m_includeResolver, getBaseUri())); + setResource(key, std::make_shared(key, it->second, m_includeResolver, + getBaseUri())); } else if (key == Keys::Traits) { @@ -223,7 +230,8 @@ namespace RAML for (auto elem : *tt) { std::string trait = READ_NODE_AS_STRING(elem.first); - setTrait(trait, std::make_shared(ActionType::NONE, elem.second , m_includeResolver)); + setTrait(trait, std::make_shared(ActionType::NONE, elem.second , + m_includeResolver)); } } } @@ -235,7 +243,8 @@ namespace RAML for (auto elem : *tt) { std::string type = READ_NODE_AS_STRING(elem.first); - setResourceType(type, std::make_shared(type, elem.second, m_includeResolver, + setResourceType(type, std::make_shared(type, elem.second, + m_includeResolver, getBaseUri())); } diff --git a/service/simulator/ramlparser/raml/model/Raml.h b/service/simulator/ramlparser/raml/model/Raml.h index 6c7454a..f90fdea 100755 --- a/service/simulator/ramlparser/raml/model/Raml.h +++ b/service/simulator/ramlparser/raml/model/Raml.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file Raml.h + * + * @brief This file provides data Model for RAML file. + */ + #ifndef RAML_H #define RAML_H @@ -48,48 +54,208 @@ namespace RAML { + /** + * @class Raml + * @brief This class provides data Model for RAML file. + */ class Raml { public: + /** + * This method is for getting Title from Raml. + * + * @return Title as string. + */ virtual std::string getTitle() const; + + /** + * This method is for setting Title to Raml. + * + * @param title - Title as string + */ virtual void setTitle(const std::string &title); + /** + * This method is for getting Version from Raml. + * + * @return Version as string. + */ virtual std::string getVersion() const; + + /** + * This method is for setting Version to Raml. + * + * @param version - Version as string + */ virtual void setVersion(const std::string &version); + /** + * This method is for getting BaseUri from Raml. + * + * @return BaseUri as string. + */ virtual std::string getBaseUri() const; + + /** + * This method is for setting BaseUri to Raml. + * + * @param baseUri - BaseUri as string + */ virtual void setBaseUri(const std::string &baseUri); + /** + * This method is for getting Protocols from Raml. + * + * @return list of Protocols as string. + */ virtual std::list const &getProtocols() const; + + /** + * This method is for setting Protocols to Raml. + * + * @param protocol - Protocol as string + */ virtual void setProtocol(const std::string &protocol); + /** + * This method is for getting BaseUriParameter from Raml. + * + * @return map of BaseUriParameter name and Pointer to UriParameter. + */ virtual std::map const &getBaseUriParameters() const; - virtual void setBaseUriParameter(const std::string ¶mName, const UriParameterPtr &uriParameter); + /** + * This method is for setting BaseUriParameter to Raml. + * + * @param paramName - name of BaseUriParameter as string + * @param uriParameter - pointer to UriParameter + */ + virtual void setBaseUriParameter(const std::string ¶mName, + const UriParameterPtr &uriParameter); + + + /** + * This method is for getting MediaType from Raml. + * + * @return Title as string. + */ virtual std::string getMediaType() const; + + /** + * This method is for setting MediaType to Raml. + * + * @param mediaType - MediaType as string + */ virtual void setMediaType(const std::string &mediaType); + /** + * This method is for getting Schemas from Raml. + * + * @return list of Schemas name and Pointer to Schema as pair. + */ virtual std::list > const &getSchemas() const; + + /** + * This method is for setting Schemas to Raml. + * + * @param schemaName - name of schema as string + * @param schema - pointer to Schema + */ virtual void setSchema(const std::string &schemaName, const SchemaPtr &schema); + /** + * This method is for getting ResourceTypes from Raml. + * + * @return list of ResourceTypes name and Pointer to RamlResource as pair. + */ virtual std::list > const &getResourceTypes() const; - virtual void setResourceType(const std::string &typeName, const RamlResourcePtr &resourceType); + /** + * This method is for setting ResourceTypes to Raml. + * + * @param typeName - name of ResourceType as string + * @param resourceType - pointer to RamlResource + */ + virtual void setResourceType(const std::string &typeName, + const RamlResourcePtr &resourceType); + + /** + * This method is for getting Traits from Raml. + * + * @return list of Traits name and Pointer to Action as pair. + */ virtual std::list > const &getTraits() const; + + /** + * This method is for setting Traits to Raml. + * + * @param traitName - name of Trait as string + * @param trait - pointer to Action + */ virtual void setTrait(const std::string &traitName, const ActionPtr &trait); + /** + * This method is for getting Resource from Raml. + * + * @param resourceName - name of Resource as string + * + * @return Pointer to Resource + */ virtual RamlResourcePtr getResource(const std::string &resourceName); + + /** + * This method is for getting Resource from Raml. + * + * @return map of Resource name and Pointer to Resource + */ virtual std::map const &getResources() const; - virtual void setResource(const std::string &resourceKey, const RamlResourcePtr &resource); + /** + * This method is for setting Resource to Raml. + * + * @param resourceKey - name of Resource as string + * @param resource - pointer to Resource + */ + virtual void setResource(const std::string &resourceKey, + const RamlResourcePtr &resource); + + /** + * This method is for setting DocumentationItem to Raml. + * + * @param documentationItem - pointer to DocumentationItem + */ virtual void setDocumentationItem(const std::shared_ptr &documentationItem); + + /** + * This method is for getting DocumentationItem from Raml. + * + * @return list of DocumentationItem + */ virtual std::list > const &getDocumentation() const; + /** + * This method is for setting Raml object reading from Yaml nodes + * + * @param yamlNode - Reference to YamlNode for reading into Raml object + */ void readRamlFromYaml(const YAML::Node &yamlNode); + + /** + * Constructor of Raml. + */ Raml() : m_includeResolver(std::make_shared()) {} - Raml(const std::string &fileLocation, - const std::string &ramlName) : m_includeResolver(std::make_shared(fileLocation)) + + /** + * Constructor of Raml. + * + * @param fileLocation - RAML configuration file path. + * @param ramlName - RAML configuration file Name + * + * NOTE: Constructor would throw RamlException if any error occured. + */ + Raml(const std::string &fileLocation, const std::string &ramlName) + : m_includeResolver(std::make_shared(fileLocation)) { try { @@ -128,6 +294,7 @@ namespace RAML IncludeResolverPtr m_includeResolver; }; + /** RamlPtr - shared Ptr to Raml.*/ typedef std::shared_ptr RamlPtr; } diff --git a/service/simulator/ramlparser/raml/model/RamlResource.cpp b/service/simulator/ramlparser/raml/model/RamlResource.cpp index 66fc2fc..ecee418 100755 --- a/service/simulator/ramlparser/raml/model/RamlResource.cpp +++ b/service/simulator/ramlparser/raml/model/RamlResource.cpp @@ -128,18 +128,21 @@ namespace RAML setDisplayName(READ_NODE_AS_STRING(it->second)); else if (key == Keys::Description) setDescription(READ_NODE_AS_STRING(it->second)); - else if (std::find(Keys::ActionType.begin(), Keys::ActionType.end(), key) != Keys::ActionType.end()) + else if (std::find(Keys::ActionType.begin(), Keys::ActionType.end(), key) != + Keys::ActionType.end()) { ActionType actionType = GET_ACTION_TYPE(key); - setAction(actionType, std::make_shared(actionType, it->second, m_includeResolver)); + setAction(actionType, std::make_shared(actionType, it->second, + m_includeResolver)); } else if (key == Keys::UriParameters) { YAML::Node paramNode = it->second; for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt ) { - setUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared(tt->second)); + setUriParameter(READ_NODE_AS_STRING(tt->first), + std::make_shared(tt->second)); } } else if (key == Keys::BaseUriParameters) @@ -147,7 +150,8 @@ namespace RAML YAML::Node paramNode = it->second; for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt ) { - setBaseUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared(tt->second)); + setBaseUriParameter(READ_NODE_AS_STRING(tt->first), + std::make_shared(tt->second)); } } else if (key == Keys::IsTrait) diff --git a/service/simulator/ramlparser/raml/model/RamlResource.h b/service/simulator/ramlparser/raml/model/RamlResource.h index c7acf78..cac949d 100755 --- a/service/simulator/ramlparser/raml/model/RamlResource.h +++ b/service/simulator/ramlparser/raml/model/RamlResource.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file RamlResource.h + * + * @brief This file provides data Model for RAML RamlResource. + */ + #ifndef RESOURCE_H #define RESOURCE_H @@ -32,44 +38,189 @@ namespace RAML { + /** + * @class RamlResource + * @brief This class provides data Model for RAML RamlResource. + */ class RamlResource { public: + /** + * This method is for getting DisplayName from RamlResource. + * + * @return DisplayName as string. + */ virtual std::string getDisplayName() const; + + /** + * This method is for setting DisplayName to RamlResource. + * + * @param displayName - DisplayName as string + */ virtual void setDisplayName(const std::string &displayName); + /** + * This method is for getting Description from RamlResource. + * + * @return Description as string. + */ virtual std::string getDescription() const; + + /** + * This method is for setting Description to RamlResource. + * + * @param description - Description as string + */ virtual void setDescription(const std::string &description); + /** + * This method is for getting ParentUri from RamlResource. + * + * @return ParentUri as string. + */ virtual std::string getParentUri() const; + + /** + * This method is for setting ParentUri to RamlResource. + * + * @param parentUri - ParentUri as string + */ virtual void setParentUri(const std::string &parentUri); + /** + * This method is for getting RelativeUri from RamlResource. + * + * @return RelativeUri as string. + */ virtual std::string getRelativeUri() const; + + /** + * This method is for setting RelativeUri to RamlResource. + * + * @param relativeUri - RelativeUri as string + */ virtual void setRelativeUri(const std::string &relativeUri); + /** + * This method is for getting UriParameter from RamlResource. + * + * @return map of UriParameter name and Pointer to UriParameter. + */ virtual std::map const &getUriParameters() const; + + /** + * This method is for setting UriParameter to RamlResource. + * + * @param paramName - name of UriParameter as string + * @param uriParameter - pointer to UriParameter + */ virtual void setUriParameter(const std::string ¶mName, const UriParameterPtr &uriParameter); + /** + * This method is for getting BaseUriParameter from RamlResource. + * + * @return map of BaseUriParameter name and Pointer to UriParameter. + */ virtual std::map const &getBaseUriParameters() const; + + /** + * This method is for setting BaseUriParameter to RamlResource. + * + * @param paramName - name of BaseUriParameter as string + * @param baseUriParameter - pointer to UriParameter + */ virtual void setBaseUriParameter(const std::string ¶mName, const UriParameterPtr &baseUriParameter); + /** + * This method is for getting Action from RamlResource. + * + * @param actionType - type of action as ActionType + * + * @return Pointer to Action. + */ virtual ActionPtr getAction(ActionType actionType); + + /** + * This method is for getting Action from RamlResource. + * + * @return map of ActionType and Pointer to Action. + */ virtual std::map const &getActions() const; + + /** + * This method is for setting Action to RamlResource. + * + * @param actiontype - type of action + * @param action - pointer to Action + */ virtual void setAction(const ActionType &actiontype , const ActionPtr &action ); + /** + * This method is for getting child Resource from RamlResource. + * + * @return map of Resource name and Pointer to RamlResource. + */ virtual std::map > const &getResources() const; + + /** + * This method is for setting child Resource to RamlResource. + * + * @param resourceName - name of Resource as string + * @param resources - pointer to RamlResource + */ virtual void setResource(const std::string &resourceName, const std::shared_ptr &resources); + /** + * This method is for getting Traits from RamlResource. + * + * @return list of Traits name. + */ virtual std::list const &getTraits() const; + + /** + * This method is for setting Traits to RamlResource. + * + * @param trait - name of Traits + */ virtual void setTrait(const std::string &trait); + /** + * This method is for getting ResourceType from RamlResource. + * + * @return ResourceType name. + */ virtual std::string getResourceType() const; + + /** + * This method is for setting ResourceType to RamlResource. + * + * @param type - name of ResourceType + */ virtual void setResourceType(const std::string &type); + /** + * This method is for getting ResourceUri from RamlResource. + * + * @return ResourceUri as string. + */ virtual std::string getResourceUri() const; + + /** + * Constructor of RamlResource. + */ RamlResource(): m_includeResolver(NULL) {} + + /** + * Constructor of RamlResource. + * + * @param resourceKey - name of the Resource + * @param yamlNode - Reference to YamlNode for reading the RamlResource + * @param includeResolver - Reference to IncludeResolver for reading external files + * @param parentUri - Uri of the Parent to form the Absolute Uri + * + */ RamlResource(const std::string resourceKey, const YAML::Node &yamlNode , const IncludeResolverPtr &includeResolver, const std::string &parentUri) : m_includeResolver(includeResolver) @@ -93,6 +244,7 @@ namespace RAML IncludeResolverPtr m_includeResolver; }; + /** RamlResourcePtr - shared Ptr to RamlResource.*/ typedef std::shared_ptr RamlResourcePtr; } #endif diff --git a/service/simulator/ramlparser/raml/model/RequestResponseBody.cpp b/service/simulator/ramlparser/raml/model/RequestResponseBody.cpp index e96226a..a140cee 100755 --- a/service/simulator/ramlparser/raml/model/RequestResponseBody.cpp +++ b/service/simulator/ramlparser/raml/model/RequestResponseBody.cpp @@ -67,9 +67,11 @@ namespace RAML if (key == Keys::Schema) { IncludeResolver::FileType fileType = m_includeResolver->getFileType(it->second); - if ((fileType == IncludeResolver::FileType::JSON) || (fileType == IncludeResolver::FileType::FILE)) + if ((fileType == IncludeResolver::FileType::JSON) || + (fileType == IncludeResolver::FileType::FILE)) { - setSchema(std::make_shared(m_includeResolver->readFromFile(it->second), m_includeResolver)); + setSchema(std::make_shared(m_includeResolver->readFromFile(it->second), + m_includeResolver)); } else { @@ -84,7 +86,8 @@ namespace RAML YAML::Node paramNode = it->second; for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt ) { - setFormParameter(READ_NODE_AS_STRING(tt->first), std::make_shared(tt->second)); + setFormParameter(READ_NODE_AS_STRING(tt->first), + std::make_shared(tt->second)); } } } diff --git a/service/simulator/ramlparser/raml/model/RequestResponseBody.h b/service/simulator/ramlparser/raml/model/RequestResponseBody.h index 7b2956e..78aaee9 100755 --- a/service/simulator/ramlparser/raml/model/RequestResponseBody.h +++ b/service/simulator/ramlparser/raml/model/RequestResponseBody.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file RequestResponseBody.h + * + * @brief This file provides data Model for RAML RequestResponseBody. + */ + #ifndef REQUEST_RESPONSE_BODY_H #define REQUEST_RESPONSE_BODY_H @@ -30,25 +36,101 @@ namespace RAML { + /** + * @class RequestResponseBody + * @brief This class provides data Model for RAML RequestResponseBody. + */ class RequestResponseBody { public: + /** + * This method is for getting Type from RequestResponseBody. + * + * @return type as string. + */ virtual std::string getType() const; + + /** + * This method is for setting Type to RequestResponseBody. + * + * @param type - type of RequestResponseBody + */ virtual void setType(const std::string &type); + + /** + * This method is for getting Schema from RequestResponseBody. + * + * @return pointer to Schema. + */ virtual SchemaPtr const &getSchema() const; + + /** + * This method is for setting Schema to RequestResponseBody. + * + * @param schema - pointer to Schema + */ virtual void setSchema(const SchemaPtr &schema); + + /** + * This method is for getting Example from RequestResponseBody. + * + * @return Example as string. + */ virtual std::string getExample() const; + + /** + * This method is for setting Example to RequestResponseBody. + * + * @param example - Example as string + */ virtual void setExample(const std::string &example); + + /** + * This method is for getting FormParameter from RequestResponseBody. + * + * @return map of pointer to param Name and pointer to FormParameter. + */ virtual std::map const &getFormParameters() const; - virtual void setFormParameter(const std::string ¶mName, const FormParameterPtr &formParameter); + + /** + * This method is for setting FormParameter to RequestResponseBody. + * + * @param paramName - Name of FormParameter + * @param formParameter - pointer to FormParameter + */ + virtual void setFormParameter(const std::string ¶mName, + const FormParameterPtr &formParameter); + + /** + * Constructor of RequestResponseBody. + */ RequestResponseBody(): m_schema(NULL), m_includeResolver(NULL) {} + + /** + * Constructor of RequestResponseBody. + * + * @param type - type of request response body + * + */ RequestResponseBody(const std::string type) : m_type(type), m_schema(NULL), m_includeResolver(NULL) {} + + /** + * Constructor of RequestResponseBody. + * + * @param type - type of request response body + * @param yamlNode - Reference to YamlNode for reading the RequestResponseBody + * @param includeResolver - Reference to IncludeResolver for reading external files + * + */ RequestResponseBody(const std::string type, const YAML::Node &yamlNode, - const IncludeResolverPtr &includeResolver): m_schema(NULL), m_includeResolver(includeResolver) { readRequestResponseBody(type, yamlNode); } + const IncludeResolverPtr &includeResolver): m_schema(NULL), + m_includeResolver(includeResolver) + { readRequestResponseBody(type, yamlNode); } private: - virtual void readRequestResponseBody(const std::string &type, const YAML::Node &yamlNode) ; + virtual void readRequestResponseBody(const std::string &type, + const YAML::Node &yamlNode) ; private: std::string m_type; SchemaPtr m_schema; @@ -57,6 +139,7 @@ namespace RAML IncludeResolverPtr m_includeResolver; }; + /** RequestResponseBodyPtr - shared Ptr to RequestResponseBody.*/ typedef std::shared_ptr RequestResponseBodyPtr; } #endif diff --git a/service/simulator/ramlparser/raml/model/Response.cpp b/service/simulator/ramlparser/raml/model/Response.cpp index cbd1433..4897dc4 100755 --- a/service/simulator/ramlparser/raml/model/Response.cpp +++ b/service/simulator/ramlparser/raml/model/Response.cpp @@ -71,7 +71,8 @@ namespace RAML for ( YAML::const_iterator tt = responseBody.begin(); tt != responseBody.end(); ++tt ) { std::string type = READ_NODE_AS_STRING(tt->first); - setResponseBody(type, std::make_shared(type, tt->second, m_includeResolver)); + setResponseBody(type, std::make_shared(type, tt->second, + m_includeResolver)); } } else if (key == Keys::Headers) diff --git a/service/simulator/ramlparser/raml/model/Response.h b/service/simulator/ramlparser/raml/model/Response.h index 92c09db..5d3ed62 100755 --- a/service/simulator/ramlparser/raml/model/Response.h +++ b/service/simulator/ramlparser/raml/model/Response.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file Response.h + * + * @brief This file provides data Model for RAML Response. + */ + #ifndef RESPONSE_H #define RESPONSE_H @@ -31,22 +37,88 @@ namespace RAML { + /** + * @class Response + * @brief This class provides data Model for RAML Response. + */ class Response { public: + /** + * This method is for getting Headers from Response. + * + * @return map of headerName and Pointer to Header. + */ virtual std::map const &getHeaders() const; + + /** + * This method is for setting Header to Response. + * + * @param headerName - header Name + * @param header - pointer to Header Object. + */ virtual void setHeader(const std::string &headerName, const HeaderPtr &header); + + /** + * This method is for getting Description from Response. + * + * @return Description string. + */ virtual std::string getDescription() const; + + /** + * This method is for setting Description to Response. + * + * @param description - description string + */ virtual void setDescription(const std::string &description); + + /** + * This method is for setting ResponseBody to Response. + * + * @param typeName - response body typeName + */ virtual void setResponseBody(const std::string &typeName); + + /** + * This method is for setting ResponseBody to Response. + * + * @param type - response body typeName + * @param body - Pointer to RequestResponseBody + */ virtual void setResponseBody(const std::string &type, const RequestResponseBodyPtr &body) ; + + /** + * This method is for getting ResponseBody from Response. + * + * @return map of body type and Pointer to RequestResponseBody. + */ virtual std::map const &getResponseBody() const; - virtual RequestResponseBodyPtr getResponseBody(const std::string &bodyType); + /** + * This method is for getting ResponseBody from Response. + * + * @param bodyType - response body type + * + * @return Pointer to RequestResponseBody. + */ + virtual RequestResponseBodyPtr getResponseBody(const std::string &bodyType); + /** + * Constructor of Response. + */ Response() : m_includeResolver(NULL) {} + + /** + * Constructor of Response. + * + * @param yamlNode - Reference to YamlNode for reading the Response + * @param includeResolver - Reference to IncludeResolver for reading external files + * + */ Response(const YAML::Node &yamlNode, - const IncludeResolverPtr &includeResolver): m_includeResolver(includeResolver) { readResponse(yamlNode);} + const IncludeResolverPtr &includeResolver): m_includeResolver(includeResolver) + { readResponse(yamlNode);} private: void readResponse(const YAML::Node &yamlNode) ; private: @@ -55,6 +127,8 @@ namespace RAML std::map m_headers; IncludeResolverPtr m_includeResolver; }; + + /** ResponsePtr - shared Ptr to Response.*/ typedef std::shared_ptr ResponsePtr; } #endif diff --git a/service/simulator/ramlparser/raml/model/Schema.h b/service/simulator/ramlparser/raml/model/Schema.h index e38be93..c1c95d3 100755 --- a/service/simulator/ramlparser/raml/model/Schema.h +++ b/service/simulator/ramlparser/raml/model/Schema.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file Schema.h + * + * @brief This file provides data Model for RAML Schema. + */ + #ifndef SCHEMAS_H #define SCHEMAS_H @@ -29,28 +35,79 @@ namespace RAML { + /** + * @class Schema + * @brief This class provides data Model for RAML Schema. + */ class Schema { public: + /** + * This method is for getting CJson object of schema. + * + * @return pointer to cJSON. + */ virtual cJSON *getJson() const; + + /** + * This method is for setting schema as CJson object. + * + * @param cjson - Cjson pointer. + */ virtual void setJson(cJSON *cjson); + + /** + * This method is for getting schema as string. + * + * @return string. + */ virtual std::string getSchema() const; + + /** + * This method is for setting schema as string. + * + * @param schema - schema string. + */ virtual void setSchema(const std::string &schema); + + /** + * This method is for getting Properties from JsonSchema. + * + * @return pointer to JsonSchema. + */ virtual JsonSchemaPtr const &getProperties() const; - Schema(const std::string &schema, const IncludeResolverPtr &includeResolver): m_schema(schema) , - m_cjson(cJSON_Parse(schema.c_str())), + /** + * Constructor of Schema. + * + * @param schema - contents of schema to be parsed + * @param includeResolver - Reference to IncludeResolver for reading external files + * + */ + Schema(const std::string &schema, const IncludeResolverPtr &includeResolver): + m_schema(schema) , m_cjson(cJSON_Parse(schema.c_str())), m_resProperties(std::make_shared(m_cjson, includeResolver) ) , m_includeResolver(includeResolver) {} - Schema(): m_cjson(NULL), m_includeResolver(NULL), m_resProperties(std::make_shared()) {} + + /** + * Constructor of Schema. + */ + Schema(): m_cjson(NULL), m_resProperties(std::make_shared()), + m_includeResolver(NULL) {} + + /** + * Destructor of Schema. + */ ~Schema() { cJSON_Delete(m_cjson); } private: - cJSON *m_cjson; std::string m_schema; + cJSON *m_cjson; JsonSchemaPtr m_resProperties; IncludeResolverPtr m_includeResolver; }; + + /** SchemaPtr - shared Ptr to Schema.*/ typedef std::shared_ptr SchemaPtr; } diff --git a/service/simulator/ramlparser/raml/model/UriParameter.h b/service/simulator/ramlparser/raml/model/UriParameter.h index 5f8d61e..c766db0 100755 --- a/service/simulator/ramlparser/raml/model/UriParameter.h +++ b/service/simulator/ramlparser/raml/model/UriParameter.h @@ -18,6 +18,12 @@ * ******************************************************************/ +/** + * @file UriParameter.h + * + * @brief This file provides data Model for RAML UriParameters. + */ + #ifndef URI_PARAMETER_H #define URI_PARAMETER_H @@ -25,12 +31,29 @@ namespace RAML { + /** + * @class UriParameter + * @brief This class provides data Model for RAML UriParameters. + */ class UriParameter: public AbstractParam { public: + /** + * Constructor of UriParameter. + * + * @param yamlNode - Reference to YamlNode for reading the UriParameter + * + */ UriParameter(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {} + + /** + * Constructor of UriParameter. + */ UriParameter() {} }; + + /** UriParameterPtr - shared Ptr to UriParameter.*/ + typedef std::shared_ptr UriParameterPtr; }