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
24 * @brief This file provides data Model for RAML file.
\r
33 #include "AbstractParam.h"
\r
34 #include "UriParameter.h"
\r
35 #include "QueryParameter.h"
\r
36 #include "FormParameter.h"
\r
39 #include "RequestResponseBody.h"
\r
40 #include "RamlResource.h"
\r
41 #include "ActionType.h"
\r
43 #include "Response.h"
\r
45 #include "IncludeResolver.h"
\r
47 #include "DocumentationItem.h"
\r
48 #include "yaml-cpp/yaml.h"
\r
49 #include "yaml-cpp/exceptions.h"
\r
50 #include "RamlExceptions.h"
\r
59 * @brief This class provides data Model for RAML file.
\r
65 * This method is for getting Title from Raml.
\r
67 * @return Title as string.
\r
69 virtual std::string getTitle() const;
\r
72 * This method is for setting Title to Raml.
\r
74 * @param title - Title as string
\r
76 virtual void setTitle(const std::string &title);
\r
79 * This method is for getting Version from Raml.
\r
81 * @return Version as string.
\r
83 virtual std::string getVersion() const;
\r
86 * This method is for setting Version to Raml.
\r
88 * @param version - Version as string
\r
90 virtual void setVersion(const std::string &version);
\r
93 * This method is for getting BaseUri from Raml.
\r
95 * @return BaseUri as string.
\r
97 virtual std::string getBaseUri() const;
\r
100 * This method is for setting BaseUri to Raml.
\r
102 * @param baseUri - BaseUri as string
\r
104 virtual void setBaseUri(const std::string &baseUri);
\r
107 * This method is for getting Protocols from Raml.
\r
109 * @return list of Protocols as string.
\r
111 virtual std::list<std::string> const &getProtocols() const;
\r
114 * This method is for setting Protocols to Raml.
\r
116 * @param protocol - Protocol as string
\r
118 virtual void setProtocol(const std::string &protocol);
\r
122 * This method is for getting BaseUriParameter from Raml.
\r
124 * @return map of BaseUriParameter name and Pointer to UriParameter.
\r
126 virtual std::map<std::string, UriParameterPtr> const &getBaseUriParameters() const;
\r
129 * This method is for setting BaseUriParameter to Raml.
\r
131 * @param paramName - name of BaseUriParameter as string
\r
132 * @param uriParameter - pointer to UriParameter
\r
134 virtual void setBaseUriParameter(const std::string ¶mName,
\r
135 const UriParameterPtr &uriParameter);
\r
139 * This method is for getting MediaType from Raml.
\r
141 * @return Title as string.
\r
143 virtual std::string getMediaType() const;
\r
146 * This method is for setting MediaType to Raml.
\r
148 * @param mediaType - MediaType as string
\r
150 virtual void setMediaType(const std::string &mediaType);
\r
153 * This method is for getting Schemas from Raml.
\r
155 * @return list of Schemas name and Pointer to Schema as pair.
\r
157 virtual std::list<std::pair<std::string, SchemaPtr> > const &getSchemas() const;
\r
160 * This method is for setting Schemas to Raml.
\r
162 * @param schemaName - name of schema as string
\r
163 * @param schema - pointer to Schema
\r
165 virtual void setSchema(const std::string &schemaName, const SchemaPtr &schema);
\r
168 * This method is for getting ResourceTypes from Raml.
\r
170 * @return list of ResourceTypes name and Pointer to RamlResource as pair.
\r
172 virtual std::list<std::pair<std::string, RamlResourcePtr> > const &getResourceTypes() const;
\r
175 * This method is for setting ResourceTypes to Raml.
\r
177 * @param typeName - name of ResourceType as string
\r
178 * @param resourceType - pointer to RamlResource
\r
180 virtual void setResourceType(const std::string &typeName,
\r
181 const RamlResourcePtr &resourceType);
\r
184 * This method is for getting Traits from Raml.
\r
186 * @return list of Traits name and Pointer to Action as pair.
\r
188 virtual std::list<std::pair<std::string, ActionPtr> > const &getTraits() const;
\r
191 * This method is for setting Traits to Raml.
\r
193 * @param traitName - name of Trait as string
\r
194 * @param trait - pointer to Action
\r
196 virtual void setTrait(const std::string &traitName, const ActionPtr &trait);
\r
199 * This method is for getting Resource from Raml.
\r
201 * @param resourceName - name of Resource as string
\r
203 * @return Pointer to Resource
\r
205 virtual RamlResourcePtr getResource(const std::string &resourceName);
\r
208 * This method is for getting Resource from Raml.
\r
210 * @return map of Resource name and Pointer to Resource
\r
212 virtual std::map<std::string, RamlResourcePtr> const &getResources() const;
\r
215 * This method is for setting Resource to Raml.
\r
217 * @param resourceKey - name of Resource as string
\r
218 * @param resource - pointer to Resource
\r
220 virtual void setResource(const std::string &resourceKey,
\r
221 const RamlResourcePtr &resource);
\r
224 * This method is for setting DocumentationItem to Raml.
\r
226 * @param documentationItem - pointer to DocumentationItem
\r
228 virtual void setDocumentationItem(const std::shared_ptr<DocumentationItem> &documentationItem);
\r
231 * This method is for getting DocumentationItem from Raml.
\r
233 * @return list of DocumentationItem
\r
235 virtual std::list<std::shared_ptr<DocumentationItem> > const &getDocumentation() const;
\r
238 * This method is for setting Raml object reading from Yaml nodes
\r
240 * @param yamlNode - Reference to YamlNode for reading into Raml object
\r
242 void readRamlFromYaml(const YAML::Node &yamlNode);
\r
245 * Constructor of Raml.
\r
247 Raml() : m_includeResolver(std::make_shared<IncludeResolver>()) {}
\r
250 * Constructor of Raml.
\r
252 * @param fileLocation - RAML configuration file path.
\r
253 * @param ramlName - RAML configuration file Name
\r
255 * NOTE: Constructor would throw RamlException if any error occured.
\r
257 Raml(const std::string &fileLocation, const std::string &ramlName)
\r
258 : m_includeResolver(std::make_shared<IncludeResolver>(fileLocation))
\r
262 YAML::Node yamlRootNode = YAML::LoadFile(fileLocation + ramlName);
\r
263 readRamlFromYaml(yamlRootNode);
\r
265 catch (YAML::ParserException &e)
\r
267 throw RamlParserException(e.mark, e.msg);
\r
269 catch (YAML::RepresentationException &e)
\r
271 throw RamlRepresentationException(e.mark, e.msg);
\r
273 catch (YAML::BadFile &e)
\r
275 throw RamlBadFile(e.mark, e.msg);
\r
277 catch (JsonException &e)
\r
283 std::string m_title;
\r
284 std::string m_version;
\r
285 std::string m_baseUri;
\r
286 std::list<std::string> m_protocols;
\r
287 std::map<std::string, UriParameterPtr> m_baseUriParameters;
\r
288 std::string m_mediaType;
\r
289 std::list <std::pair<std::string, SchemaPtr> > m_schemas;
\r
290 std::list <std::pair<std::string, RamlResourcePtr> > m_resourceTypes;
\r
291 std::list <std::pair<std::string, ActionPtr> > m_traits;
\r
292 std::map<std::string, RamlResourcePtr> m_resources;
\r
293 std::list<std::shared_ptr<DocumentationItem> > m_documentation;
\r
294 IncludeResolverPtr m_includeResolver;
\r
297 /** RamlPtr - shared Ptr to Raml.*/
\r
298 typedef std::shared_ptr<Raml> RamlPtr;
\r