jekyll-ramler 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c62d98f44e879c5e455e68126e04798618d9e5e
4
- data.tar.gz: 9d364fb6a8ee65e00aa6c4878e1f3318a33caef6
3
+ metadata.gz: e8c8f7b9ff188f55b8e43ba97d0a9008adf597f9
4
+ data.tar.gz: 17a4cd41e1e904142dffa6b51a02a45d8d6edbb0
5
5
  SHA512:
6
- metadata.gz: 52771dd08ccbb20433c6e6f5f0a00ce71633e20387cb2235eac9000186b112735ca23dc03cae6465698a85a8b02d624780d86a9ed5269b2ec97e5ae785415a1f
7
- data.tar.gz: 0d9bde906a622c2330ecd3b60c65798d3b25ad3c6b5b503c2d4248777a62c763f13a86c8ab2b560e43957e696d55a7e1011ca6fe7555cb6a5153a509ebb88482
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.5 - 2014-02-18
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 - 2014-02-18
19
+ ## 0.0.4 - 2015-02-18
13
20
 
14
21
  ### Fixed
15
22
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-ramler (0.0.5)
4
+ jekyll-ramler (0.0.6)
5
5
  jekyll
6
6
 
7
7
  GEM
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jekyll-ramler'
3
- s.version = '0.0.5'
3
+ s.version = '0.0.6'
4
4
  s.date = '2015-02-09'
5
5
  s.authors = ['GovDelivery']
6
6
  s.email = 'support@govdelivery.com'
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 obj['body'].include?('application/json') && !(obj['body']['application/json'].include?('schema'))
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-ramler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - GovDelivery