prmd 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTg0MzdjNDU3M2MxOTk2ODE2MTYyMGU1YWM2OGNjMGQ5OWM5NWM4Mg==
4
+ YzI3ZTkyMWEwZDAzNzc5ZDQxZDI3ZmUwMWQ2MTVhZGIyNTRmNzI0NQ==
5
5
  data.tar.gz: !binary |-
6
- ZDViYzZmYmIxODY3YzFhOTBjZWZhMzM2ODNhZGJkNjk4MjViNDRjMw==
6
+ OTdiNDJlZWQ1YzkxYmU1OWRkODU1NWY4YmVhZThiMzhjZjhmMjA0YQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDgwNWU1ODRmNzc1MjJlNzU3NmUxNzg4OTk2NGVlZmY3NDRkODg2ZTYyN2E3
10
- NmU2ZjJkNjI0MWI1YmQ5MTFlYTZjZTdmNjJmZGE4MmExNzk5YjBlMDA5YjEy
11
- ZDhhOGJjMzRjMjQ1MzY2ZWY4ZTYzOWExMTA5OTFiODNjZDBjZjA=
9
+ NDkxMjczOWQ0MmMwMDEzN2JkYzVhOGZmNTUyZGQxYzg4ZDY4N2EyZDMzNTIx
10
+ YTI4ZjJiMTBhMTdlNmU5MTU2MmRmMzY0MjVkNzY4YTBkMjEyYTkzODk2NjI5
11
+ MmMxN2E3NTg1OTAzNWRmOWE1MjdmMTQyY2Y0YmExNzIwNWJmNGM=
12
12
  data.tar.gz: !binary |-
13
- NWRmM2Y5NjQyYmUwYjVlNzI4ZDYxY2VjMmYwNjA4MTJiMTE4NGVhNTQ1MzZl
14
- MzM1MjMwMjkzZGMwYWMzM2EwMDJiOTRjN2VlMjVhMzA5ZjczN2IzZjUyYmMx
15
- MDNmYjc4YTgyOTE1ZWNiMWJhYzhjMGZiOWI2MjkwZTMyZGVkODY=
13
+ NGZlY2E3NzVhOGRkN2YxODM1ZjJkMTk1ZDAwNzNiNjE4Yzk3MjJmNjhjMDhk
14
+ NWJkNDJhNDY5M2E5OWViY2VhM2MyZGI0ZTMxMjI0MTFjMzk5YWVjN2JjYWI0
15
+ OTJiN2YzZmUxMzY5YWRhODA2ZDM4ZDNlNmJlMzQ4N2Y0NmFhN2I=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prmd (0.5.0)
4
+ prmd (0.6.0)
5
5
  erubis (~> 2.7)
6
6
  json_schema (~> 0.1)
7
7
 
data/lib/prmd/schema.rb CHANGED
@@ -58,15 +58,18 @@ module Prmd
58
58
 
59
59
  def schema_value_example(value)
60
60
  if value.has_key?('example')
61
- return value['example']
61
+ value['example']
62
+ elsif value.has_key?('anyOf')
63
+ ref = value['anyOf'].detect {|ref| ref['$ref'].split('/').last == 'id'} || value['anyOf'].first
64
+ schema_example(ref)
62
65
  elsif value.has_key?('properties') # nested properties
63
- return schema_example(value)
66
+ schema_example(value)
64
67
  elsif value.has_key?('items') # array of objects
65
68
  _, items = dereference(value['items'])
66
69
  if value['items'].has_key?('example')
67
- return [items['example']]
70
+ [items['example']]
68
71
  else
69
- return [schema_example(items)]
72
+ [schema_example(items)]
70
73
  end
71
74
  end
72
75
  end
@@ -10,9 +10,9 @@
10
10
  schema: schema,
11
11
  schemata: schemata
12
12
  })
13
- rescue => e
13
+ rescue => e
14
14
  $stdout.puts("Error in resource: #{resource}")
15
15
  raise e
16
16
  end
17
- end.join("\n") << "\n"
17
+ end.join("\n")
18
18
  %>
@@ -6,6 +6,12 @@
6
6
  properties.each do |key, value|
7
7
  # found a reference to another element:
8
8
  _, value = schema.dereference(value)
9
+
10
+ # include top level reference to nested things, when top level is nullable
11
+ if value.has_key?('type') && value['type'].include?('null') && (value.has_key?('items') || value.has_key?('properties'))
12
+ attributes << build_attribute(schema, key, value)
13
+ end
14
+
9
15
  if value.has_key?('anyOf')
10
16
  descriptions = []
11
17
  examples = []
@@ -34,14 +40,14 @@
34
40
  attributes << [key, "string", description, example]
35
41
 
36
42
  # found a nested object
37
- elsif value['type'] == ['object'] && value['properties']
43
+ elsif value['properties']
38
44
  nested = extract_attributes(schema, value['properties'])
39
45
  nested.each do |attribute|
40
46
  attribute[0] = "#{key}:#{attribute[0]}"
41
47
  end
42
48
  attributes.concat(nested)
43
49
  # found an array with nested objects
44
- elsif value['type'] == ['array'] && value['items'] && value['items']['properties']
50
+ elsif value['items'] && value['items']['properties']
45
51
  nested = extract_attributes(schema, value['items']['properties'])
46
52
  nested.each do |attribute|
47
53
  attribute[0] = "#{key}/#{attribute[0]}"
@@ -49,37 +55,44 @@
49
55
  attributes.concat(nested)
50
56
  # just a regular attribute
51
57
  else
52
- description = value['description']
53
- if value['default']
54
- description += "<br/><b>default:</b> <code>#{value['default'].to_json}</code>"
55
- end
58
+ attributes << build_attribute(schema, key, value)
59
+ end
60
+ end
61
+ return attributes
62
+ end
56
63
 
57
- if value['enum']
58
- description += '<br/><b>one of:</b>' + [*value['enum']].map { |e| "<code>#{e.to_json}</code>" }.join(" or ")
59
- end
64
+ def build_attribute(schema, key, value)
65
+ description = value['description']
66
+ if value['default']
67
+ description += "<br/><b>default:</b> <code>#{value['default'].to_json}</code>"
68
+ end
60
69
 
61
- if value.has_key?('example')
62
- example = if value['example'].is_a?(Hash) && value['example'].has_key?('oneOf')
63
- value['example']['oneOf'].map { |e| "<code>#{e.to_json}</code>" }.join(" or ")
64
- else
65
- "<code>#{value['example'].to_json}</code>"
66
- end
67
- elsif value['type'] == ['array'] && value.has_key?('items')
68
- example = "<code>#{schema.schema_value_example(value)}</code>"
69
- end
70
+ if value['enum']
71
+ description += '<br/><b>one of:</b>' + [*value['enum']].map { |e| "<code>#{e.to_json}</code>" }.join(" or ")
72
+ end
70
73
 
71
- type = if value['type'].include?('null')
72
- 'nullable '
73
- else
74
- ''
75
- end
76
- type += (value['format'] || (value['type'] - ['null']).first)
77
- attributes << [key, type, description, example]
74
+ if value.has_key?('example')
75
+ example = if value['example'].is_a?(Hash) && value['example'].has_key?('oneOf')
76
+ value['example']['oneOf'].map { |e| "<code>#{e.to_json}</code>" }.join(" or ")
77
+ else
78
+ "<code>#{value['example'].to_json}</code>"
78
79
  end
80
+ elsif value['type'] == ['array'] && value.has_key?('items')
81
+ example = "<code>#{schema.schema_value_example(value)}</code>"
82
+ elsif value['type'].include?('null')
83
+ example = "<code>null</code>"
79
84
  end
80
- return attributes
85
+
86
+ type = if value['type'].include?('null')
87
+ 'nullable '
88
+ else
89
+ ''
90
+ end
91
+ type += (value['format'] || (value['type'] - ['null']).first)
92
+ [key, type, description, example]
81
93
  end
82
94
 
95
+
83
96
  def build_link_path(schema, link)
84
97
  link['href'].gsub(%r|(\{\([^\)]+\)\})|) do |ref|
85
98
  ref = ref.gsub('%2F', '/').gsub('%23', '#').gsub(%r|[\{\(\)\}]|, '')
@@ -43,6 +43,8 @@
43
43
  HTTP/1.1 <%= case link['rel']
44
44
  when 'create'
45
45
  '201 Created'
46
+ when 'empty'
47
+ '202 Accepted'
46
48
  else
47
49
  '200 OK'
48
50
  end %>
@@ -13,11 +13,10 @@
13
13
  end
14
14
  %>
15
15
  $ curl -n -X <%= link['method'] %> <%= schema.href %><%= path -%>
16
- <%- unless data.empty? || link['method'].upcase == 'GET' %> \
16
+ <%- if !data.empty? && link['method'].upcase == 'GET' %> \
17
17
  -H "Content-Type: <%= options[:content_type] %>" \
18
- -d '<%= data.to_json %>'
19
- <%- end %>
20
- <%- unless get_params.empty? || link['method'].upcase != 'GET' %> -G \
18
+ -d '<%= JSON.pretty_generate(data) %>'
19
+ <%- elsif !get_params.empty? && link['method'].upcase == 'GET' %> -G \
21
20
  -d <%= get_params.join(" \\\n -d ") %>
22
21
  <%- end %>
23
22
  ```
data/lib/prmd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Prmd
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -154,4 +154,3 @@ test_files:
154
154
  - test/schema_test.rb
155
155
  - test/schemata/input/meta.json
156
156
  - test/schemata/input/user.json
157
- has_rdoc: