1 /******************************************************************
\r
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
19 ******************************************************************/
\r
22 * @file RamlParser.h
\r
24 * @brief This file provides APIs for parsing Raml file.
\r
27 #ifndef RAML_PARSER_H
\r
28 #define RAML_PARSER_H
\r
30 #include "yaml-cpp/yaml.h"
\r
33 #include "RequestResponseBody.h"
\r
34 #include "RamlResource.h"
\r
36 #include "Response.h"
\r
38 #include "RamlErrorCodes.h"
\r
39 #include "yaml-cpp/exceptions.h"
\r
40 #include "RamlExceptions.h"
\r
46 * @brief This class provides a set of APIs for parsing Raml file.
\r
51 void setDataFromRoot();
\r
52 void setBodyDefaultMediaType(const std::map<std::string, RamlResourcePtr> &resource);
\r
53 void setBodySchema(const std::map<std::string, RamlResourcePtr> &resource);
\r
54 void setTypes(const std::map<std::string, RamlResourcePtr> &resource);
\r
55 void setTraits(const std::map<std::string, RamlResourcePtr> &resource);
\r
59 * This method is for getting the created and Parsed RAML object from RAML file.
\r
61 * @param result - Reference to RamlParserResult.
\r
63 * @return pointer to Raml shared object parsed.
\r
65 virtual RamlPtr getRamlPtr(RamlParserResult &result);
\r
68 * This method is for getting the created and Parsed RAML object from RAML file.
\r
70 * @return pointer to Raml shared object parsed.
\r
72 virtual RamlPtr getRamlPtr();
\r
75 * Constructor of RamlParser.
\r
77 * NOTE: Constructor would initialize the RamlParserResult with File Path Required
\r
79 RamlParser(): m_ramlPtr(std::make_shared<Raml>()),
\r
80 m_ramlParserResult(RAML_FILE_PATH_REQUIRED) {}
\r
83 * Constructor of RamlParser.
\r
85 * @param path - RAML configuration file path.
\r
87 * NOTE: Constructor would throw RamlBadFile when invalid arguments passed, and
\r
88 * RamlException if any other error occured.
\r
90 RamlParser(const std::string &path): m_ramlParserResult(RAML_PARSER_ERROR)
\r
92 if (path.length() > 0)
\r
94 std::size_t found = path.find_last_of("/\\");
\r
95 if (found < path.length())
\r
97 m_fileLocation = path.substr(0, found) + "/";
\r
98 m_ramlName = path.substr(found + 1);
\r
101 m_ramlPtr = std::make_shared<Raml>(m_fileLocation, m_ramlName);
\r
103 m_ramlParserResult = RAML_PARSER_OK;
\r
105 catch (RamlException &e)
\r
112 m_ramlParserResult = RAML_FILE_PATH_REQUIRED;
\r
113 throw RamlBadFile("Raml File Path incorrect");
\r
118 m_ramlParserResult = RAML_FILE_PATH_REQUIRED;
\r
119 throw RamlBadFile("Raml File Path required");
\r
125 std::string m_fileLocation;
\r
126 std::string m_ramlName;
\r
127 RamlParserResult m_ramlParserResult;
\r