prmd 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +6 -4
- data/docs/schemata.md +5 -0
- data/lib/prmd/rake_tasks/doc.rb +5 -0
- data/lib/prmd/schema.rb +2 -0
- data/lib/prmd/templates/schema.erb +8 -1
- data/lib/prmd/templates/schemata.md.erb +9 -1
- data/lib/prmd/templates/schemata/helper.erb +6 -3
- data/lib/prmd/templates/schemata/link.md.erb +7 -1
- data/lib/prmd/templates/table_of_contents.erb +6 -4
- data/lib/prmd/version.rb +1 -1
- data/prmd.gemspec +2 -2
- data/test/commands/render_test.rb +18 -3
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7d549096116bdd614f84c9956e2de37d34d09721c8d67be4d189beab98787934
|
4
|
+
data.tar.gz: ecbd1909e6258876c49165bfdaaab02a6fcd99397bdd7470ec6b033c99381113
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92c5e9081ae01609eac6223fe89e1a487bf9924001d60ef14baf3557c7ea053ecefe010ab4ae2ba7f771c82266abc6c891cb610662c1d5d32b426331bb2dce0b
|
7
|
+
data.tar.gz: 9874013f4b85083bf9405dad926be63584a5856fa6810463f727bec82a81d363d350117a122db2fd90e865306f3dc3ec9f29e8a8de57d74d7c9512414dcb8d55
|
data/.travis.yml
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
3
|
+
- 2.3.8
|
4
|
+
- 2.4.10
|
5
|
+
- 2.5.8
|
6
|
+
- 2.6.6
|
7
|
+
- 2.7.2
|
6
8
|
- ruby-head
|
7
9
|
before_install:
|
8
|
-
- gem install bundler -v '~>
|
10
|
+
- gem install bundler -v '~> 2.0'
|
9
11
|
script: "bundle exec rake"
|
10
12
|
notifications:
|
11
13
|
email: false
|
data/docs/schemata.md
CHANGED
data/lib/prmd/rake_tasks/doc.rb
CHANGED
@@ -5,6 +5,7 @@ require 'prmd/url_generator'
|
|
5
5
|
require 'prmd/template'
|
6
6
|
require 'prmd/schema'
|
7
7
|
require 'prmd/link'
|
8
|
+
require_relative '../hash_helpers'
|
8
9
|
|
9
10
|
# :nodoc:
|
10
11
|
module Prmd
|
@@ -34,6 +35,10 @@ module Prmd
|
|
34
35
|
options = legacy_parameters(*args)
|
35
36
|
@files = options.fetch(:files) { [] }
|
36
37
|
super options, &block
|
38
|
+
if @options[:settings].is_a? String
|
39
|
+
settings = Prmd.load_schema_file(@options[:settings])
|
40
|
+
@options.merge! HashHelpers.deep_symbolize_keys(settings)
|
41
|
+
end
|
37
42
|
@options[:template] ||= Prmd::Template.template_dirname
|
38
43
|
end
|
39
44
|
|
data/lib/prmd/schema.rb
CHANGED
@@ -118,6 +118,8 @@ module Prmd
|
|
118
118
|
end
|
119
119
|
ref = id_ref || value['anyOf'].first
|
120
120
|
schema_example(ref)
|
121
|
+
elsif value.key?('allOf')
|
122
|
+
value['allOf'].map { |ref| schema_example(ref) }.reduce({}, &:merge)
|
121
123
|
elsif value.key?('properties') # nested properties
|
122
124
|
schema_example(value)
|
123
125
|
elsif value.key?('items') # array of objects
|
@@ -1,4 +1,11 @@
|
|
1
|
-
|
1
|
+
<%- if options[:doc][:toc] -%>
|
2
|
+
<%=
|
3
|
+
Prmd::Template::load('table_of_contents.erb', options[:template]).result({
|
4
|
+
options: options,
|
5
|
+
schema: schema
|
6
|
+
})
|
7
|
+
%>
|
8
|
+
<%- end -%>
|
2
9
|
<%=
|
3
10
|
schemata_template = Prmd::Template::load('schemata.md.erb', options[:template])
|
4
11
|
|
@@ -9,7 +9,8 @@
|
|
9
9
|
title = schemata['title'].split(' - ', 2).last
|
10
10
|
-%>
|
11
11
|
<%- unless options[:doc][:disable_title_and_description] %>
|
12
|
-
|
12
|
+
<a name="#resource-<%= resource %>"></a>
|
13
|
+
## <%= title %>
|
13
14
|
|
14
15
|
<%- if schemata['stability'] && !schemata['stability'].empty? %>
|
15
16
|
Stability: `<%= schemata['stability'] %>`
|
@@ -19,8 +20,13 @@ Stability: `<%= schemata['stability'] %>`
|
|
19
20
|
<%- end -%>
|
20
21
|
|
21
22
|
<%- if schemata['properties'] && !schemata['properties'].empty? %>
|
23
|
+
|
22
24
|
### Attributes
|
23
25
|
|
26
|
+
<details>
|
27
|
+
<summary>Details</summary>
|
28
|
+
|
29
|
+
|
24
30
|
| Name | Type | Description | Example |
|
25
31
|
| ------- | ------- | ------- | ------- |
|
26
32
|
<%- refs = extract_schemata_refs(schema, schemata['properties']).map {|v| v && v.split("/")} %>
|
@@ -33,6 +39,8 @@ Stability: `<%= schemata['stability'] %>`
|
|
33
39
|
| **<%= name %>** | *<%= type %>* | <%= description %> | <%= example %> |
|
34
40
|
<%- end %>
|
35
41
|
|
42
|
+
</details>
|
43
|
+
|
36
44
|
<%- end %>
|
37
45
|
<%- (schemata['links'] || []).each do |link, datum| %>
|
38
46
|
<%=
|
@@ -137,7 +137,10 @@
|
|
137
137
|
end
|
138
138
|
|
139
139
|
if value['pattern']
|
140
|
-
|
140
|
+
# Prevent the pipe regex pattern characters from being interpreted as markdown table:
|
141
|
+
pattern = value['pattern'].gsub(/\|/, '|')
|
142
|
+
|
143
|
+
description += "<br/> **pattern:** <pre>#{pattern}</pre>"
|
141
144
|
end
|
142
145
|
|
143
146
|
if value['minLength'] || value['maxLength']
|
@@ -175,7 +178,7 @@
|
|
175
178
|
else
|
176
179
|
''
|
177
180
|
end
|
178
|
-
type += (value['format'] || (value['type'] - ['null']).
|
181
|
+
type += (value['format'] || (value['type'] - ['null']).join(' or '))
|
179
182
|
[key, type, description, example]
|
180
183
|
end
|
181
184
|
|
@@ -183,8 +186,8 @@
|
|
183
186
|
def build_link_path(schema, link)
|
184
187
|
link['href'].gsub(%r|(\{\([^\)]+\)\})|) do |ref|
|
185
188
|
ref = ref.gsub('%2F', '/').gsub('%23', '#').gsub(%r|[\{\(\)\}]|, '')
|
186
|
-
ref_resource = ref.split('#/definitions/').last.split('/').first.gsub('-','_')
|
187
189
|
identity_key, identity_value = schema.dereference(ref)
|
190
|
+
ref_resource = identity_key.split('#/definitions/').last.split('/').first.gsub('-','_')
|
188
191
|
if identity_value.has_key?('anyOf')
|
189
192
|
'{' + ref_resource + '_' + identity_value['anyOf'].map {|r| r['$ref'].split('/').last}.join('_or_') + '}'
|
190
193
|
else
|
@@ -3,7 +3,11 @@
|
|
3
3
|
response_example = link['response_example']
|
4
4
|
link_schema_properties_template = Prmd::Template.load_template('link_schema_properties.md.erb', options[:template])
|
5
5
|
-%>
|
6
|
-
|
6
|
+
<a name="link-<%= link['method'] %>-<%= resource %>-<%= link['href'] %>"></a>
|
7
|
+
### <%= title %> <%= link['title'] %>
|
8
|
+
|
9
|
+
<details>
|
10
|
+
<summary>Details</summary>
|
7
11
|
|
8
12
|
<%= link['description'] %>
|
9
13
|
|
@@ -78,3 +82,5 @@ HTTP/1.1 <%=
|
|
78
82
|
<%- end %>
|
79
83
|
```
|
80
84
|
<%- end %>
|
85
|
+
|
86
|
+
</details>
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
1
|
+
<%- Prmd::Template.render('schemata/helper.erb', options[:template]) -%>
|
2
|
+
## The table of contents
|
3
|
+
|
2
4
|
<% schema['properties'].keys.sort.map do |key| %>
|
3
5
|
<% resource, property = key, schema['properties'][key] %>
|
4
6
|
<% _, schemata = schema.dereference(property) %>
|
5
|
-
|
7
|
+
- <a href="#resource-<%= resource %>"><%= schemata['title'].split(' - ', 2).last %></a>
|
6
8
|
<% schemata.fetch('links', []).each do |l| %>
|
7
|
-
|
9
|
+
- <a href="#link-<%= l['method'] %>-<%= resource %>-<%= l['href'] %>"><%= l['method'] %> <%= build_link_path(schema, l) %></a>
|
8
10
|
<% end %>
|
9
|
-
|
11
|
+
<% end %>
|
data/lib/prmd/version.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
module Prmd
|
3
3
|
# Well, duh, its a Version module, what did you expect?
|
4
4
|
module Version
|
5
|
-
MAJOR, MINOR, TEENY, PATCH = 0,
|
5
|
+
MAJOR, MINOR, TEENY, PATCH = 0, 14, 0, nil
|
6
6
|
# version string
|
7
7
|
# @return [String]
|
8
8
|
STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze
|
data/prmd.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'erubis', '~> 2.7'
|
22
22
|
spec.add_dependency 'json_schema', '~> 0.3', '>= 0.3.1'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler', '~>
|
25
|
-
spec.add_development_dependency 'rake', '
|
24
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
25
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
26
26
|
spec.add_development_dependency 'minitest', '~> 5.4'
|
27
27
|
end
|
@@ -37,10 +37,10 @@ class InteragentRenderTest < Minitest::Test
|
|
37
37
|
template = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'prmd', 'templates'))
|
38
38
|
markdown = Prmd.render(schema, template: template, doc: { toc: true })
|
39
39
|
|
40
|
-
assert_match
|
40
|
+
assert_match /^## The table of contents/, markdown
|
41
41
|
assert_match '<a href="#resource-app"', markdown
|
42
42
|
assert_match '- <a href="#link-POST-app-/apps">POST /apps', markdown
|
43
|
-
assert_match '<a name="link-POST-app-/apps"', markdown
|
43
|
+
assert_match '<a name="link-POST-app-/apps"></a>', markdown
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_render_for_example_as_an_array
|
@@ -50,6 +50,12 @@ class InteragentRenderTest < Minitest::Test
|
|
50
50
|
assert_match expression, markdown
|
51
51
|
end
|
52
52
|
|
53
|
+
def test_render_for_regex_patterns_with_pipes
|
54
|
+
expression = /<pre>\(\^first\$|\^second\$\)<\/pre> \| \`"second"\` \|\n/
|
55
|
+
markdown = render
|
56
|
+
assert_match expression, markdown
|
57
|
+
end
|
58
|
+
|
53
59
|
private
|
54
60
|
|
55
61
|
def data
|
@@ -113,6 +119,12 @@ class InteragentRenderTest < Minitest::Test
|
|
113
119
|
'example' => 'OPTION2',
|
114
120
|
'enum' => 'OPTION2'
|
115
121
|
},
|
122
|
+
'patterned-string' => {
|
123
|
+
'description' => 'A string with a regex pattern applied to it.',
|
124
|
+
'type' => 'string',
|
125
|
+
'example' => 'second',
|
126
|
+
'pattern' => '(^first$|^second$)'
|
127
|
+
},
|
116
128
|
'option1' => {
|
117
129
|
'properties' => {
|
118
130
|
'type' => {
|
@@ -175,7 +187,10 @@ class InteragentRenderTest < Minitest::Test
|
|
175
187
|
},
|
176
188
|
'options' => {
|
177
189
|
'$ref' => '#/definitions/config-var/definitions/options'
|
178
|
-
}
|
190
|
+
},
|
191
|
+
'patterned-string' => {
|
192
|
+
'$ref' => '#/definitions/config-var/definitions/patterned-string'
|
193
|
+
},
|
179
194
|
}
|
180
195
|
}
|
181
196
|
},
|
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.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- geemus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|
@@ -50,28 +50,28 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '2.0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '2.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rake
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: 12.3.3
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - "
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
74
|
+
version: 12.3.3
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: minitest
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,8 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
211
|
- !ruby/object:Gem::Version
|
212
212
|
version: '0'
|
213
213
|
requirements: []
|
214
|
-
|
215
|
-
rubygems_version: 2.5.1
|
214
|
+
rubygems_version: 3.1.4
|
216
215
|
signing_key:
|
217
216
|
specification_version: 4
|
218
217
|
summary: JSON Schema tooling
|