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 utilities for RamlParser.
\r
30 #include "yaml-cpp/yaml.h"
\r
31 #include "ActionType.h"
\r
37 /** Title - Raml title key.*/
\r
38 const std::string Title = "title";
\r
39 /** Version - Raml Version key.*/
\r
40 const std::string Version = "version";
\r
41 /** BaseUri - Raml BaseUri key.*/
\r
42 const std::string BaseUri = "baseUri";
\r
43 /** Protocols - Raml Protocols key.*/
\r
44 const std::string Protocols = "protocols";
\r
45 /** MediaType - Raml MediaType key.*/
\r
46 const std::string MediaType = "mediaType";
\r
47 /** Schemas - Raml Schemas key.*/
\r
48 const std::string Schemas = "schemas";
\r
49 /** ResourceTypes - Raml ResourceTypes key.*/
\r
50 const std::string ResourceTypes = "resourceTypes";
\r
51 /** Traits - Raml Traits key.*/
\r
52 const std::string Traits = "traits";
\r
53 /** IsTrait - Raml is key.*/
\r
54 const std::string IsTrait = "is";
\r
56 /** Resource - Raml Resource key.*/
\r
57 const std::string Resource = "/";
\r
58 /** ActionType - Raml allowed ActionType key.*/
\r
59 const std::vector<std::string> ActionType = {"get", "post", "put", "delete",
\r
60 "head", "patch", "options", "trace"
\r
63 /** Responses - Raml Responses key.*/
\r
64 const std::string Responses = "responses";
\r
65 /** Body - Raml Body key.*/
\r
66 const std::string Body = "body";
\r
67 /** Schema - Raml Schema key.*/
\r
68 const std::string Schema = "schema";
\r
69 /** Example - Raml Example key.*/
\r
70 const std::string Example = "example";
\r
72 /** BaseUriParameters - Raml BaseUriParameters key.*/
\r
73 const std::string BaseUriParameters = "baseUriParameters";
\r
74 /** UriParameters - Raml UriParameters key.*/
\r
75 const std::string UriParameters = "uriParameters";
\r
76 /** Headers - Raml title Headers.*/
\r
77 const std::string Headers = "headers";
\r
78 /** QueryParameters - Raml QueryParameters key.*/
\r
79 const std::string QueryParameters = "queryParameters";
\r
80 /** FormParameters - Raml FormParameters key.*/
\r
81 const std::string FormParameters = "formParameters";
\r
82 /** DisplayName - Raml DisplayName key.*/
\r
83 const std::string DisplayName = "displayName";
\r
84 /** Description - Raml Description key.*/
\r
85 const std::string Description = "description";
\r
86 /** Type - Raml Type key.*/
\r
87 const std::string Type = "type";
\r
88 /** Enum - Raml Enum key.*/
\r
89 const std::string Enum = "enum";
\r
90 /** Pattern - Raml Pattern key.*/
\r
91 const std::string Pattern = "pattern";
\r
92 /** MinLength - Raml MinLength key.*/
\r
93 const std::string MinLength = "minLength";
\r
94 /** MaxLength - Raml MaxLength key.*/
\r
95 const std::string MaxLength = "maxLength";
\r
96 /** Minimum - Raml Minimum key.*/
\r
97 const std::string Minimum = "minimum";
\r
98 /** Maximum - Raml Maximum key.*/
\r
99 const std::string Maximum = "maximum";
\r
100 /** Repeat - Raml Repeat key.*/
\r
101 const std::string Repeat = "repeat";
\r
102 /** Required - Raml Required key.*/
\r
103 const std::string Required = "required";
\r
104 /** Default - Raml Default key.*/
\r
105 const std::string Default = "default";
\r
106 /** Title - Raml title key.*/
\r
108 /** Documentation - Raml Documentation key.*/
\r
109 const std::string Documentation = "documentation";
\r
110 /** Content - Raml Content key.*/
\r
111 const std::string Content = "content";
\r
113 /** Json - Raml Json key.*/
\r
114 const std::string Json = "json";
\r
115 /** AllowedRamlYamlTypes - Raml AllowedRamlYamlTypes key.*/
\r
116 const std::vector<std::string> AllowedRamlYamlTypes = {"raml", "yaml", "yml"};
\r
121 * This macro is reading yamlNode as String.
\r
123 * @param yamlNode - reference to yamlNode
\r
125 * @return value as string
\r
128 #define READ_NODE_AS_STRING(yamlNode) \
\r
130 (yamlNode).as<std::string>(); \
\r
134 * This macro is reading yamlNode as int.
\r
136 * @param yamlNode - reference to yamlNode
\r
138 * @return value as int
\r
140 #define READ_NODE_AS_INT(yamlNode) \
\r
142 (yamlNode).as<int>(); \
\r
146 * This macro is reading yamlNode as long.
\r
148 * @param yamlNode - reference to yamlNode
\r
150 * @return value as long
\r
152 #define READ_NODE_AS_LONG(yamlNode) \
\r
154 (yamlNode).as<long>(); \
\r
157 * This macro is reading yamlNode as bool.
\r
159 * @param yamlNode - reference to yamlNode
\r
161 * @return value as bool
\r
163 #define READ_NODE_AS_BOOL(yamlNode) \
\r
165 (yamlNode).as<bool>(); \
\r
168 * This macro is getting ActionType
\r
170 * @param key - string
\r
172 * @return ActionType
\r
175 #define GET_ACTION_TYPE(key) \
\r
177 ActionType actionType = ActionType::GET; \
\r
178 if (key == "get" ) \
\r
179 actionType = ActionType::GET; \
\r
180 else if (key == "post" ) \
\r
181 actionType = ActionType::POST; \
\r
182 else if (key == "put" ) \
\r
183 actionType = ActionType::PUT; \
\r
184 else if (key == "delete" ) \
\r
185 actionType = ActionType::DELETE; \
\r
186 else if (key == "head" ) \
\r
187 actionType = ActionType::HEAD; \
\r
188 else if (key == "patch" ) \
\r
189 actionType = ActionType::PATCH; \
\r
190 else if (key == "options" ) \
\r
191 actionType = ActionType::OPTIONS; \
\r
192 else if (key == "trace" ) \
\r
193 actionType = ActionType::TRACE; \
\r