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 +8 -8
- data/Gemfile.lock +1 -1
- data/lib/prmd/schema.rb +7 -4
- data/lib/prmd/templates/schema.erb +2 -2
- data/lib/prmd/templates/schemata/helper.erb +39 -26
- data/lib/prmd/templates/schemata/link.erb +2 -0
- data/lib/prmd/templates/schemata/link_curl_example.erb +3 -4
- data/lib/prmd/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzI3ZTkyMWEwZDAzNzc5ZDQxZDI3ZmUwMWQ2MTVhZGIyNTRmNzI0NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTdiNDJlZWQ1YzkxYmU1OWRkODU1NWY4YmVhZThiMzhjZjhmMjA0YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDkxMjczOWQ0MmMwMDEzN2JkYzVhOGZmNTUyZGQxYzg4ZDY4N2EyZDMzNTIx
|
10
|
+
YTI4ZjJiMTBhMTdlNmU5MTU2MmRmMzY0MjVkNzY4YTBkMjEyYTkzODk2NjI5
|
11
|
+
MmMxN2E3NTg1OTAzNWRmOWE1MjdmMTQyY2Y0YmExNzIwNWJmNGM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGZlY2E3NzVhOGRkN2YxODM1ZjJkMTk1ZDAwNzNiNjE4Yzk3MjJmNjhjMDhk
|
14
|
+
NWJkNDJhNDY5M2E5OWViY2VhM2MyZGI0ZTMxMjI0MTFjMzk5YWVjN2JjYWI0
|
15
|
+
OTJiN2YzZmUxMzY5YWRhODA2ZDM4ZDNlNmJlMzQ4N2Y0NmFhN2I=
|
data/Gemfile.lock
CHANGED
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
|
-
|
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
|
-
|
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
|
-
|
70
|
+
[items['example']]
|
68
71
|
else
|
69
|
-
|
72
|
+
[schema_example(items)]
|
70
73
|
end
|
71
74
|
end
|
72
75
|
end
|
@@ -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['
|
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['
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
58
|
+
attributes << build_attribute(schema, key, value)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
return attributes
|
62
|
+
end
|
56
63
|
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
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|[\{\(\)\}]|, '')
|
@@ -13,11 +13,10 @@
|
|
13
13
|
end
|
14
14
|
%>
|
15
15
|
$ curl -n -X <%= link['method'] %> <%= schema.href %><%= path -%>
|
16
|
-
<%-
|
16
|
+
<%- if !data.empty? && link['method'].upcase == 'GET' %> \
|
17
17
|
-H "Content-Type: <%= options[:content_type] %>" \
|
18
|
-
-d '<%= data
|
19
|
-
<%-
|
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
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.
|
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-
|
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:
|