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
26 std::string Raml::getTitle() const
\r
30 void Raml::setTitle(const std::string &title)
\r
35 std::string Raml::getVersion() const
\r
39 void Raml::setVersion(const std::string &version)
\r
41 m_version = version;
\r
44 std::string Raml::getBaseUri() const
\r
48 void Raml::setBaseUri(const std::string &baseUri)
\r
50 m_baseUri = baseUri;
\r
53 std::list<std::string> const &Raml::getProtocols() const
\r
57 void Raml::setProtocol(const std::string &protocol)
\r
59 m_protocols.push_back(protocol);
\r
61 std::map<std::string, UriParameterPtr> const &Raml::getBaseUriParameters() const
\r
63 return m_baseUriParameters;
\r
65 void Raml::setBaseUriParameter(const std::string ¶mName, const UriParameterPtr &uriParameter)
\r
67 m_baseUriParameters[paramName] = uriParameter;
\r
70 std::string Raml::getMediaType() const
\r
74 void Raml::setMediaType(const std::string &mediaType)
\r
76 m_mediaType = mediaType;
\r
79 std::list<std::pair<std::string, SchemaPtr> > const &Raml::getSchemas() const
\r
84 void Raml::setSchema(const std::string &schemaName, const SchemaPtr &schema)
\r
86 m_schemas.push_back(std::make_pair(schemaName, schema));
\r
89 std::list<std::pair<std::string, RamlResourcePtr> > const &Raml::getResourceTypes() const
\r
91 return m_resourceTypes;
\r
93 void Raml::setResourceType(const std::string &typeName, const RamlResourcePtr &resourceType)
\r
95 m_resourceTypes.push_back(std::make_pair(typeName, resourceType));
\r
98 std::list<std::pair<std::string, ActionPtr> > const &Raml::getTraits() const
\r
102 void Raml::setTrait(const std::string &traitName, const ActionPtr &trait)
\r
104 m_traits.push_back(std::make_pair(traitName, trait));
\r
106 RamlResourcePtr Raml::getResource(const std::string &resourceName)
\r
108 return m_resources[resourceName];
\r
111 std::map<std::string, RamlResourcePtr> const &Raml::getResources() const
\r
113 return m_resources;
\r
116 void Raml::setResource(const std::string &resourceKey, const RamlResourcePtr &resource)
\r
118 m_resources[resourceKey] = resource;
\r
121 void Raml::setDocumentationItem(const std::shared_ptr<DocumentationItem> &documentationItem)
\r
123 m_documentation.push_back(documentationItem);
\r
126 std::list<std::shared_ptr<DocumentationItem> > const &Raml::getDocumentation() const
\r
128 return m_documentation;
\r
130 void Raml::readRamlFromYaml(const YAML::Node &yamlNode )
\r
132 if (yamlNode.Type() == YAML::NodeType::Map)
\r
134 for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )
\r
136 std::string key = READ_NODE_AS_STRING(it->first);
\r
137 if (key == Keys::Title)
\r
139 setTitle(READ_NODE_AS_STRING(it->second));
\r
141 else if (key == Keys::Version)
\r
143 setVersion(READ_NODE_AS_STRING(it->second));
\r
145 else if (key == Keys::BaseUri)
\r
147 setBaseUri(READ_NODE_AS_STRING(it->second));
\r
149 else if ((key == Keys::BaseUriParameters) || (key == Keys::UriParameters))
\r
151 YAML::Node paramNode = it->second;
\r
152 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )
\r
154 setBaseUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared<UriParameter>(tt->second));
\r
157 else if (key == Keys::Protocols)
\r
159 YAML::Node protocolNode = it->second;
\r
160 for ( YAML::const_iterator tt = protocolNode.begin(); tt != protocolNode.end(); ++tt )
\r
162 setProtocol(READ_NODE_AS_STRING(*tt));
\r
165 else if (key == Keys::MediaType)
\r
167 setMediaType(READ_NODE_AS_STRING(it->second));
\r
169 else if (key == Keys::Documentation)
\r
171 YAML::Node docNode = it->second;
\r
172 for ( YAML::const_iterator iit = docNode.begin(); iit != docNode.end(); ++iit )
\r
174 std::string title ;
\r
175 std::string content ;
\r
177 for ( YAML::const_iterator tt = (*iit).begin(); tt != (*iit).end(); ++tt )
\r
179 std::string key = READ_NODE_AS_STRING(tt->first);
\r
181 if (key == Keys::Title)
\r
182 title = READ_NODE_AS_STRING(tt->second);
\r
183 else if (key == Keys::Content)
\r
184 content = READ_NODE_AS_STRING(tt->second);
\r
187 setDocumentationItem(std::make_shared<DocumentationItem>(title, content));
\r
190 else if (key == Keys::Schemas)
\r
192 YAML::Node schemaNode = it->second;
\r
193 for ( YAML::const_iterator iit = schemaNode.begin(); iit != schemaNode.end(); ++iit )
\r
195 for ( YAML::const_iterator tt = (*iit).begin(); tt != (*iit).end(); ++tt )
\r
197 std::string key = READ_NODE_AS_STRING(tt->first);
\r
198 std::pair<std::string, Schema> schema;
\r
200 IncludeResolver::FileType fileType = m_includeResolver->getFileType(tt->second);
\r
201 if ((fileType == IncludeResolver::FileType::JSON) || (fileType == IncludeResolver::FileType::FILE))
\r
203 setSchema(key, std::make_shared<Schema>(m_includeResolver->readFromFile(tt->second),
\r
204 m_includeResolver));
\r
208 setSchema(key, std::make_shared<Schema>(READ_NODE_AS_STRING(tt->second), m_includeResolver));
\r
214 else if (key.compare(0, Keys::Resource.length(), Keys::Resource) == 0)
\r
216 setResource(key, std::make_shared<RamlResource>(key, it->second, m_includeResolver, getBaseUri()));
\r
218 else if (key == Keys::Traits)
\r
220 YAML::Node traitNode = it->second;
\r
221 for ( YAML::const_iterator tt = traitNode.begin(); tt != traitNode.end(); ++tt )
\r
223 for (auto elem : *tt)
\r
225 std::string trait = READ_NODE_AS_STRING(elem.first);
\r
226 setTrait(trait, std::make_shared<Action>(ActionType::NONE, elem.second , m_includeResolver));
\r
230 else if (key == Keys::ResourceTypes)
\r
232 YAML::Node typeNode = it->second;
\r
233 for ( YAML::const_iterator tt = typeNode.begin(); tt != typeNode.end(); ++tt )
\r
235 for (auto elem : *tt)
\r
237 std::string type = READ_NODE_AS_STRING(elem.first);
\r
238 setResourceType(type, std::make_shared<RamlResource>(type, elem.second, m_includeResolver,
\r