redsnow 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -1
  3. data/README.md +12 -0
  4. data/ext/snowcrash/bin/snowcrash +0 -0
  5. data/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.c +5 -2
  6. data/ext/snowcrash/snowcrash.gyp +7 -2
  7. data/ext/snowcrash/src/ActionParser.h +141 -81
  8. data/ext/snowcrash/src/AssetParser.h +19 -11
  9. data/ext/snowcrash/src/Blueprint.h +44 -14
  10. data/ext/snowcrash/src/BlueprintParser.h +65 -51
  11. data/ext/snowcrash/src/BlueprintSourcemap.h +254 -0
  12. data/ext/snowcrash/src/BlueprintUtility.h +3 -24
  13. data/ext/snowcrash/src/CBlueprint.cc +40 -31
  14. data/ext/snowcrash/src/CBlueprint.h +54 -58
  15. data/ext/snowcrash/src/CBlueprintSourcemap.cc +620 -0
  16. data/ext/snowcrash/src/CBlueprintSourcemap.h +342 -0
  17. data/ext/snowcrash/src/CSourceAnnotation.cc +14 -0
  18. data/ext/snowcrash/src/CodeBlockUtility.h +42 -5
  19. data/ext/snowcrash/src/HeadersParser.h +84 -42
  20. data/ext/snowcrash/src/ParameterParser.h +110 -68
  21. data/ext/snowcrash/src/ParametersParser.h +26 -28
  22. data/ext/snowcrash/src/PayloadParser.h +164 -83
  23. data/ext/snowcrash/src/ResourceGroupParser.h +35 -41
  24. data/ext/snowcrash/src/ResourceParser.h +142 -97
  25. data/ext/snowcrash/src/SectionParser.h +15 -14
  26. data/ext/snowcrash/src/SectionParserData.h +11 -2
  27. data/ext/snowcrash/src/SectionProcessor.h +42 -18
  28. data/ext/snowcrash/src/Serialize.cc +2 -0
  29. data/ext/snowcrash/src/Serialize.h +3 -1
  30. data/ext/snowcrash/src/SerializeJSON.cc +608 -16
  31. data/ext/snowcrash/src/SerializeJSON.h +4 -1
  32. data/ext/snowcrash/src/SerializeYAML.cc +367 -19
  33. data/ext/snowcrash/src/SerializeYAML.h +4 -1
  34. data/ext/snowcrash/src/SymbolTable.h +12 -1
  35. data/ext/snowcrash/src/ValuesParser.h +12 -11
  36. data/ext/snowcrash/src/Version.h +1 -1
  37. data/ext/snowcrash/src/csnowcrash.cc +7 -3
  38. data/ext/snowcrash/src/csnowcrash.h +4 -2
  39. data/ext/snowcrash/src/snowcrash.cc +10 -11
  40. data/ext/snowcrash/src/snowcrash.h +3 -3
  41. data/ext/snowcrash/src/snowcrash/snowcrash.cc +38 -8
  42. data/ext/snowcrash/tools/homebrew/snowcrash.rb +1 -1
  43. data/lib/redsnow.rb +41 -2
  44. data/lib/redsnow/binding.rb +93 -8
  45. data/lib/redsnow/blueprint.rb +48 -25
  46. data/lib/redsnow/parseresult.rb +9 -2
  47. data/lib/redsnow/sourcemap.rb +369 -0
  48. data/lib/redsnow/version.rb +1 -1
  49. data/test/fixtures/sample-api-ast.json +1 -1
  50. data/test/fixtures/sample-api-sourcemap.json +169 -0
  51. data/test/redsnow_binding_test.rb +19 -2
  52. data/test/redsnow_options_test.rb +42 -0
  53. data/test/redsnow_parseresult_test.rb +5 -1
  54. data/test/redsnow_test.rb +5 -0
  55. metadata +11 -2
@@ -11,6 +11,20 @@ module RedSnow
11
11
  class BlueprintNode
12
12
  end
13
13
 
14
+ # Blueprint AST Reference node
15
+ #
16
+ # @attr id [String] identifier of the reference
17
+ #
18
+ # @abstrac
19
+ class ReferenceNode < BlueprintNode
20
+
21
+ attr_accessor :id
22
+
23
+ def initialize(id)
24
+ @id = id
25
+ end
26
+ end
27
+
14
28
  # Blueprint AST node with name and description associated
15
29
  #
16
30
  # @attr name [String] name of the node
@@ -137,6 +151,7 @@ module RedSnow
137
151
  attr_accessor :default_value
138
152
  attr_accessor :example_value
139
153
  attr_accessor :values
154
+
140
155
  # @param sc_parameter_handle [FFI::Pointer]
141
156
  def initialize(sc_parameter_handle)
142
157
  @name = RedSnow::Binding.sc_parameter_name(sc_parameter_handle)
@@ -145,6 +160,7 @@ module RedSnow
145
160
  @use = RedSnow::Binding.sc_parameter_parameter_use(sc_parameter_handle)
146
161
  @default_value = RedSnow::Binding.sc_parameter_default_value(sc_parameter_handle)
147
162
  @example_value = RedSnow::Binding.sc_parameter_example_value(sc_parameter_handle)
163
+
148
164
  @values = Array.new
149
165
 
150
166
  sc_value_collection_handle = RedSnow::Binding.sc_value_collection_handle(sc_parameter_handle)
@@ -155,8 +171,7 @@ module RedSnow
155
171
 
156
172
  for valueIndex in 0..values_size do
157
173
  sc_value_handle = RedSnow::Binding.sc_value_handle(sc_value_collection_handle, valueIndex)
158
- value = RedSnow::Binding.sc_value_string(sc_value_handle)
159
- @values << value
174
+ @values << RedSnow::Binding.sc_value(sc_value_handle)
160
175
  end
161
176
  end
162
177
  end
@@ -181,8 +196,7 @@ module RedSnow
181
196
 
182
197
  for index in 0..parameters_size do
183
198
  sc_parameter_handle = RedSnow::Binding.sc_parameter_handle(sc_parameter_collection_handle, index)
184
- parameter = Parameter.new(sc_parameter_handle)
185
- @collection << parameter
199
+ @collection << Parameter.new(sc_parameter_handle)
186
200
  end
187
201
  end
188
202
  end
@@ -194,15 +208,16 @@ module RedSnow
194
208
  #
195
209
  # @abstract
196
210
  # @attr parameters [Array] ignored
197
- # @attr headers [Array<Headers>] array of HTTP header fields of the message or nil
211
+ # @attr headers [Headers] array of HTTP header fields of the message or nil
198
212
  # @attr body [String] HTTP-message body or nil
199
213
  # @attr schema [String] HTTP-message body validation schema or nil
214
+ # @attr reference [Hash] Symbol Reference if the payload is a reference
200
215
  class Payload < NamedBlueprintNode
201
216
 
202
- attr_accessor :parameters
203
217
  attr_accessor :headers
204
218
  attr_accessor :body
205
219
  attr_accessor :schema
220
+ attr_accessor :reference
206
221
 
207
222
  # @param sc_payload_handle_resource [FFI::Pointer]
208
223
  def initialize(sc_payload_handle_resource)
@@ -211,6 +226,12 @@ module RedSnow
211
226
  @body = RedSnow::Binding.sc_payload_body(sc_payload_handle_resource)
212
227
  @schema = RedSnow::Binding.sc_payload_schema(sc_payload_handle_resource)
213
228
 
229
+ symbol = RedSnow::Binding.sc_payload_symbol(sc_payload_handle_resource)
230
+
231
+ if not symbol.empty?
232
+ @reference = ReferenceNode.new(symbol)
233
+ end
234
+
214
235
  sc_header_collection_handle_payload = RedSnow::Binding.sc_header_collection_handle_payload(sc_payload_handle_resource)
215
236
  @headers = Headers.new(sc_header_collection_handle_payload)
216
237
  end
@@ -230,6 +251,7 @@ module RedSnow
230
251
  def initialize(sc_transaction_example_handle)
231
252
  @name = RedSnow::Binding.sc_transaction_example_name(sc_transaction_example_handle)
232
253
  @description = RedSnow::Binding.sc_transaction_example_description(sc_transaction_example_handle)
254
+
233
255
  # BP Resource Actions Examples Requests
234
256
  @requests = Array.new
235
257
  sc_payload_collection_handle_requests = RedSnow::Binding.sc_payload_collection_handle_requests(sc_transaction_example_handle)
@@ -239,8 +261,8 @@ module RedSnow
239
261
  requests_size = sc_payload_collection_size_requests - 1
240
262
 
241
263
  for index in 0..requests_size do
242
- request = Payload.new(RedSnow::Binding.sc_payload_handle(sc_payload_collection_handle_requests, index))
243
- @requests << request
264
+ sc_payload_handle = RedSnow::Binding.sc_payload_handle(sc_payload_collection_handle_requests, index)
265
+ @requests << Payload.new(sc_payload_handle)
244
266
  end
245
267
  end
246
268
 
@@ -253,8 +275,8 @@ module RedSnow
253
275
  responses_size = sc_payload_collection_size_responses - 1
254
276
 
255
277
  for index in 0..responses_size do
256
- response = Payload.new(RedSnow::Binding.sc_payload_handle(sc_payload_collection_handle_responses, index))
257
- @responses << response
278
+ sc_payload_handle = RedSnow::Binding.sc_payload_handle(sc_payload_collection_handle_responses, index)
279
+ @responses << Payload.new(sc_payload_handle)
258
280
  end
259
281
  end
260
282
  end
@@ -290,8 +312,8 @@ module RedSnow
290
312
  examples_size = sc_transaction_example_collection_size - 1
291
313
 
292
314
  for index in 0..examples_size do
293
- example = TransactionExample.new(RedSnow::Binding.sc_transaction_example_handle(sc_transaction_example_collection_handle, index))
294
- @examples << example
315
+ sc_transaction_example_handle = RedSnow::Binding.sc_transaction_example_handle(sc_transaction_example_collection_handle, index)
316
+ @examples << TransactionExample.new(sc_transaction_example_handle)
295
317
  end
296
318
  end
297
319
  end
@@ -329,7 +351,8 @@ module RedSnow
329
351
  action_size = sc_action_collection_size - 1
330
352
 
331
353
  for index in 0..action_size do
332
- @actions << Action.new(RedSnow::Binding.sc_action_handle(sc_action_collection_handle, index))
354
+ sc_action_handle = RedSnow::Binding.sc_action_handle(sc_action_collection_handle, index)
355
+ @actions << Action.new(sc_action_handle)
333
356
  end
334
357
  end
335
358
 
@@ -346,13 +369,13 @@ module RedSnow
346
369
 
347
370
  attr_accessor :resources
348
371
 
349
- # @param sc_resource_groups_handle [FFI::Pointer]
350
- def initialize(sc_resource_groups_handle)
351
- @name = RedSnow::Binding.sc_resource_groups_name(sc_resource_groups_handle)
352
- @description = RedSnow::Binding.sc_resource_groups_description(sc_resource_groups_handle)
372
+ # @param sc_resource_group_handle [FFI::Pointer]
373
+ def initialize(sc_resource_group_handle)
374
+ @name = RedSnow::Binding.sc_resource_group_name(sc_resource_group_handle)
375
+ @description = RedSnow::Binding.sc_resource_group_description(sc_resource_group_handle)
353
376
 
354
377
  @resources = Array.new
355
- sc_resource_collection_handle = RedSnow::Binding.sc_resource_collection_handle(sc_resource_groups_handle)
378
+ sc_resource_collection_handle = RedSnow::Binding.sc_resource_collection_handle(sc_resource_group_handle)
356
379
  sc_resource_collection_size = RedSnow::Binding.sc_resource_collection_size(sc_resource_collection_handle)
357
380
 
358
381
  if sc_resource_collection_size > 0
@@ -382,7 +405,7 @@ module RedSnow
382
405
  VERSION_KEY = :_version
383
406
 
384
407
  # Supported version of Api Blueprint
385
- SUPPORTED_VERSIONS = ["2.0"]
408
+ SUPPORTED_VERSIONS = ["2.1"]
386
409
 
387
410
  # @param handle [FFI:Pointer]
388
411
  def initialize(handle)
@@ -395,16 +418,16 @@ module RedSnow
395
418
  @metadata = Metadata.new(sc_metadata_collection_handle)
396
419
 
397
420
  # BP Resource Groups
398
- sc_resource_groups_collection_handle = RedSnow::Binding.sc_resource_groups_collection_handle(handle)
399
- sc_resource_groups_collection_size = RedSnow::Binding.sc_resource_groups_collection_size(sc_resource_groups_collection_handle)
421
+ sc_resource_group_collection_handle = RedSnow::Binding.sc_resource_group_collection_handle(handle)
422
+ sc_resource_group_collection_size = RedSnow::Binding.sc_resource_group_collection_size(sc_resource_group_collection_handle)
400
423
  @resource_groups = Array.new
401
424
 
402
- if sc_resource_groups_collection_size > 0
403
- group_size = sc_resource_groups_collection_size - 1
425
+ if sc_resource_group_collection_size > 0
426
+ group_size = sc_resource_group_collection_size - 1
404
427
 
405
428
  for index in 0..group_size do
406
- sc_resource_groups_handle = RedSnow::Binding.sc_resource_groups_handle(sc_resource_groups_collection_handle, index)
407
- @resource_groups << ResourceGroup.new(sc_resource_groups_handle)
429
+ sc_resource_group_handle = RedSnow::Binding.sc_resource_group_handle(sc_resource_group_collection_handle, index)
430
+ @resource_groups << ResourceGroup.new(sc_resource_group_handle)
408
431
  end
409
432
  end
410
433
  end
@@ -5,22 +5,29 @@ module RedSnow
5
5
  # @param ast [Blueprint]
6
6
  # @param error [Hash] Description of a parsing error as occurred during parsing. If this field is present and code different from 0 then the content of ast field should be ignored.
7
7
  # @param warnings [Array<Hash>] Ordered array of parser warnings as occurred during the parsing.
8
+ # @param sourcemap [BlueprintSourcemap]
8
9
  class ParseResult
10
+
9
11
  attr_accessor :ast
10
12
  attr_accessor :error
11
13
  attr_accessor :warnings
14
+ attr_accessor :sourcemap
12
15
 
13
16
  # Version key
14
17
  VERSION_KEY = :_version
18
+
15
19
  # Supported version of Api Blueprint
16
- SUPPORTED_VERSIONS = ["2.0"]
20
+ SUPPORTED_VERSIONS = ["2.1"]
17
21
 
18
22
  # @param report_handle [FFI::Pointer]
19
- def initialize(blueprint_handle, report_handle)
23
+ def initialize(report_handle, blueprint_handle, sourcemap_handle)
20
24
 
21
25
  @ast = Blueprint.new(blueprint_handle)
26
+ @sourcemap = RedSnow::Sourcemap::Blueprint.new(sourcemap_handle)
27
+
22
28
  warnings = RedSnow::Binding.sc_warnings_handler(report_handle)
23
29
  warningsSize = RedSnow::Binding.sc_warnings_size(warnings)
30
+
24
31
  @warnings = Array.new
25
32
 
26
33
  for index in 0..(warningsSize - 1) do
@@ -0,0 +1,369 @@
1
+ require "redsnow/object"
2
+
3
+ # The classes in this module should be 1:1 with the Snow Crash Blueprint sourcemap
4
+ # counterparts (https://github.com/apiaryio/snowcrash/blob/master/src/BlueprintSourcemap.h).
5
+ module RedSnow
6
+
7
+ module Sourcemap
8
+
9
+ class Node
10
+ end
11
+
12
+ class SourceMap < Array
13
+
14
+ def initialize(sc_source_map_handle)
15
+ source_map_size = RedSnow::Binding.sc_source_map_size(sc_source_map_handle) - 1
16
+
17
+ for index in 0..source_map_size do
18
+ location = RedSnow::Binding.sc_source_map_location(sc_source_map_handle, index)
19
+ length = RedSnow::Binding.sc_source_map_length(sc_source_map_handle, index)
20
+
21
+ self << [location, length]
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ # Blueprint sourcemap node with name and description associated
28
+ #
29
+ # @attr name [SourceMap] name of the node
30
+ # @attr description [SourceMap] description of the node
31
+ #
32
+ # @abstract
33
+ class NamedNode < Node
34
+
35
+ attr_accessor :name
36
+ attr_accessor :description
37
+
38
+ end
39
+
40
+ # Metadata source map collection node
41
+ class Metadata < Node
42
+
43
+ attr_accessor :collection
44
+
45
+ # @param sc_sm_metadata_collection_handle [FFI::Pointer]
46
+ def initialize(sc_sm_metadata_collection_handle)
47
+ sc_sm_metadata_collection_size = RedSnow::Binding.sc_sm_metadata_collection_size(sc_sm_metadata_collection_handle)
48
+
49
+ if sc_sm_metadata_collection_size > 0
50
+ metadata_size = sc_sm_metadata_collection_size - 1
51
+ @collection = Array.new
52
+
53
+ for index in 0..metadata_size do
54
+ sc_sm_metadata_handle = RedSnow::Binding.sc_sm_metadata_handle(sc_sm_metadata_collection_handle, index)
55
+ @collection << SourceMap.new(RedSnow::Binding.sc_sm_metadata(sc_sm_metadata_handle))
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ # Headers source map collection node
63
+ class Headers < Node
64
+
65
+ attr_accessor :collection
66
+
67
+ # @param sc_header_collection_handle_payload [FFI::Pointer]
68
+ def initialize(sc_sm_header_collection_handle_payload)
69
+ sc_sm_header_collection_size = RedSnow::Binding.sc_sm_header_collection_size(sc_sm_header_collection_handle_payload)
70
+
71
+ if sc_sm_header_collection_size > 0
72
+ headers_size = sc_sm_header_collection_size - 1
73
+ @collection = Array.new
74
+
75
+ for index in 0..headers_size do
76
+ sc_sm_header_handle = RedSnow::Binding.sc_sm_header_handle(sc_sm_header_collection_handle_payload, index)
77
+ @collection << SourceMap.new(RedSnow::Binding.sc_sm_header(sc_sm_header_handle))
78
+ end
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ # Parameter source map node
85
+ #
86
+ # @attr type [Sourcemap] an arbitrary type of the parameter or nil
87
+ # @attr use [Sourcemap] parameter necessity flag, `:required` or `:optional`
88
+ # @attr default_value [Sourcemap] default value of the parameter or nil
89
+ # @attr example_value [Sourcemap] example value of the parameter or nil
90
+ # @attr values [Array<Sourcemap>] an enumeration of possible parameter values
91
+ class Parameter < NamedNode
92
+
93
+ attr_accessor :type
94
+ attr_accessor :use
95
+ attr_accessor :default_value
96
+ attr_accessor :example_value
97
+ attr_accessor :values
98
+
99
+ # @param sc_sm_parameter_handle [FFI::Pointer]
100
+ def initialize(sc_sm_parameter_handle)
101
+ @name = SourceMap.new(RedSnow::Binding.sc_sm_parameter_name(sc_sm_parameter_handle))
102
+ @description = SourceMap.new(RedSnow::Binding.sc_sm_parameter_description(sc_sm_parameter_handle))
103
+ @type = SourceMap.new(RedSnow::Binding.sc_sm_parameter_type(sc_sm_parameter_handle))
104
+ @use = SourceMap.new(RedSnow::Binding.sc_sm_parameter_parameter_use(sc_sm_parameter_handle))
105
+ @default_value = SourceMap.new(RedSnow::Binding.sc_sm_parameter_default_value(sc_sm_parameter_handle))
106
+ @example_value = SourceMap.new(RedSnow::Binding.sc_sm_parameter_example_value(sc_sm_parameter_handle))
107
+
108
+ @values = Array.new
109
+
110
+ sc_sm_value_collection_handle = RedSnow::Binding.sc_sm_value_collection_handle(sc_sm_parameter_handle)
111
+ sc_sm_value_collection_size = RedSnow::Binding.sc_sm_value_collection_size(sc_sm_value_collection_handle)
112
+
113
+ if sc_sm_value_collection_size > 0
114
+ values_size = sc_sm_value_collection_size - 1
115
+
116
+ for valueIndex in 0..values_size do
117
+ sc_sm_value_handle = RedSnow::Binding.sc_sm_value_handle(sc_sm_value_collection_handle, valueIndex)
118
+ @values << SourceMap.new(RedSnow::Binding.sc_sm_value(sc_sm_value_handle))
119
+ end
120
+ end
121
+ end
122
+
123
+ end
124
+
125
+ # Parameters source map collection node
126
+ #
127
+ # @attr collection [Array<Parameter>] an array of URI parameters
128
+ class Parameters < Node
129
+
130
+ attr_accessor :collection
131
+
132
+ # @param sc_sm_parameter_collection_handle [FFI::Pointer]
133
+ def initialize(sc_sm_parameter_collection_handle)
134
+ sc_sm_parameter_collection_size = RedSnow::Binding.sc_sm_parameter_collection_size(sc_sm_parameter_collection_handle)
135
+ @collection = Array.new
136
+
137
+ if sc_sm_parameter_collection_size > 0
138
+ parameters_size = sc_sm_parameter_collection_size - 1
139
+
140
+ for index in 0..parameters_size do
141
+ sc_sm_parameter_handle = RedSnow::Binding.sc_sm_parameter_handle(sc_sm_parameter_collection_handle, index)
142
+ @collection << Parameter.new(sc_sm_parameter_handle)
143
+ end
144
+ end
145
+ end
146
+
147
+ end
148
+
149
+ # Payload source map node
150
+ #
151
+ # @abstract
152
+ # @attr parameters [Parameters] ignored
153
+ # @attr headers [Headers] array of HTTP header fields of the message or nil
154
+ # @attr body [Sourcemap] HTTP-message body or nil
155
+ # @attr schema [Sourcemap] HTTP-message body validation schema or nil
156
+ # @attr reference [Sourcemap] Symbol Reference sourcemap if the payload is a reference
157
+ class Payload < NamedNode
158
+
159
+ attr_accessor :headers
160
+ attr_accessor :body
161
+ attr_accessor :schema
162
+ attr_accessor :reference
163
+
164
+ # @param sc_sm_payload_handle_resource [FFI::Pointer]
165
+ def initialize(sc_sm_payload_handle_resource)
166
+ @name = SourceMap.new(RedSnow::Binding.sc_sm_payload_name(sc_sm_payload_handle_resource))
167
+ @description = SourceMap.new(RedSnow::Binding.sc_sm_payload_description(sc_sm_payload_handle_resource))
168
+ @body = SourceMap.new(RedSnow::Binding.sc_sm_payload_body(sc_sm_payload_handle_resource))
169
+ @schema = SourceMap.new(RedSnow::Binding.sc_sm_payload_schema(sc_sm_payload_handle_resource))
170
+
171
+ symbol_source_map_handle = RedSnow::Binding.sc_sm_payload_symbol(sc_sm_payload_handle_resource)
172
+ symbol_source_map_size = RedSnow::Binding.sc_source_map_size(symbol_source_map_handle)
173
+
174
+ if symbol_source_map_size != 0
175
+ @reference = SourceMap.new(symbol_source_map_handle)
176
+ end
177
+
178
+ sc_sm_header_collection_handle_payload = RedSnow::Binding.sc_sm_header_collection_handle_payload(sc_sm_payload_handle_resource)
179
+ @headers = Headers.new(sc_sm_header_collection_handle_payload)
180
+ end
181
+
182
+ end
183
+
184
+ # Transaction example source map node
185
+ #
186
+ # @attr requests [Array<Request>] example request payloads
187
+ # @attr response [Array<Response>] example response payloads
188
+ class TransactionExample < NamedNode
189
+
190
+ attr_accessor :requests
191
+ attr_accessor :responses
192
+
193
+ # @param sc_sm_transaction_example_handle [FFI::Pointer]
194
+ def initialize(sc_sm_transaction_example_handle)
195
+ @name = SourceMap.new(RedSnow::Binding.sc_sm_transaction_example_name(sc_sm_transaction_example_handle))
196
+ @description = SourceMap.new(RedSnow::Binding.sc_sm_transaction_example_description(sc_sm_transaction_example_handle))
197
+
198
+ # BP Resource Actions Examples Requests
199
+ @requests = Array.new
200
+ sc_sm_payload_collection_handle_requests = RedSnow::Binding.sc_sm_payload_collection_handle_requests(sc_sm_transaction_example_handle)
201
+ sc_sm_payload_collection_size_requests = RedSnow::Binding.sc_sm_payload_collection_size(sc_sm_payload_collection_handle_requests)
202
+
203
+ if sc_sm_payload_collection_size_requests > 0
204
+ requests_size = sc_sm_payload_collection_size_requests - 1
205
+
206
+ for index in 0..requests_size do
207
+ sc_sm_payload_handle = RedSnow::Binding.sc_sm_payload_handle(sc_sm_payload_collection_handle_requests, index)
208
+ @requests << Payload.new(sc_sm_payload_handle)
209
+ end
210
+ end
211
+
212
+ # BP Resource Actions Examples Responses
213
+ @responses = Array.new
214
+ sc_sm_payload_collection_handle_responses = RedSnow::Binding.sc_sm_payload_collection_handle_responses(sc_sm_transaction_example_handle)
215
+ sc_sm_payload_collection_size_responses = RedSnow::Binding.sc_sm_payload_collection_size(sc_sm_payload_collection_handle_responses)
216
+
217
+ if sc_sm_payload_collection_size_responses > 0
218
+ responses_size = sc_sm_payload_collection_size_responses - 1
219
+
220
+ for index in 0..responses_size do
221
+ sc_sm_payload_handle = RedSnow::Binding.sc_sm_payload_handle(sc_sm_payload_collection_handle_responses, index)
222
+ @responses << Payload.new(sc_sm_payload_handle)
223
+ end
224
+ end
225
+ end
226
+
227
+ end
228
+
229
+ # Action source map node
230
+ #
231
+ # @attr method [Sourcemap] HTTP request method or nil
232
+ # @attr parameters [Parameters] action-specific URI parameters or nil
233
+ # @attr examples [Array<TransactionExample>] action transaction examples
234
+ class Action < NamedNode
235
+
236
+ attr_accessor :method
237
+ attr_accessor :parameters
238
+ attr_accessor :examples
239
+
240
+ # @param sc_sm_action_handle [FFI::Pointer]
241
+ def initialize(sc_sm_action_handle)
242
+ @name = SourceMap.new(RedSnow::Binding.sc_sm_action_name(sc_sm_action_handle))
243
+ @description = SourceMap.new(RedSnow::Binding.sc_sm_action_description(sc_sm_action_handle))
244
+
245
+ @method = SourceMap.new(RedSnow::Binding.sc_sm_action_httpmethod(sc_sm_action_handle))
246
+
247
+ @parameters = Parameters.new(RedSnow::Binding.sc_sm_parameter_collection_handle_action(sc_sm_action_handle))
248
+
249
+ @examples = Array.new
250
+ sc_sm_transaction_example_collection_handle = RedSnow::Binding.sc_sm_transaction_example_collection_handle(sc_sm_action_handle)
251
+ sc_sm_transaction_example_collection_size = RedSnow::Binding.sc_sm_transaction_example_collection_size(sc_sm_transaction_example_collection_handle)
252
+
253
+ if sc_sm_transaction_example_collection_size > 0
254
+ examples_size = sc_sm_transaction_example_collection_size - 1
255
+
256
+ for index in 0..examples_size do
257
+ sc_sm_transaction_example_handle = RedSnow::Binding.sc_sm_transaction_example_handle(sc_sm_transaction_example_collection_handle, index)
258
+ @examples << TransactionExample.new(sc_sm_transaction_example_handle)
259
+ end
260
+ end
261
+ end
262
+
263
+ end
264
+
265
+ # Resource source map node
266
+ #
267
+ # @attr uri_template [Sourcemap] RFC 6570 URI template
268
+ # @attr model [Payload] model payload for the resource or nil
269
+ # @attr parameters [Parameters] action-specific URI parameters or nil
270
+ # @attr actions [Array<Action>] array of resource actions or nil
271
+ class Resource < NamedNode
272
+
273
+ attr_accessor :uri_template
274
+ attr_accessor :model
275
+ attr_accessor :parameters
276
+ attr_accessor :actions
277
+
278
+ # @param sc_sm_resource_handle [FFI::Pointer]
279
+ def initialize(sc_sm_resource_handle)
280
+ @name = SourceMap.new(RedSnow::Binding.sc_sm_resource_name(sc_sm_resource_handle))
281
+ @description = SourceMap.new(RedSnow::Binding.sc_sm_resource_description(sc_sm_resource_handle))
282
+ @uri_template = SourceMap.new(RedSnow::Binding.sc_sm_resource_uritemplate(sc_sm_resource_handle))
283
+
284
+ sc_sm_payload_handle_resource = RedSnow::Binding.sc_sm_payload_handle_resource(sc_sm_resource_handle)
285
+ @model = Payload.new(sc_sm_payload_handle_resource)
286
+
287
+ @actions = Array.new
288
+ sc_sm_action_collection_handle = RedSnow::Binding.sc_sm_action_collection_handle(sc_sm_resource_handle)
289
+ sc_sm_action_collection_size = RedSnow::Binding.sc_sm_action_collection_size(sc_sm_action_collection_handle)
290
+
291
+ if sc_sm_action_collection_size > 0
292
+ action_size = sc_sm_action_collection_size - 1
293
+
294
+ for index in 0..action_size do
295
+ sc_sm_action_handle = RedSnow::Binding.sc_sm_action_handle(sc_sm_action_collection_handle, index)
296
+ @actions << Action.new(sc_sm_action_handle)
297
+ end
298
+ end
299
+
300
+ @parameters = Parameters.new(RedSnow::Binding.sc_sm_parameter_collection_handle_resource(sc_sm_resource_handle))
301
+ end
302
+
303
+ end
304
+
305
+ # Resource group source map node
306
+ #
307
+ # @attr resources [Array<Resource>] array of resources in the group
308
+ class ResourceGroup < NamedNode
309
+
310
+ attr_accessor :resources
311
+
312
+ # @param sc_sm_resource_group_handle [FFI::Pointer]
313
+ def initialize(sc_sm_resource_group_handle)
314
+ @name = SourceMap.new(RedSnow::Binding.sc_sm_resource_group_name(sc_sm_resource_group_handle))
315
+ @description = SourceMap.new(RedSnow::Binding.sc_sm_resource_group_description(sc_sm_resource_group_handle))
316
+
317
+ @resources = Array.new
318
+ sc_sm_resource_collection_handle = RedSnow::Binding.sc_sm_resource_collection_handle(sc_sm_resource_group_handle)
319
+ sc_sm_resource_collection_size = RedSnow::Binding.sc_sm_resource_collection_size(sc_sm_resource_collection_handle)
320
+
321
+ if sc_sm_resource_collection_size > 0
322
+ resource_size = sc_sm_resource_collection_size - 1
323
+
324
+ for index in 0..resource_size do
325
+ sc_sm_resource_handle = RedSnow::Binding.sc_sm_resource_handle(sc_sm_resource_collection_handle, index)
326
+ @resources << Resource.new(sc_sm_resource_handle)
327
+ end
328
+ end
329
+ end
330
+
331
+ end
332
+
333
+
334
+ # Blueprint source map node
335
+ #
336
+ # @attr metadata [Metadata] tool-specific metadata collection or nil
337
+ # @attr resource_groups [Array<ResourceGroup>] array of resource groups
338
+ class Blueprint < NamedNode
339
+
340
+ attr_accessor :metadata
341
+ attr_accessor :resource_groups
342
+
343
+ # @param handle [FFI:Pointer]
344
+ def initialize(handle)
345
+ # BP name, desc
346
+ @name = SourceMap.new(RedSnow::Binding.sc_sm_blueprint_name(handle))
347
+ @description = SourceMap.new(RedSnow::Binding.sc_sm_blueprint_description(handle))
348
+
349
+ # BP metadata
350
+ sc_sm_metadata_collection_handle = RedSnow::Binding.sc_sm_metadata_collection_handle(handle)
351
+ @metadata = Metadata.new(sc_sm_metadata_collection_handle)
352
+
353
+ # BP Resource Groups
354
+ sc_sm_resource_group_collection_handle = RedSnow::Binding.sc_sm_resource_group_collection_handle(handle)
355
+ sc_sm_resource_group_collection_size = RedSnow::Binding.sc_sm_resource_group_collection_size(sc_sm_resource_group_collection_handle)
356
+ @resource_groups = Array.new
357
+
358
+ if sc_sm_resource_group_collection_size > 0
359
+ group_size = sc_sm_resource_group_collection_size - 1
360
+
361
+ for index in 0..group_size do
362
+ sc_sm_resource_group_handle = RedSnow::Binding.sc_sm_resource_group_handle(sc_sm_resource_group_collection_handle, index)
363
+ @resource_groups << ResourceGroup.new(sc_sm_resource_group_handle)
364
+ end
365
+ end
366
+ end
367
+ end
368
+ end
369
+ end