raml_ruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +1 -9
- data/Rakefile +7 -0
- data/lib/raml.rb +6 -26
- data/lib/raml/exceptions.rb +1 -0
- data/lib/raml/mixin/bodies.rb +3 -3
- data/lib/raml/mixin/documentable.rb +3 -8
- data/lib/raml/mixin/global.rb +14 -10
- data/lib/raml/mixin/headers.rb +1 -1
- data/lib/raml/mixin/merge.rb +4 -4
- data/lib/raml/mixin/secured_by.rb +27 -0
- data/lib/raml/mixin/validation.rb +27 -27
- data/lib/raml/node.rb +22 -80
- data/lib/raml/node/abstract_method.rb +7 -7
- data/lib/raml/node/abstract_resource.rb +17 -7
- data/lib/raml/node/body.rb +12 -10
- data/lib/raml/node/documentation.rb +0 -8
- data/lib/raml/node/method.rb +5 -7
- data/lib/raml/node/parameter/abstract_parameter.rb +22 -24
- data/lib/raml/node/parametized_reference.rb +3 -3
- data/lib/raml/node/resource.rb +0 -2
- data/lib/raml/node/resource_type.rb +9 -9
- data/lib/raml/node/resource_type_reference.rb +2 -2
- data/lib/raml/node/response.rb +0 -2
- data/lib/raml/node/root.rb +66 -57
- data/lib/raml/node/schema.rb +3 -9
- data/lib/raml/node/schema_reference.rb +2 -2
- data/lib/raml/node/security_scheme.rb +47 -0
- data/lib/raml/node/security_scheme_reference.rb +5 -0
- data/lib/raml/node/trait.rb +8 -8
- data/lib/raml/node/trait_reference.rb +2 -2
- data/lib/raml/parser.rb +25 -16
- data/lib/raml/version.rb +1 -1
- data/raml_ruby.gemspec +3 -7
- data/test/apis/box-api.raml +1447 -1447
- data/test/apis/instagram-api.raml +48 -48
- data/test/apis/stripe-api.raml +4266 -4266
- data/test/apis/twilio-rest-api.raml +47 -47
- data/test/apis/twitter-rest-api.raml +1883 -1883
- data/test/raml/body_spec.rb +22 -39
- data/test/raml/documentation_spec.rb +2 -12
- data/test/raml/method_spec.rb +112 -93
- data/test/raml/parameter/abstract_parameter_spec.rb +9 -34
- data/test/raml/parameter/query_parameter_spec.rb +0 -15
- data/test/raml/parameter/uri_parameter_spec.rb +1 -16
- data/test/raml/resource_spec.rb +59 -41
- data/test/raml/resource_type_spec.rb +13 -13
- data/test/raml/response_spec.rb +23 -36
- data/test/raml/root_spec.rb +85 -18
- data/test/raml/security_scheme_spec.rb +71 -0
- data/test/raml/spec_helper.rb +2 -1
- data/test/raml/template_spec.rb +92 -92
- data/test/raml/trait_spec.rb +7 -7
- metadata +14 -74
- data/templates/abstract_parameter.slim +0 -68
- data/templates/body.slim +0 -15
- data/templates/collapse.slim +0 -10
- data/templates/documentation.slim +0 -2
- data/templates/method.slim +0 -38
- data/templates/resource.slim +0 -33
- data/templates/response.slim +0 -13
- data/templates/root.slim +0 -39
- data/templates/style.sass +0 -119
@@ -90,7 +90,7 @@ describe Raml::Parameter::AbstractParameter do
|
|
90
90
|
let(:parameter_data) { { type: 'string', enum: enum } }
|
91
91
|
it { expect { subject }.to raise_error Raml::InvalidParameterAttribute }
|
92
92
|
end
|
93
|
-
end
|
93
|
+
end
|
94
94
|
context 'and an pattern attribute is given' do
|
95
95
|
let(:parameter_data) { { type: 'string', pattern: pattern } }
|
96
96
|
context 'and the value is string representing a valid regexp' do
|
@@ -132,7 +132,7 @@ describe Raml::Parameter::AbstractParameter do
|
|
132
132
|
let(:pattern) { '[' }
|
133
133
|
it { expect { subject }.to raise_error Raml::InvalidParameterAttribute }
|
134
134
|
end
|
135
|
-
end
|
135
|
+
end
|
136
136
|
end
|
137
137
|
context 'when the parameter type is not string' do
|
138
138
|
context 'and a minLength attribute is given' do
|
@@ -190,7 +190,7 @@ describe Raml::Parameter::AbstractParameter do
|
|
190
190
|
it { expect { subject }.to raise_error Raml::InapplicableParameterAttribute }
|
191
191
|
end
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
[
|
195
195
|
[ 'string' , 'string' , '123', 123 ],
|
196
196
|
[ 'number' , 'number' , 12.3, '123' ],
|
@@ -215,7 +215,7 @@ describe Raml::Parameter::AbstractParameter do
|
|
215
215
|
end
|
216
216
|
end
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
%w{repeat required}.each do |attribute|
|
220
220
|
context "when the #{attribute} attribute is not true or false" do
|
221
221
|
let(:parameter_data) { { attribute => 111 } }
|
@@ -237,7 +237,7 @@ describe Raml::Parameter::AbstractParameter do
|
|
237
237
|
end
|
238
238
|
end
|
239
239
|
end
|
240
|
-
|
240
|
+
|
241
241
|
context 'when example property is given' do
|
242
242
|
context 'when the example property is a string' do
|
243
243
|
let(:parameter_data) { { 'example' => 'My Attribute' } }
|
@@ -245,12 +245,9 @@ describe Raml::Parameter::AbstractParameter do
|
|
245
245
|
it 'should store the value' do
|
246
246
|
subject.example.should eq parameter_data['example']
|
247
247
|
end
|
248
|
-
it 'uses the description in the documentation' do
|
249
|
-
subject.document.should include parameter_data['example']
|
250
|
-
end
|
251
248
|
end
|
252
249
|
end
|
253
|
-
|
250
|
+
|
254
251
|
context 'when the parameter has multiple types' do
|
255
252
|
let(:parameter_data) {
|
256
253
|
YAML.load %q(
|
@@ -267,13 +264,9 @@ describe Raml::Parameter::AbstractParameter do
|
|
267
264
|
subject.children.should all( be_a Raml::Parameter::AbstractParameter )
|
268
265
|
subject.children.map(&:type).should contain_exactly 'string', 'file'
|
269
266
|
end
|
270
|
-
|
271
|
-
it "prints out documentation" do
|
272
|
-
subject.document
|
273
|
-
end
|
274
267
|
end
|
275
268
|
end
|
276
|
-
|
269
|
+
|
277
270
|
describe '#has_multiple_types?' do
|
278
271
|
let(:name) { 'file' }
|
279
272
|
context 'when the parameter has a single type' do
|
@@ -289,9 +282,9 @@ describe Raml::Parameter::AbstractParameter do
|
|
289
282
|
description: File to upload. The file must be the last field in the form.
|
290
283
|
)
|
291
284
|
}
|
292
|
-
|
285
|
+
|
293
286
|
it { subject.has_multiple_types?.should be true }
|
294
|
-
end
|
287
|
+
end
|
295
288
|
end
|
296
289
|
|
297
290
|
describe '#merge' do
|
@@ -543,22 +536,4 @@ describe Raml::Parameter::AbstractParameter do
|
|
543
536
|
end
|
544
537
|
end
|
545
538
|
|
546
|
-
describe '#document' do
|
547
|
-
let(:name) { 'page_number' }
|
548
|
-
let(:parameter_data) {
|
549
|
-
{
|
550
|
-
type: 'integer',
|
551
|
-
required: true,
|
552
|
-
example: 253995,
|
553
|
-
minimum: 33
|
554
|
-
}
|
555
|
-
}
|
556
|
-
it 'returns a String' do
|
557
|
-
subject.document.should be_a String
|
558
|
-
end
|
559
|
-
it 'should render the template' do
|
560
|
-
mock(Slim::Template).new(/templates\/abstract_parameter.slim\z/, is_a(Hash)).mock!.render(is_a(Raml::Node)) { '' }
|
561
|
-
subject.document
|
562
|
-
end
|
563
|
-
end
|
564
539
|
end
|
@@ -15,19 +15,4 @@ describe Raml::Parameter::QueryParameter do
|
|
15
15
|
it "should instanciate Query parameter" do
|
16
16
|
Raml::Parameter::QueryParameter.new(name, data, root)
|
17
17
|
end
|
18
|
-
|
19
|
-
describe "#document" do
|
20
|
-
let(:data) {
|
21
|
-
YAML.load(%q(
|
22
|
-
description: Specify the page that you want to retrieve
|
23
|
-
type: integer
|
24
|
-
required: true
|
25
|
-
example: 1
|
26
|
-
))
|
27
|
-
}
|
28
|
-
|
29
|
-
it "prints out documentation" do
|
30
|
-
subject.document
|
31
|
-
end
|
32
|
-
end
|
33
18
|
end
|
@@ -18,7 +18,7 @@ describe Raml::Parameter::UriParameter do
|
|
18
18
|
it "should instanciate Uri parameter" do
|
19
19
|
Raml::Parameter::UriParameter.new(name, data, root)
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
context 'when no required attribute is given' do
|
23
23
|
let(:data) { { } }
|
24
24
|
it 'defaults to true' do
|
@@ -26,19 +26,4 @@ describe Raml::Parameter::UriParameter do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
|
-
describe "#document" do
|
31
|
-
let(:data) {
|
32
|
-
YAML.load(%q(
|
33
|
-
description: Specify the page that you want to retrieve
|
34
|
-
type: integer
|
35
|
-
required: true
|
36
|
-
example: 1
|
37
|
-
))
|
38
|
-
}
|
39
|
-
|
40
|
-
it "prints out documentation" do
|
41
|
-
subject.document
|
42
|
-
end
|
43
|
-
end
|
44
29
|
end
|
data/test/raml/resource_spec.rb
CHANGED
@@ -35,18 +35,15 @@ describe Raml::Resource do
|
|
35
35
|
it "should instanciate Resource" do
|
36
36
|
subject
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
context 'when displayName is given' do
|
40
40
|
let(:data) { { 'displayName' => 'My Name', 'description' => 'foo' } }
|
41
41
|
it { expect { subject }.to_not raise_error }
|
42
42
|
it 'should store the value' do
|
43
43
|
subject.display_name.should eq data['displayName']
|
44
44
|
end
|
45
|
-
it 'uses the displayName in the documentation' do
|
46
|
-
subject.document.should include data['displayName']
|
47
|
-
end
|
48
45
|
end
|
49
|
-
|
46
|
+
|
50
47
|
context 'when description is not given' do
|
51
48
|
let(:data) { {} }
|
52
49
|
it { expect { subject }.to_not raise_error }
|
@@ -62,12 +59,9 @@ describe Raml::Resource do
|
|
62
59
|
it 'should store the value' do
|
63
60
|
subject.description.should eq data['description']
|
64
61
|
end
|
65
|
-
it 'uses the description in the documentation' do
|
66
|
-
subject.document.should include data['description']
|
67
|
-
end
|
68
62
|
end
|
69
63
|
end
|
70
|
-
|
64
|
+
|
71
65
|
context 'when the uriParameters parameter is given with valid parameters' do
|
72
66
|
context 'when the uriParameters property is well formed' do
|
73
67
|
it { expect { subject }.to_not raise_error }
|
@@ -88,7 +82,7 @@ describe Raml::Resource do
|
|
88
82
|
it { expect { subject }.to raise_error Raml::InvalidProperty, /uriParameters/ }
|
89
83
|
end
|
90
84
|
end
|
91
|
-
|
85
|
+
|
92
86
|
context 'when nested resources are defined' do
|
93
87
|
let(:name) { '/{userId}' }
|
94
88
|
let(:data) {
|
@@ -115,7 +109,7 @@ describe Raml::Resource do
|
|
115
109
|
expect( subject.resources.keys ).to contain_exactly('/followers','/following', '/keys')
|
116
110
|
end
|
117
111
|
end
|
118
|
-
|
112
|
+
|
119
113
|
context 'when a baseUriParameters property is given' do
|
120
114
|
context 'when the baseUriParameters property is well formed' do
|
121
115
|
let(:name) { '/files' }
|
@@ -129,7 +123,7 @@ describe Raml::Resource do
|
|
129
123
|
)
|
130
124
|
)
|
131
125
|
}
|
132
|
-
|
126
|
+
|
133
127
|
it { expect { subject }.to_not raise_error }
|
134
128
|
it 'stores all as Raml::Parameter::UriParameter instances' do
|
135
129
|
expect( subject.base_uri_parameters.values ).to all( be_a Raml::Parameter::BaseUriParameter )
|
@@ -155,7 +149,7 @@ describe Raml::Resource do
|
|
155
149
|
end
|
156
150
|
|
157
151
|
context 'when an type property is given' do
|
158
|
-
let(:root) {
|
152
|
+
let(:root) {
|
159
153
|
Raml::Root.new 'title' => 'x', 'baseUri' => 'http://foo.com', 'resourceTypes' => [
|
160
154
|
{ 'collection' => {} },
|
161
155
|
{ 'member' => {} },
|
@@ -208,9 +202,9 @@ describe Raml::Resource do
|
|
208
202
|
end
|
209
203
|
end
|
210
204
|
end
|
211
|
-
|
205
|
+
|
212
206
|
context 'when an is property is given' do
|
213
|
-
let(:root) {
|
207
|
+
let(:root) {
|
214
208
|
Raml::Root.new 'title' => 'x', 'baseUri' => 'http://foo.com', 'traits' => [
|
215
209
|
{ 'secured' => {} },
|
216
210
|
{ 'paged' => {} },
|
@@ -227,11 +221,11 @@ describe Raml::Resource do
|
|
227
221
|
end
|
228
222
|
end
|
229
223
|
context 'when the property is an array of trait references with parameters' do
|
230
|
-
let(:data) { {
|
231
|
-
'is' => [
|
232
|
-
{'secured' => {'tokenName' => 'access_token'}},
|
233
|
-
{'paged' => {'maxPages' => 10 }}
|
234
|
-
]
|
224
|
+
let(:data) { {
|
225
|
+
'is' => [
|
226
|
+
{'secured' => {'tokenName' => 'access_token'}},
|
227
|
+
{'paged' => {'maxPages' => 10 }}
|
228
|
+
]
|
235
229
|
} }
|
236
230
|
it { expect { subject }.to_not raise_error }
|
237
231
|
it 'should store the trait references' do
|
@@ -240,11 +234,11 @@ describe Raml::Resource do
|
|
240
234
|
end
|
241
235
|
end
|
242
236
|
context 'when the property is an array of trait definitions' do
|
243
|
-
let(:data) { {
|
244
|
-
'is' => [
|
245
|
-
{'queryParameters' => {'tokenName' => {'description'=>'foo'}}},
|
237
|
+
let(:data) { {
|
238
|
+
'is' => [
|
239
|
+
{'queryParameters' => {'tokenName' => {'description'=>'foo'}}},
|
246
240
|
{'queryParameters' => {'numPages' => {'description'=>'bar'}}}
|
247
|
-
]
|
241
|
+
]
|
248
242
|
} }
|
249
243
|
it { expect { subject }.to_not raise_error }
|
250
244
|
it 'should store the traits' do
|
@@ -254,12 +248,12 @@ describe Raml::Resource do
|
|
254
248
|
end
|
255
249
|
end
|
256
250
|
context 'when the property is an array of mixed trait refrences, trait refrences with parameters, and trait definitions' do
|
257
|
-
let(:data) { {
|
258
|
-
'is' => [
|
259
|
-
{'secured' => {'tokenName' => 'access_token'}},
|
251
|
+
let(:data) { {
|
252
|
+
'is' => [
|
253
|
+
{'secured' => {'tokenName' => 'access_token'}},
|
260
254
|
{'queryParameters' => {'numPages' => {'description'=>'bar'}}},
|
261
255
|
'rateLimited'
|
262
|
-
]
|
256
|
+
]
|
263
257
|
} }
|
264
258
|
it { expect { subject }.to_not raise_error }
|
265
259
|
it 'should store the traits' do
|
@@ -310,6 +304,33 @@ describe Raml::Resource do
|
|
310
304
|
}
|
311
305
|
it { expect { subject }.to raise_error Raml::InvalidProperty, /Optional properties/ }
|
312
306
|
end
|
307
|
+
|
308
|
+
context 'when the securedBy property is defined' do
|
309
|
+
let (:root_data) { {'title' => 'x', 'baseUri' => 'http://foo.com', 'securitySchemes' => ['oauth_2_0' => {'type' => 'OAuth 2.0'}, 'oauth_1_0' => {'type' => 'OAuth 1.0'}] } }
|
310
|
+
context 'when the securedBy property is an array of strings' do
|
311
|
+
let(:data) { { 'securedBy' => ['oauth_2_0', 'oauth_1_0'] } }
|
312
|
+
it { expect{ subject }.to_not raise_error }
|
313
|
+
end
|
314
|
+
context 'when the securedBy property is an array of strings and "null"' do
|
315
|
+
let(:data) { { 'securedBy' => ['oauth_2_0', 'null'] } }
|
316
|
+
it { expect{ subject }.to_not raise_error }
|
317
|
+
end
|
318
|
+
context 'when the securedBy property is an array of hash with single key' do
|
319
|
+
let(:data) { { 'securedBy' => ['oauth_2_0' => {'scopes' => 'ADMINISTRATOR'}] } }
|
320
|
+
it { expect{ subject }.to_not raise_error }
|
321
|
+
end
|
322
|
+
context 'when the securedBy property references a missing security scheme' do
|
323
|
+
let(:data) { { 'securedBy' => ['bar'] } }
|
324
|
+
it { expect{ subject }.to raise_error Raml::UnknownSecuritySchemeReference, /bar/}
|
325
|
+
end
|
326
|
+
context 'when the securedBy property is included it is accessible and' do
|
327
|
+
let(:data) { { 'securedBy' => ['oauth_2_0', 'oauth_1_0'] } }
|
328
|
+
it 'exposes the schema references' do
|
329
|
+
expect( subject.secured_by.values ).to all( be_a Raml::SecuritySchemeReference )
|
330
|
+
subject.secured_by.keys.should contain_exactly('oauth_2_0', 'oauth_1_0')
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
313
334
|
end
|
314
335
|
|
315
336
|
describe '#apply_resource_type' do
|
@@ -320,9 +341,10 @@ describe Raml::Resource do
|
|
320
341
|
'get' => {'description' => 'method description'},
|
321
342
|
'post' => {},
|
322
343
|
'/foo' => {},
|
323
|
-
'/bar' => {}
|
344
|
+
'/bar/{id}' => {}
|
324
345
|
} }
|
325
346
|
let(:resource) { Raml::Resource.new('/foo', resource_data, root) }
|
347
|
+
let(:resource_with_parameter) { Raml::Resource.new('/bar/{id}', resource_data, root) }
|
326
348
|
context 'when it has a resource type' do
|
327
349
|
it 'merges the resource type to the resource' do
|
328
350
|
resource.type.should be_a Raml::ResourceType
|
@@ -337,6 +359,12 @@ describe Raml::Resource do
|
|
337
359
|
resource.apply_resource_type
|
338
360
|
resource.methods['get'].description.should eq 'method description'
|
339
361
|
resource.methods['get'].display_name.should eq 'resource type displayName'
|
362
|
+
resource.resource_path.should eq '/foo'
|
363
|
+
resource.resource_path_name.should eq 'foo'
|
364
|
+
end
|
365
|
+
it 'sets the resource path name stripping out uri parameters' do
|
366
|
+
resource_with_parameter.apply_resource_type
|
367
|
+
resource_with_parameter.resource_path_name.should eq 'bar'
|
340
368
|
end
|
341
369
|
end
|
342
370
|
context 'when it has nested resources' do
|
@@ -352,7 +380,7 @@ describe Raml::Resource do
|
|
352
380
|
let(:resource_data) { {
|
353
381
|
'is' => [
|
354
382
|
{ 'description' => 'trait1 description' },
|
355
|
-
{ 'description' => 'trait2 description' }
|
383
|
+
{ 'description' => 'trait2 description' }
|
356
384
|
],
|
357
385
|
'get' => {},
|
358
386
|
'post' => {},
|
@@ -384,7 +412,7 @@ describe Raml::Resource do
|
|
384
412
|
end
|
385
413
|
context 'when called with a ResourceType::Instance' do
|
386
414
|
let(:root_data) { {
|
387
|
-
'title' => 'x',
|
415
|
+
'title' => 'x',
|
388
416
|
'baseUri' => 'http://foo.com',
|
389
417
|
'traits' => [ {
|
390
418
|
'secured' => { 'usage' => 'requires authentication' },
|
@@ -427,14 +455,4 @@ describe Raml::Resource do
|
|
427
455
|
end
|
428
456
|
end
|
429
457
|
end
|
430
|
-
|
431
|
-
describe '#document' do
|
432
|
-
it 'returns a String' do
|
433
|
-
subject.document.should be_a String
|
434
|
-
end
|
435
|
-
it 'should render the template' do
|
436
|
-
mock(Slim::Template).new(/templates\/resource.slim\z/, is_a(Hash)).mock!.render(is_a(Raml::Node)) { '' }
|
437
|
-
subject.document
|
438
|
-
end
|
439
|
-
end
|
440
458
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require_relative 'spec_helper'
|
3
3
|
|
4
4
|
describe Raml::ResourceType do
|
5
|
-
|
5
|
+
let(:name) { 'auditableResource' }
|
6
6
|
let(:data) {
|
7
7
|
YAML.load(%q(
|
8
8
|
post:
|
@@ -28,24 +28,24 @@ describe Raml::ResourceType do
|
|
28
28
|
subject { Raml::ResourceType.new(name, data, root) }
|
29
29
|
|
30
30
|
describe '#new' do
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
context 'with valid arguments' do
|
32
|
+
it { expect { subject }.to_not raise_error }
|
33
|
+
it { should be_a Raml::ResourceType }
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '#instantiate' do
|
38
38
|
context 'when the usage property is given' do
|
39
|
-
|
40
|
-
|
39
|
+
before { data['usage'] = 'Some text' }
|
40
|
+
it 'stores the usage property' do
|
41
41
|
subject.instantiate({}).usage.should eq data['usage']
|
42
|
-
|
43
|
-
|
42
|
+
end
|
43
|
+
end
|
44
44
|
context 'with invalid arguments' do
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
context 'when the resource type has nested resources' do
|
46
|
+
before { data['/foo'] = {} }
|
47
|
+
it { expect { subject.instantiate({}) }.to raise_error Raml::UnknownProperty, /\/foo/ }
|
48
|
+
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
data/test/raml/response_spec.rb
CHANGED
@@ -61,7 +61,7 @@ describe Raml::Response do
|
|
61
61
|
it { expect { subject }.to raise_error Raml::InvalidProperty, /body/ }
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
context 'when description property is not given' do
|
66
66
|
before { response_data.delete 'description' }
|
67
67
|
it { expect { subject }.to_not raise_error }
|
@@ -77,12 +77,9 @@ describe Raml::Response do
|
|
77
77
|
it 'should store the value' do
|
78
78
|
subject.description.should eq response_data['description']
|
79
79
|
end
|
80
|
-
it 'uses the description in the documentation' do
|
81
|
-
subject.document.should include response_data['description']
|
82
|
-
end
|
83
80
|
end
|
84
81
|
end
|
85
|
-
|
82
|
+
|
86
83
|
context 'when the headers parameter is given' do
|
87
84
|
context 'when the headers property is well formed' do
|
88
85
|
it { expect { subject }.to_not raise_error }
|
@@ -103,7 +100,7 @@ describe Raml::Response do
|
|
103
100
|
before { response_data['headers'] = { '1' => 'x'} }
|
104
101
|
it { expect { subject }.to raise_error Raml::InvalidProperty, /headers/ }
|
105
102
|
end
|
106
|
-
end
|
103
|
+
end
|
107
104
|
end
|
108
105
|
|
109
106
|
describe '#merge' do
|
@@ -132,9 +129,9 @@ describe Raml::Response do
|
|
132
129
|
end
|
133
130
|
end
|
134
131
|
context 'headers properties' do
|
135
|
-
let(:mixin_data) { {
|
132
|
+
let(:mixin_data) { {
|
136
133
|
'headers' => {
|
137
|
-
'header1' => {'description' => 'foo'},
|
134
|
+
'header1' => {'description' => 'foo'},
|
138
135
|
'header2' => {'description' => 'bar'}
|
139
136
|
}
|
140
137
|
} }
|
@@ -143,9 +140,9 @@ describe Raml::Response do
|
|
143
140
|
end
|
144
141
|
end
|
145
142
|
context 'body property' do
|
146
|
-
let(:mixin_data) { {
|
143
|
+
let(:mixin_data) { {
|
147
144
|
'body' => {
|
148
|
-
'text/mime1' => {'schema' => 'foo'},
|
145
|
+
'text/mime1' => {'schema' => 'foo'},
|
149
146
|
'text/mime2' => {'schema' => 'bar'}
|
150
147
|
}
|
151
148
|
} }
|
@@ -170,16 +167,16 @@ describe Raml::Response do
|
|
170
167
|
end
|
171
168
|
end
|
172
169
|
context 'headers properties' do
|
173
|
-
let(:response_data) { {
|
170
|
+
let(:response_data) { {
|
174
171
|
'headers' => {
|
175
|
-
'header1' => {'description' => 'foo'},
|
172
|
+
'header1' => {'description' => 'foo'},
|
176
173
|
'header2' => {'description' => 'bar'}
|
177
174
|
}
|
178
175
|
} }
|
179
176
|
context 'when the mixin headers are different from the response headers' do
|
180
|
-
let(:mixin_data) { {
|
177
|
+
let(:mixin_data) { {
|
181
178
|
'headers' => {
|
182
|
-
'header3' => {'description' => 'foo2'},
|
179
|
+
'header3' => {'description' => 'foo2'},
|
183
180
|
'header4' => {'description' => 'bar2'}
|
184
181
|
}
|
185
182
|
} }
|
@@ -188,10 +185,10 @@ describe Raml::Response do
|
|
188
185
|
end
|
189
186
|
end
|
190
187
|
context 'when the mixin headers overlap the the response headers' do
|
191
|
-
let(:mixin_data) { {
|
188
|
+
let(:mixin_data) { {
|
192
189
|
'headers' => {
|
193
|
-
'header2' => {'description' => 'bar3', 'displayName' => 'Header 3'},
|
194
|
-
'header3' => {'description' => 'foo2'},
|
190
|
+
'header2' => {'description' => 'bar3', 'displayName' => 'Header 3'},
|
191
|
+
'header3' => {'description' => 'foo2'},
|
195
192
|
'header4' => {'description' => 'bar2'}
|
196
193
|
}
|
197
194
|
} }
|
@@ -200,19 +197,19 @@ describe Raml::Response do
|
|
200
197
|
response.headers['header2'].display_name.should eq mixin.headers['header2'].display_name
|
201
198
|
response.headers['header2'].description.should eq mixin.headers['header2'].description
|
202
199
|
end
|
203
|
-
end
|
200
|
+
end
|
204
201
|
end
|
205
202
|
context 'body property' do
|
206
|
-
let(:response_data) { {
|
203
|
+
let(:response_data) { {
|
207
204
|
'body' => {
|
208
|
-
'text/mime1' => {'schema' => 'foo'},
|
205
|
+
'text/mime1' => {'schema' => 'foo'},
|
209
206
|
'text/mime2' => {'schema' => 'bar'}
|
210
207
|
}
|
211
208
|
} }
|
212
209
|
context 'when the mixin query parameters are different from the response headers' do
|
213
|
-
let(:mixin_data) { {
|
210
|
+
let(:mixin_data) { {
|
214
211
|
'body' => {
|
215
|
-
'text/mime3' => {'schema' => 'foo2'},
|
212
|
+
'text/mime3' => {'schema' => 'foo2'},
|
216
213
|
'text/mime4' => {'schema' => 'bar2'}
|
217
214
|
}
|
218
215
|
} }
|
@@ -221,10 +218,10 @@ describe Raml::Response do
|
|
221
218
|
end
|
222
219
|
end
|
223
220
|
context 'when the mixin query parameters overlap the the response query parameters' do
|
224
|
-
let(:mixin_data) { {
|
221
|
+
let(:mixin_data) { {
|
225
222
|
'body' => {
|
226
|
-
'text/mime2' => {'example' => 'Example 2'},
|
227
|
-
'text/mime3' => {'schema' => 'foo2'},
|
223
|
+
'text/mime2' => {'example' => 'Example 2'},
|
224
|
+
'text/mime3' => {'schema' => 'foo2'},
|
228
225
|
'text/mime4' => {'schema' => 'bar2'}
|
229
226
|
}
|
230
227
|
} }
|
@@ -232,20 +229,10 @@ describe Raml::Response do
|
|
232
229
|
response.merge(mixin).bodies.keys.should contain_exactly('text/mime1', 'text/mime2', 'text/mime3', 'text/mime4')
|
233
230
|
response.bodies['text/mime2'].example.should eq mixin.bodies['text/mime2'].example
|
234
231
|
end
|
235
|
-
end
|
232
|
+
end
|
236
233
|
end
|
237
234
|
end
|
238
235
|
end
|
239
236
|
end
|
240
237
|
end
|
241
|
-
|
242
|
-
describe '#document' do
|
243
|
-
it 'returns a String' do
|
244
|
-
subject.document.should be_a String
|
245
|
-
end
|
246
|
-
it 'should render the template' do
|
247
|
-
mock(Slim::Template).new(/templates\/response.slim\z/, is_a(Hash)).mock!.render(is_a(Raml::Node)) { '' }
|
248
|
-
subject.document
|
249
|
-
end
|
250
|
-
end
|
251
238
|
end
|