prmd 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CONTRIBUTORS.md +8 -0
- data/Gemfile.lock +6 -6
- data/README.md +57 -8
- data/Rakefile +4 -4
- data/bin/prmd +3 -117
- data/docs/schemata.md +11 -11
- data/lib/prmd.rb +7 -18
- data/lib/prmd/cli.rb +108 -0
- 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/commands.rb +4 -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/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.md.erb +37 -0
- 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} +8 -2
- 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/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.erb +0 -47
- data/lib/prmd/templates/schemata/link.erb +0 -61
data/test/helpers.rb
CHANGED
@@ -1,11 +1,66 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'minitest'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'prmd'
|
4
|
+
require 'prmd/cli/base'
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
module Prmd
|
7
|
+
module CLI
|
8
|
+
module Base
|
9
|
+
# silence noop_execute
|
10
|
+
def noop_execute(options = {})
|
11
|
+
options
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module CliBaseTestHelpers
|
18
|
+
def argv_for_test_run
|
19
|
+
[]
|
20
|
+
end
|
21
|
+
|
22
|
+
def options_for_test_run
|
23
|
+
{ }
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate_parse_options(options)
|
27
|
+
#
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_run_options(options)
|
31
|
+
assert_equal options[:noop], true
|
32
|
+
validate_parse_options options
|
33
|
+
end
|
34
|
+
|
35
|
+
def command_module
|
36
|
+
#
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_make_parser
|
40
|
+
parser = command_module.make_parser
|
41
|
+
assert_kind_of OptionParser, parser
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_parse_options
|
45
|
+
opts = command_module.parse_options(argv_for_test_run, options_for_test_run)
|
46
|
+
|
47
|
+
validate_parse_options opts
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_run
|
51
|
+
opts = command_module.run(argv_for_test_run,
|
52
|
+
options_for_test_run.merge(noop: true))
|
53
|
+
|
54
|
+
validate_run_options opts
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def input_schemas_path(*args)
|
59
|
+
@data_path ||= File.expand_path(File.join(*args),
|
60
|
+
File.join(File.dirname(__FILE__),
|
61
|
+
'schemata/input'))
|
7
62
|
end
|
8
63
|
|
9
64
|
def user_input_schema
|
10
|
-
|
65
|
+
@user_input_schema ||= Prmd.combine(input_schemas_path('user.json'))
|
11
66
|
end
|
data/test/schema_test.rb
CHANGED
@@ -2,33 +2,39 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helpers'))
|
|
2
2
|
|
3
3
|
class SchemaTest < Minitest::Test
|
4
4
|
def test_dereference_with_ref
|
5
|
-
key, value = user_input_schema.dereference(
|
5
|
+
key, value = user_input_schema.dereference(
|
6
6
|
'$ref' => '#/definitions/user/definitions/id'
|
7
|
-
|
7
|
+
)
|
8
8
|
assert_equal(key, '#/definitions/user/definitions/id')
|
9
|
-
|
9
|
+
user_id = user_input_schema['definitions']['user']['definitions']['id']
|
10
|
+
assert_equal(value, user_id)
|
10
11
|
end
|
11
12
|
|
12
13
|
def test_dereference_without_ref
|
13
|
-
key, value = user_input_schema.dereference(
|
14
|
+
key, value = user_input_schema.dereference(
|
15
|
+
'#/definitions/user/definitions/id'
|
16
|
+
)
|
14
17
|
assert_equal(key, '#/definitions/user/definitions/id')
|
15
|
-
|
18
|
+
user_id = user_input_schema['definitions']['user']['definitions']['id']
|
19
|
+
assert_equal(value, user_id)
|
16
20
|
end
|
17
21
|
|
18
22
|
def test_dereference_with_nested_ref
|
19
|
-
key, value = user_input_schema.dereference(
|
23
|
+
key, value = user_input_schema.dereference(
|
20
24
|
'$ref' => '#/definitions/user/definitions/identity'
|
21
|
-
|
25
|
+
)
|
22
26
|
assert_equal(key, '#/definitions/user/definitions/id')
|
23
|
-
|
27
|
+
user_id = user_input_schema['definitions']['user']['definitions']['id']
|
28
|
+
assert_equal(value, user_id)
|
24
29
|
end
|
25
30
|
|
26
31
|
def test_dereference_with_local_context
|
27
|
-
key, value = user_input_schema.dereference(
|
32
|
+
key, value = user_input_schema.dereference(
|
28
33
|
'$ref' => '#/definitions/user/properties/id',
|
29
34
|
'override' => true
|
30
|
-
|
35
|
+
)
|
31
36
|
assert_equal(key, '#/definitions/user/definitions/id')
|
32
|
-
|
37
|
+
user_id = user_input_schema['definitions']['user']['definitions']['id']
|
38
|
+
assert_equal(value, { 'override' => true }.merge(user_id))
|
33
39
|
end
|
34
40
|
end
|
metadata
CHANGED
@@ -1,85 +1,91 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.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-
|
11
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json_schema
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.3'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.3.1
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.3'
|
44
|
+
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 0.3.1
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: bundler
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - ~>
|
51
|
+
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '1.3'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- - ~>
|
58
|
+
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: '1.3'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rake
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - ~>
|
65
|
+
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '10.
|
67
|
+
version: '10.3'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- - ~>
|
72
|
+
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '10.
|
74
|
+
version: '10.3'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: minitest
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- - ~>
|
79
|
+
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: '5.
|
81
|
+
version: '5.4'
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- - ~>
|
86
|
+
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version: '5.
|
88
|
+
version: '5.4'
|
83
89
|
description: scaffold, verify and generate docs from JSON Schema
|
84
90
|
email:
|
85
91
|
- geemus@gmail.com
|
@@ -88,8 +94,8 @@ executables:
|
|
88
94
|
extensions: []
|
89
95
|
extra_rdoc_files: []
|
90
96
|
files:
|
91
|
-
- .gitignore
|
92
|
-
- .travis.yml
|
97
|
+
- ".gitignore"
|
98
|
+
- ".travis.yml"
|
93
99
|
- CONTRIBUTING.md
|
94
100
|
- CONTRIBUTORS.md
|
95
101
|
- Gemfile
|
@@ -100,28 +106,59 @@ files:
|
|
100
106
|
- bin/prmd
|
101
107
|
- docs/schemata.md
|
102
108
|
- lib/prmd.rb
|
109
|
+
- lib/prmd/cli.rb
|
110
|
+
- lib/prmd/cli/base.rb
|
111
|
+
- lib/prmd/cli/combine.rb
|
112
|
+
- lib/prmd/cli/doc.rb
|
113
|
+
- lib/prmd/cli/generate.rb
|
114
|
+
- lib/prmd/cli/render.rb
|
115
|
+
- lib/prmd/cli/verify.rb
|
116
|
+
- lib/prmd/commands.rb
|
103
117
|
- lib/prmd/commands/combine.rb
|
104
|
-
- lib/prmd/commands/expand.rb
|
105
118
|
- lib/prmd/commands/init.rb
|
106
119
|
- lib/prmd/commands/render.rb
|
107
120
|
- lib/prmd/commands/verify.rb
|
121
|
+
- lib/prmd/core/combiner.rb
|
122
|
+
- lib/prmd/core/generator.rb
|
123
|
+
- lib/prmd/core/renderer.rb
|
124
|
+
- lib/prmd/core/schema_hash.rb
|
125
|
+
- lib/prmd/core_ext/optparse.rb
|
126
|
+
- lib/prmd/hash_helpers.rb
|
127
|
+
- lib/prmd/load_schema_file.rb
|
128
|
+
- lib/prmd/rake_tasks/base.rb
|
129
|
+
- lib/prmd/rake_tasks/combine.rb
|
130
|
+
- lib/prmd/rake_tasks/doc.rb
|
131
|
+
- lib/prmd/rake_tasks/verify.rb
|
108
132
|
- lib/prmd/schema.rb
|
109
133
|
- lib/prmd/template.rb
|
110
|
-
- lib/prmd/templates/
|
134
|
+
- lib/prmd/templates/combine_head.json
|
135
|
+
- lib/prmd/templates/init_default.json
|
136
|
+
- lib/prmd/templates/init_resource.json.erb
|
137
|
+
- lib/prmd/templates/link_schema_properties.md.erb
|
111
138
|
- lib/prmd/templates/schema.erb
|
112
|
-
- lib/prmd/templates/schemata.erb
|
139
|
+
- lib/prmd/templates/schemata.md.erb
|
113
140
|
- lib/prmd/templates/schemata/helper.erb
|
114
|
-
- lib/prmd/templates/schemata/link.erb
|
115
|
-
- lib/prmd/templates/schemata/link_curl_example.erb
|
141
|
+
- lib/prmd/templates/schemata/link.md.erb
|
142
|
+
- lib/prmd/templates/schemata/link_curl_example.md.erb
|
116
143
|
- lib/prmd/url_generator.rb
|
144
|
+
- lib/prmd/url_generators/generators/default.rb
|
145
|
+
- lib/prmd/url_generators/generators/json.rb
|
117
146
|
- lib/prmd/version.rb
|
118
147
|
- prmd.gemspec
|
119
148
|
- schemas/hyper-schema.json
|
120
149
|
- schemas/interagent-hyper-schema.json
|
121
150
|
- schemas/schema.json
|
151
|
+
- test/cli/combine_test.rb
|
152
|
+
- test/cli/doc_test.rb
|
153
|
+
- test/cli/generate_test.rb
|
154
|
+
- test/cli/render_test.rb
|
155
|
+
- test/cli/verify_test.rb
|
156
|
+
- test/commands/init_test.rb
|
157
|
+
- test/commands/render_test.rb
|
122
158
|
- test/commands/verify_test.rb
|
123
159
|
- test/helpers.rb
|
124
160
|
- test/schema_test.rb
|
161
|
+
- test/schemata/input/doc-settings.json
|
125
162
|
- test/schemata/input/meta.json
|
126
163
|
- test/schemata/input/user.json
|
127
164
|
homepage: https://github.com/heroku/prmd
|
@@ -134,23 +171,31 @@ require_paths:
|
|
134
171
|
- lib
|
135
172
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
173
|
requirements:
|
137
|
-
- -
|
174
|
+
- - ">="
|
138
175
|
- !ruby/object:Gem::Version
|
139
176
|
version: '0'
|
140
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
178
|
requirements:
|
142
|
-
- -
|
179
|
+
- - ">="
|
143
180
|
- !ruby/object:Gem::Version
|
144
181
|
version: '0'
|
145
182
|
requirements: []
|
146
183
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.2.2
|
148
185
|
signing_key:
|
149
186
|
specification_version: 4
|
150
187
|
summary: JSON Schema tooling
|
151
188
|
test_files:
|
189
|
+
- test/cli/combine_test.rb
|
190
|
+
- test/cli/doc_test.rb
|
191
|
+
- test/cli/generate_test.rb
|
192
|
+
- test/cli/render_test.rb
|
193
|
+
- test/cli/verify_test.rb
|
194
|
+
- test/commands/init_test.rb
|
195
|
+
- test/commands/render_test.rb
|
152
196
|
- test/commands/verify_test.rb
|
153
197
|
- test/helpers.rb
|
154
198
|
- test/schema_test.rb
|
199
|
+
- test/schemata/input/doc-settings.json
|
155
200
|
- test/schemata/input/meta.json
|
156
201
|
- test/schemata/input/user.json
|
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
|