prmd 0.6.1 → 0.7.0
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 +5 -13
- data/CONTRIBUTORS.md +8 -0
- data/Gemfile.lock +7 -7
- data/README.md +57 -8
- data/Rakefile +4 -4
- data/bin/prmd +3 -117
- data/docs/schemata.md +11 -11
- data/lib/prmd/cli/base.rb +151 -0
- data/lib/prmd/cli/combine.rb +42 -0
- data/lib/prmd/cli/doc.rb +69 -0
- data/lib/prmd/cli/generate.rb +44 -0
- data/lib/prmd/cli/render.rb +48 -0
- data/lib/prmd/cli/verify.rb +49 -0
- data/lib/prmd/cli.rb +108 -0
- data/lib/prmd/commands/combine.rb +85 -58
- data/lib/prmd/commands/init.rb +30 -98
- data/lib/prmd/commands/render.rb +30 -17
- data/lib/prmd/commands/verify.rb +78 -35
- data/lib/prmd/commands.rb +4 -0
- data/lib/prmd/core/combiner.rb +91 -0
- data/lib/prmd/core/generator.rb +27 -0
- data/lib/prmd/core/renderer.rb +56 -0
- data/lib/prmd/core/schema_hash.rb +47 -0
- data/lib/prmd/core_ext/optparse.rb +6 -0
- data/lib/prmd/hash_helpers.rb +38 -0
- data/lib/prmd/load_schema_file.rb +25 -0
- data/lib/prmd/rake_tasks/base.rb +33 -0
- data/lib/prmd/rake_tasks/combine.rb +50 -0
- data/lib/prmd/rake_tasks/doc.rb +73 -0
- data/lib/prmd/rake_tasks/verify.rb +60 -0
- data/lib/prmd/schema.rb +86 -34
- data/lib/prmd/template.rb +65 -8
- data/lib/prmd/templates/combine_head.json +6 -0
- data/lib/prmd/templates/init_default.json +9 -0
- data/lib/prmd/templates/init_resource.json.erb +90 -0
- data/lib/prmd/templates/link_schema_properties.md.erb +5 -0
- data/lib/prmd/templates/schema.erb +2 -2
- data/lib/prmd/templates/schemata/helper.erb +29 -15
- data/lib/prmd/templates/schemata/link.md.erb +74 -0
- data/lib/prmd/templates/schemata/{link_curl_example.erb → link_curl_example.md.erb} +9 -2
- data/lib/prmd/templates/schemata.md.erb +37 -0
- data/lib/prmd/url_generator.rb +11 -69
- data/lib/prmd/url_generators/generators/default.rb +66 -0
- data/lib/prmd/url_generators/generators/json.rb +30 -0
- data/lib/prmd/version.rb +10 -1
- data/lib/prmd.rb +7 -18
- data/prmd.gemspec +15 -15
- data/test/cli/combine_test.rb +23 -0
- data/test/cli/doc_test.rb +25 -0
- data/test/cli/generate_test.rb +23 -0
- data/test/cli/render_test.rb +25 -0
- data/test/cli/verify_test.rb +21 -0
- data/test/commands/init_test.rb +7 -0
- data/test/commands/render_test.rb +93 -0
- data/test/commands/verify_test.rb +60 -60
- data/test/helpers.rb +61 -6
- data/test/schema_test.rb +17 -11
- data/test/schemata/input/doc-settings.json +4 -0
- metadata +73 -28
- data/lib/prmd/commands/expand.rb +0 -108
- data/lib/prmd/templates/link_schema_properties.erb +0 -16
- data/lib/prmd/templates/schemata/link.erb +0 -61
- data/lib/prmd/templates/schemata.erb +0 -47
data/lib/prmd/commands/expand.rb
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
original = {
|
|
2
|
-
'description' => 'A foo is bar.',
|
|
3
|
-
'id' => 'schema/foo',
|
|
4
|
-
'title' => 'API - Foo',
|
|
5
|
-
|
|
6
|
-
'definitions' => {
|
|
7
|
-
'created-at' => {
|
|
8
|
-
'description' => 'when foo was created',
|
|
9
|
-
'format' => 'date-time'
|
|
10
|
-
},
|
|
11
|
-
'email' => {
|
|
12
|
-
'description' => 'email for foo',
|
|
13
|
-
'format' => 'email'
|
|
14
|
-
},
|
|
15
|
-
'id' => {
|
|
16
|
-
'description' => 'unique identifier for foo',
|
|
17
|
-
'format' => 'uuid'
|
|
18
|
-
},
|
|
19
|
-
'updated-at' => {
|
|
20
|
-
'description' => 'when foo was created',
|
|
21
|
-
'format' => 'date-time',
|
|
22
|
-
'type' => ['null', 'string']
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
expanded = original.dup
|
|
27
|
-
|
|
28
|
-
expanded = {
|
|
29
|
-
'$schema' => 'http://json-schema.org/draft-04/hyper-schema',
|
|
30
|
-
'definitions' => {},
|
|
31
|
-
'links' => [],
|
|
32
|
-
'properties' => {},
|
|
33
|
-
'type' => ['object']
|
|
34
|
-
}.merge!(expanded)
|
|
35
|
-
|
|
36
|
-
if original['definitions']
|
|
37
|
-
original['definitions'].each do |key, value|
|
|
38
|
-
default = case value['format']
|
|
39
|
-
when 'uuid'
|
|
40
|
-
{
|
|
41
|
-
'example' => '01234567-89ab-cdef-0123-456789abcdef',
|
|
42
|
-
'type' => ['string']
|
|
43
|
-
}
|
|
44
|
-
when 'email'
|
|
45
|
-
{
|
|
46
|
-
'example' => 'username@example.com',
|
|
47
|
-
'type' => ['string']
|
|
48
|
-
}
|
|
49
|
-
when 'date-time'
|
|
50
|
-
{
|
|
51
|
-
'example' => '2012-01-01T12:00:00Z',
|
|
52
|
-
'type' => ['string']
|
|
53
|
-
}
|
|
54
|
-
else
|
|
55
|
-
{}
|
|
56
|
-
end
|
|
57
|
-
expanded['definitions'][key] = default.merge!(value)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
if original['links']
|
|
62
|
-
original['links'].each do |key, value|
|
|
63
|
-
default = case value['title']
|
|
64
|
-
when 'Create'
|
|
65
|
-
{
|
|
66
|
-
'method' => 'POST',
|
|
67
|
-
'rel' => 'create'
|
|
68
|
-
}
|
|
69
|
-
when 'Delete'
|
|
70
|
-
{
|
|
71
|
-
'method' => 'DELETE',
|
|
72
|
-
'rel' => 'delete'
|
|
73
|
-
}
|
|
74
|
-
when 'Info'
|
|
75
|
-
{
|
|
76
|
-
'method' => 'GET',
|
|
77
|
-
'rel' => 'self'
|
|
78
|
-
}
|
|
79
|
-
when 'List'
|
|
80
|
-
{
|
|
81
|
-
'method' => 'GET',
|
|
82
|
-
'rel' => 'instances'
|
|
83
|
-
}
|
|
84
|
-
when 'Update'
|
|
85
|
-
{
|
|
86
|
-
'method' => 'PATCH',
|
|
87
|
-
'rel' => 'update'
|
|
88
|
-
}
|
|
89
|
-
end
|
|
90
|
-
expanded = original['links'][key] = default.merge!(value)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
#require 'json'
|
|
96
|
-
#require 'pp'
|
|
97
|
-
|
|
98
|
-
#puts
|
|
99
|
-
|
|
100
|
-
#puts original_json = JSON.pretty_generate(original)
|
|
101
|
-
#puts original_json.split("\n").length
|
|
102
|
-
|
|
103
|
-
#puts
|
|
104
|
-
|
|
105
|
-
#puts expanded_json = JSON.pretty_generate(expanded)
|
|
106
|
-
#puts expanded_json.split("\n").length
|
|
107
|
-
|
|
108
|
-
#puts
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<table>
|
|
2
|
-
<tr>
|
|
3
|
-
<th>Name</th>
|
|
4
|
-
<th>Type</th>
|
|
5
|
-
<th>Description</th>
|
|
6
|
-
<th>Example</th>
|
|
7
|
-
</tr>
|
|
8
|
-
<%- extract_attributes(schema, params).each do |(key, type, description, example)| %>
|
|
9
|
-
<tr>
|
|
10
|
-
<td><strong><%= key %></strong></td>
|
|
11
|
-
<td><em><%= type %></em></td>
|
|
12
|
-
<td><%= description %></td>
|
|
13
|
-
<td><%= example %></td>
|
|
14
|
-
</tr>
|
|
15
|
-
<%- end %>
|
|
16
|
-
</table>
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
<%-
|
|
2
|
-
path = build_link_path(schema, link)
|
|
3
|
-
link_schema_properties_template = Prmd::Template::load('link_schema_properties.erb', options[:template])
|
|
4
|
-
-%>
|
|
5
|
-
### <%= title %> <%= link['title'] %>
|
|
6
|
-
<%= link['description'] %>
|
|
7
|
-
|
|
8
|
-
```
|
|
9
|
-
<%= link['method'] %> <%= path %>
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
<%- if link.has_key?('schema') && link['schema'].has_key?('properties') %>
|
|
13
|
-
<%-
|
|
14
|
-
required, optional = link['schema']['properties'].partition do |k, v|
|
|
15
|
-
(link['schema']['required'] || []).include?(k)
|
|
16
|
-
end.map { |partition| Hash[partition] }
|
|
17
|
-
%>
|
|
18
|
-
<%- unless required.empty? %>
|
|
19
|
-
#### Required Parameters
|
|
20
|
-
<%= Erubis::Eruby.new(link_schema_properties_template).result(params: required, schema: schema) %>
|
|
21
|
-
|
|
22
|
-
<%- end %>
|
|
23
|
-
<%- unless optional.empty? %>
|
|
24
|
-
#### Optional Parameters
|
|
25
|
-
<%= Erubis::Eruby.new(link_schema_properties_template).result(params: optional, schema: schema) %>
|
|
26
|
-
<%- end %>
|
|
27
|
-
<%- end %>
|
|
28
|
-
|
|
29
|
-
#### Curl Example
|
|
30
|
-
<%=
|
|
31
|
-
Prmd::Template::render(File.join('schemata', 'link_curl_example.erb'), File.dirname(options[:template]), {
|
|
32
|
-
options: options,
|
|
33
|
-
resource: resource,
|
|
34
|
-
schema: schema,
|
|
35
|
-
schemata: schemata,
|
|
36
|
-
link: link,
|
|
37
|
-
path: path
|
|
38
|
-
})
|
|
39
|
-
%>
|
|
40
|
-
|
|
41
|
-
#### Response Example
|
|
42
|
-
```
|
|
43
|
-
HTTP/1.1 <%= case link['rel']
|
|
44
|
-
when 'create'
|
|
45
|
-
'201 Created'
|
|
46
|
-
when 'empty'
|
|
47
|
-
'202 Accepted'
|
|
48
|
-
else
|
|
49
|
-
'200 OK'
|
|
50
|
-
end %>
|
|
51
|
-
```
|
|
52
|
-
```json
|
|
53
|
-
<%- if link['rel'] == 'empty' %>
|
|
54
|
-
<%- elsif link.has_key?('targetSchema') && link['targetSchema'].has_key?('properties') %>
|
|
55
|
-
<%= JSON.pretty_generate(schema.schema_example(link['targetSchema'])) %>
|
|
56
|
-
<%- elsif link['rel'] == 'instances' %>
|
|
57
|
-
<%= JSON.pretty_generate([schema.schemata_example(resource)]) %>
|
|
58
|
-
<%- else %>
|
|
59
|
-
<%= JSON.pretty_generate(schema.schemata_example(resource)) %>
|
|
60
|
-
<%- end %>
|
|
61
|
-
```
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
<%-
|
|
2
|
-
return unless schemata.has_key?('links') && !schemata['links'].empty?
|
|
3
|
-
|
|
4
|
-
Prmd::Template::render(File.join('schemata', 'helper.erb'), options[:template], {
|
|
5
|
-
options: options,
|
|
6
|
-
resource: resource,
|
|
7
|
-
schema: schema,
|
|
8
|
-
schemata: schemata
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
title = schemata['title'].split(' - ', 2).last
|
|
12
|
-
%>
|
|
13
|
-
## <%= title %>
|
|
14
|
-
<%= schemata['description'] %>
|
|
15
|
-
|
|
16
|
-
<%- if schemata['properties'] %>
|
|
17
|
-
### Attributes
|
|
18
|
-
<table>
|
|
19
|
-
<tr>
|
|
20
|
-
<th>Name</th>
|
|
21
|
-
<th>Type</th>
|
|
22
|
-
<th>Description</th>
|
|
23
|
-
<th>Example</th>
|
|
24
|
-
</tr>
|
|
25
|
-
<%- extract_attributes(schema, schemata['properties']).each do |(key, type, description, example)| %>
|
|
26
|
-
<tr>
|
|
27
|
-
<td><strong><%= key %></strong></td>
|
|
28
|
-
<td><em><%= type %></em></td>
|
|
29
|
-
<td><%= description %></td>
|
|
30
|
-
<td><%= example %></td>
|
|
31
|
-
</tr>
|
|
32
|
-
<%- end %>
|
|
33
|
-
</table>
|
|
34
|
-
|
|
35
|
-
<%- end %>
|
|
36
|
-
<%- schemata['links'].each do |link, datum| %>
|
|
37
|
-
<%=
|
|
38
|
-
Prmd::Template::render(File.join('schemata', 'link.erb'), options[:template], {
|
|
39
|
-
options: options,
|
|
40
|
-
resource: resource,
|
|
41
|
-
schema: schema,
|
|
42
|
-
schemata: schemata,
|
|
43
|
-
link: link,
|
|
44
|
-
title: title
|
|
45
|
-
})
|
|
46
|
-
%>
|
|
47
|
-
<%- end -%>
|