-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconstructs.txt
More file actions
366 lines (283 loc) · 9.5 KB
/
constructs.txt
File metadata and controls
366 lines (283 loc) · 9.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
### jinja2 test functions
#### has_body (method_name)
method name of an swagger path name
### jinja2 custom (global) functions
#### replace_chars (string, array of chars to be replaced by "")
any input string.
function: santize strings to be part of the target language.
typical value = "+-? ,./"
#### retrieve_path_value
retrieve an specific value from a property:
- input: json_object
- input: path leading from that object
- input: property name to retrieve the value from, e.g. will be prefixed with path
- return: value of the property
typical usage:
```
{% for path, path_data in json_data['paths'].items() -%}
var {{path|variablesyntax}}_resourceTypes = {{retrieve_path_value(path_data, "get/200/x-example", "rt")}};
{% endfor -%}
```
#### query_rt
retrieve an rt value for an path
- input: full swagger file
- input: path
- return: rt value (as part of the x-example)
typical usage:
```
{% for path, path_data in json_data['paths'].items() -%}
{{query_rt(json_data,path)}}
{% endfor -%}
```
#### query_if
retrieve an list of if values for an path
- input: full swagger file
- input: path
- return: if value (as part of the resolved schema)
typical usage:
```
{% for path, path_data in json_data['paths'].items() -%}
{{query_if(json_data, path)}}
{% endfor -%}
```
#### query_property_names
retrieve an list of properties values of an schema belonging to the path
from the GET 200 response, if that is not available then from the POST 200 response
- input: full swagger file
- input: path
- return: if value (as part of the resolved schema)
typical usage:
```
{% for path, path_data in json_data['paths'].items() -%}
{% for propname in query_property_names(json_data, path) -%}
{{propname}}
{% endfor -%}
{% endfor -%}
```
#### query_properties
retrieve an list of properties an schema belonging to the path
from the GET 200 response, if that is not available then from the POST 200 response
- input: full swagger file
- input: path
- return: if value (as part of the resolved schema)
typical usage:
```
{% for path, path_data in json_data['paths'].items() %}
{% for var, var_data in query_properties(json_data, path).items() %}
{{var_data.type|convert_to_c_type}} m{{path|variablesyntax}}{{var|variablesyntax}};
{% endfor %}
{% endfor %}
```
#### query_properties_filtered
retrieve an list of properties an schema belonging to the path
from the GET 200 response, if that is not available then from the POST 200 response
filtered, e.g. removing the values [ "n", "if", "rt" ]
- input: full swagger file
- input: path
- return: if value (as part of the resolved schema)
typical usage:
```
{% for path, path_data in json_data['paths'].items() %}
{% for var, var_data in query_properties_filtered(json_data, path).items() %}
{{var_data.type|convert_to_c_type}} m{{path|variablesyntax}}{{var|variablesyntax}};
{% endfor %}
{% endfor %}
```
#### query_properties_post
retrieve an list of properties an schema belonging to the path
from the POST request, if that is not available then from the GET 200 response
- input: full swagger file
- input: path
- return: if value (as part of the resolved schema)
typical usage:
```
{% for path, path_data in json_data['paths'].items() %}
{% for var, var_data in query_properties_post(json_data, path).items() %}
{{var_data.type|convert_to_c_type}} m{{path|variablesyntax}}{{var|variablesyntax}};
{% endfor %}
{% endfor %}
```
#### query_properties_post_filtered
retrieve an list of properties an schema belonging to the path
from the POST request, if that is not available then from the GET 200 response
filtered, e.g. removing the values [ "n", "if", "rt" ]
- input: full swagger file
- input: path
- return: if value (as part of the resolved schema)
typical usage:
```
{% for path, path_data in json_data['paths'].items() %}
{% for var, var_data in query_properties_post_filtered(json_data, path).items() %}
{{var_data.type|convert_to_c_type}} m{{path|variablesyntax}}{{var|variablesyntax}};
{% endfor %}
{% endfor %}
```
#### query_ref
retrieve an reference
typical usage:
```
{{query_ref(json_data, parameter_data["$ref"], "enum")}}
```
#### path_names (string, array of chars to be replaced by "")
any input string.
function: sanitize strings to be part of the target language.
typical value = "+-? ,./"
#### swagger_property_data_schema
get the value of the property name from the schema that is referenced by the path in get (or put)
it tries to get first the enum values or the default value.
if this is not found then it will try to get the value from the example
param json_data: the swagger file as json struct
param input_path: the path to which the if should be queried
return: list of if values
typical usage:
```
{% for path, path_data in json_data['paths'].items() -%}
{% for var, var_data in query_properties(json_data, path).items() -%}
{{swagger_property_data_schema(json_data, path, var) | convert_value_to_c_value}};
{% endfor -%}
{% endfor -%}
```
#### sdf_return_path_info
Return ocf resource type name: OCF name, e.g. oic.r.grinderAppliance returns grinderAppliance or grinderApplianceResURI
param json_data: inputted resource type file
param returnType: "name" or "path" or "description"
return: if returnType: "name" - string formatted name: e.g. grinder returnType: "description" - returns the description property of the "get" path, returnType: "path" the path name, e.g. /GrinderResURI
typical usage:
```
"sdfObject": {
"{{ sdf_return_path_info(json_data, "name") }}": {
"name": "{{ sdf_return_path_info(json_data, "name") }}",
"description": "{{ sdf_return_path_info(json_data, "description") }}",
"sdfProperty": {
{{sdf_property_object(json_data, "top")}}
}
}
}
```
#### sdf_property_object
Take the property values from a resource type and reformat for SDF
param json_data: sdfProperty's json_data from resource type
param level: "top" = top level, ignore filtered out types, "sub" = subsequent level, no filter required
return: json formatted string
typical usage:
```
"sdfObject": {
"{{ sdf_return_path_info(json_data, "name") }}": {
"name": "{{ sdf_return_path_info(json_data, "name") }}",
"description": "{{ sdf_return_path_info(json_data, "description") }}",
"sdfProperty": {
{{sdf_property_object(json_data, "top")}}
}
}
}
```
#### sdf_required_block_check
Return True/False if the sdfRequired block should be populated
:json_data: inputted resource type file
:return: True/False
typical usage:
```
{% if sdf_required_block_check(json_data) is sameas True %}
,
"sdfRequired":
{{sdf_required_object(json_data)}}
{% endif %}
```
#### sdf_required_object
Return the required object block for OAS2SDF
:param json_value: json object for resource type
:return: json formatted string for SDF required block
typical usage:
```
{% if sdf_required_block_check(json_data) is sameas True %}
,
"sdfRequired":
{{sdf_required_object(json_data)}}
{% endif %}
```
### jinja2 filter functions
#### variablesyntax
replace chars so that the data can be used as an variable.
note that it prefixes the variable with "_" so that names don't get in the
way of language defined names (like "if")
typical usage:
```
{% for path, path_data in json_data['paths'].items() -%}
{{path|variablesyntax}}
{% endfor -%}
```
#### classsyntax
replace chars so that the data can be used for an class name.
note that it capitalizes the first letter of the string.
this also solves issue with keywords like "if" won't occur.
typical usage:
```
{% for path, path_data in json_data['paths'].items() -%}
{{path|classsyntax}}
{% endfor -%}
```
#### variableforbidden
if the variable is "if", "var", "function", "null"
it will be prefixed with "_"
all other names will be kept intact (e.g. just pass through)
#### convert_to_c_type
convert the json types into C types.
typical usage:
```
{{var|convert_to_c_type}}
```
note string will be mapped to char*
note does not do array type.
#### convert_to_cplus_type
convert the json types into C++ types.
typical usage:
```
{{var|convert_to_cplus_type}}
```
note string will be mapped to std:string
note does not do array type.
#### convert_to_cplus_array_type
convert the json array types into C++ vector types.
typical usage:
```
{% if var_data.type == "array" %}
{{var_data |convert_to_cplus_array_type}} m_var_value{{var|variablesyntax}};
{% endif -%}
```
#### get_c_data
convert the properties into an dict so that one can iterate over it
returns a dict with key array pairs
array value 0 = type
array value 1 = description
typical usage:
```
{%- set my_data = var_data.properties |get_c_data() %}
{%- for k,v in my_data.items() %}
...
```
#### convert_array_size
determines the size of the array.
for single strings, 1 is returned.
typical usage:
```
{{var|convert_array_size}}
```
#### code_indent
indents the descriptions with an prefix per line.
typical usage:
```
{{ method_data["description"] | code_indent(" * ")}}
```
#### convert_value_to_c_value
used in combination with swagger_property_data_schema
the filter is then unwrapping the array and gives out the variable in c style
e.g. boolean True False are corrected to true and false
string needs to be with quotes in the jinga2 template.
typical usage:
```
{% for path, path_data in json_data['paths'].items() -%}
{% for var, var_data in query_properties(json_data, path).items() -%}
{{swagger_property_data_schema(json_data, path, var) | convert_value_to_c_value}};
{% endfor -%}
{% endfor -%}
```