jekyll-ramler 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +9 -2
- data/Gemfile.lock +1 -1
- data/jekyll-ramler.gemspec +1 -1
- data/lib/utils.rb +9 -1
- data/spec/utils_raml_schema_generator_spec.rb +39 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8c8f7b9ff188f55b8e43ba97d0a9008adf597f9
|
4
|
+
data.tar.gz: 17a4cd41e1e904142dffa6b51a02a45d8d6edbb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 986223e927a63c61221a9fb1f271fc2d90a7b57ff265c0b56261f8a0bafd64baa5a63da38336ebfb2b60cd739edecd7504f043406e5283ef52cf703ab59c3738
|
7
|
+
data.tar.gz: a9844a050da4c5aba6beac0299839bd15682b434989c08dad4e4fe71ceaeb85bda721d43eb61a9120e932c8cd2e0da6f9ef52baf33f825d9bb2fcc86e6bc0c9f
|
data/CHANGELOG
CHANGED
@@ -3,13 +3,20 @@ CHANGELOG
|
|
3
3
|
|
4
4
|
This project does *not* adhere to Semantic Versioning
|
5
5
|
|
6
|
-
## 0.0.
|
6
|
+
## 0.0.6 - 2015-02-23
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
|
10
|
+
- JSON Schema is now generated based on RAML if application/json is present
|
11
|
+
and nil
|
12
|
+
|
13
|
+
## 0.0.5 - 2015-02-18
|
7
14
|
|
8
15
|
### Fixed
|
9
16
|
|
10
17
|
- Security pages are back to using the layout defined for resource pages
|
11
18
|
|
12
|
-
## 0.0.4 -
|
19
|
+
## 0.0.4 - 2015-02-18
|
13
20
|
|
14
21
|
### Fixed
|
15
22
|
|
data/Gemfile.lock
CHANGED
data/jekyll-ramler.gemspec
CHANGED
data/lib/utils.rb
CHANGED
@@ -42,7 +42,7 @@ module Jekyll
|
|
42
42
|
|
43
43
|
if obj.include?('body')
|
44
44
|
if obj['body'].fetch('application/x-www-form-urlencoded', {}).include?('formParameters')
|
45
|
-
if
|
45
|
+
if insert_json_schema?(obj)
|
46
46
|
insert_json_schema(obj, generate_json_schema(obj))
|
47
47
|
end
|
48
48
|
end
|
@@ -54,6 +54,7 @@ module Jekyll
|
|
54
54
|
|
55
55
|
# Inserts provided JSON Schema into obj['body']['application/json']['schema']
|
56
56
|
def insert_json_schema(obj, schema)
|
57
|
+
obj['body']['application/json'] = {} if obj['body']['application/json'].nil?
|
57
58
|
obj['body']['application/json']['schema'] = schema
|
58
59
|
end
|
59
60
|
|
@@ -88,6 +89,13 @@ module Jekyll
|
|
88
89
|
|
89
90
|
JSON.pretty_generate(schema_hash)
|
90
91
|
end
|
92
|
+
|
93
|
+
def insert_json_schema?(obj)
|
94
|
+
return false if !obj['body'].include?('application/json')
|
95
|
+
json_hash = obj['body']['application/json']
|
96
|
+
json_hash = {} if json_hash.nil?
|
97
|
+
!(json_hash.include?('schema'))
|
98
|
+
end
|
91
99
|
end
|
92
100
|
|
93
101
|
class JsonSchemaCompiler
|
@@ -38,6 +38,32 @@ describe 'Utils' do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
context '.insert_json_schema?' do
|
42
|
+
it 'returns true if application/json does not contain "schema"' do
|
43
|
+
method = @raml_hash['resources']['/test_resource']['post']
|
44
|
+
method['body']['application/json'] = {}
|
45
|
+
expect(@rsg.insert_json_schema?(method)).to be true
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns true if application/json is nil' do
|
49
|
+
method = @raml_hash['resources']['/test_resource']['post']
|
50
|
+
method['body']['application/json'] = nil
|
51
|
+
expect(@rsg.insert_json_schema?(method)).to be true
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns false if there is no application/json' do
|
55
|
+
method = @raml_hash['resources']['/test_resource']['post']
|
56
|
+
method['body'].delete('application/json')
|
57
|
+
expect(@rsg.insert_json_schema?(method)).to be false
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns false if application/json contains "schema"' do
|
61
|
+
method = @raml_hash['resources']['/test_resource']['post']
|
62
|
+
method['body']['application/json'] = {"schema" => "{A Schema!}"}
|
63
|
+
expect(@rsg.insert_json_schema?(method)).to be false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
41
67
|
context '.insert_json_schema' do
|
42
68
|
it 'inserts an appropriate string into application/json:schema' do
|
43
69
|
@raml_hash['resources']['/test_resource']['post']['body']['application/json'] = {}
|
@@ -55,6 +81,19 @@ describe 'Utils' do
|
|
55
81
|
it 'throws an error if provided object does not have expected properties' do
|
56
82
|
expect{@rsg.insert_json_schema(@raml_hash, 'foobar')}.to raise_error
|
57
83
|
end
|
84
|
+
|
85
|
+
it 'elegantly handles a nil application/json and inserts an appropriate string into application/json:schema' do
|
86
|
+
@raml_hash['resources']['/test_resource']['post']['body']['application/json'] = nil
|
87
|
+
orig_raml_hash = DeepClone.clone @raml_hash
|
88
|
+
|
89
|
+
json_schema = @rsg.generate_json_schema(@raml_hash['resources']['/test_resource']['post'])
|
90
|
+
@rsg.insert_json_schema(@raml_hash['resources']['/test_resource']['post'], json_schema)
|
91
|
+
|
92
|
+
expect(@raml_hash['resources']['/test_resource']['post']['body']['application/json']).to include('schema')
|
93
|
+
expect(@raml_hash['resources']['/test_resource']['post']['body']['application/json']['schema']).to eq(json_schema)
|
94
|
+
@raml_hash['resources']['/test_resource']['post']['body']['application/json'] = nil
|
95
|
+
expect(@raml_hash).to eq(orig_raml_hash)
|
96
|
+
end
|
58
97
|
end
|
59
98
|
|
60
99
|
context '.insert_schemas' do
|