prmd 0.7.0 → 0.7.1
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 +4 -4
- data/.gitignore +1 -0
- data/README.md +21 -4
- data/docs/schemata.md +4 -0
- data/lib/prmd/core/combiner.rb +4 -34
- data/lib/prmd/core/reference_localizer.rb +93 -0
- data/lib/prmd/load_schema_file.rb +3 -14
- data/lib/prmd/multi_loader.rb +2 -0
- data/lib/prmd/multi_loader/json.rb +19 -0
- data/lib/prmd/multi_loader/loader.rb +128 -0
- data/lib/prmd/multi_loader/toml.rb +19 -0
- data/lib/prmd/multi_loader/yajl.rb +19 -0
- data/lib/prmd/multi_loader/yaml.rb +19 -0
- data/lib/prmd/multi_loader/yml.rb +2 -0
- data/lib/prmd/rake_tasks/base.rb +33 -5
- data/lib/prmd/rake_tasks/combine.rb +20 -4
- data/lib/prmd/rake_tasks/doc.rb +24 -8
- data/lib/prmd/rake_tasks/verify.rb +17 -5
- data/lib/prmd/schema.rb +5 -1
- data/lib/prmd/templates/combine_head.json +3 -3
- data/lib/prmd/templates/init_default.json +5 -3
- data/lib/prmd/templates/init_resource.json.erb +18 -1
- data/lib/prmd/templates/schemata.md.erb +3 -0
- data/lib/prmd/templates/schemata/helper.erb +20 -0
- data/lib/prmd/templates/schemata/link.md.erb +11 -1
- data/lib/prmd/templates/schemata/link_curl_example.md.erb +8 -5
- data/lib/prmd/version.rb +1 -1
- data/test/commands/render_test.rb +60 -0
- data/test/core/reference_localizer_test.rb +65 -0
- data/test/helpers.rb +25 -3
- data/test/multi_loader/common.rb +35 -0
- data/test/multi_loader/json_test.rb +14 -0
- data/test/multi_loader/toml_test.rb +18 -0
- data/test/multi_loader/yajl_test.rb +18 -0
- data/test/multi_loader/yaml_test.rb +14 -0
- data/test/rake_tasks/combine_test.rb +38 -0
- data/test/rake_tasks/doc_test.rb +31 -0
- data/test/rake_tasks/verify_test.rb +23 -0
- data/test/schemata/data/test.json +6 -0
- data/test/schemata/data/test.toml +4 -0
- data/test/schemata/data/test.yaml +3 -0
- data/test/schemata/input/rake-meta.json +9 -0
- data/test/schemata/input/rake_combine/post.json +100 -0
- data/test/schemata/input/rake_combine/user.json +100 -0
- data/test/schemata/input/rake_doc.json +223 -0
- data/test/schemata/input/rake_verify.json +223 -0
- metadata +44 -3
- data/Gemfile.lock +0 -23
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, 7,
|
5
|
+
MAJOR, MINOR, TEENY, PATCH = 0, 7, 1, nil
|
6
6
|
# version string
|
7
7
|
# @return [String]
|
8
8
|
STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze
|
@@ -25,6 +25,13 @@ class InteragentRenderTest < Minitest::Test
|
|
25
25
|
assert_match /version.*v10\.9\.rc1/, markdown
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_render_for_example_as_an_array
|
29
|
+
# matches -d '[{...}]' taking into account line breaks and spacing
|
30
|
+
expression = /-d '\[[\s\n]+\{[\n\s]+\"name\": \"EXAMPLE\",[\n\s]+\"value\": \"example\"[\s\n]+\}[\n\s]+\]/
|
31
|
+
markdown = render
|
32
|
+
assert_match expression, markdown
|
33
|
+
end
|
34
|
+
|
28
35
|
private
|
29
36
|
|
30
37
|
def data
|
@@ -62,6 +69,56 @@ class InteragentRenderTest < Minitest::Test
|
|
62
69
|
],
|
63
70
|
'properties' => {
|
64
71
|
}
|
72
|
+
},
|
73
|
+
'config-var' => {
|
74
|
+
'description' => 'A configuration variable for an app.',
|
75
|
+
'title' => 'Config-var',
|
76
|
+
'type' => 'object',
|
77
|
+
'definitions' => {
|
78
|
+
'name' => {
|
79
|
+
'description' => 'The config-var\'s name.',
|
80
|
+
'type' => 'string',
|
81
|
+
'example' => 'EXAMPLE'
|
82
|
+
},
|
83
|
+
'value' => {
|
84
|
+
'description' => 'The config-var\'s value.',
|
85
|
+
'type' => 'string',
|
86
|
+
'example' => 'example'
|
87
|
+
},
|
88
|
+
},
|
89
|
+
'links' => [
|
90
|
+
{
|
91
|
+
'description' => 'Create many config-vars.',
|
92
|
+
'href' => '/config-vars',
|
93
|
+
'method' => 'PATCH',
|
94
|
+
'rel' => 'instances',
|
95
|
+
'title' => 'Create Config-var',
|
96
|
+
'schema' => {
|
97
|
+
'type' => [
|
98
|
+
'array'
|
99
|
+
],
|
100
|
+
'items' => {
|
101
|
+
'name' => {
|
102
|
+
'$ref' => '#/definitions/config-var/definitions/name'
|
103
|
+
},
|
104
|
+
'value' => {
|
105
|
+
'$ref' => '#/definitions/config-var/definitions/value'
|
106
|
+
},
|
107
|
+
'example' => [
|
108
|
+
{ 'name' => 'EXAMPLE', 'value' => 'example' }
|
109
|
+
]
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
],
|
114
|
+
'properties' => {
|
115
|
+
'name' => {
|
116
|
+
'$ref' => '#/definitions/config-var/definitions/name'
|
117
|
+
},
|
118
|
+
'value' => {
|
119
|
+
'$ref' => '#/definitions/config-var/definitions/value'
|
120
|
+
}
|
121
|
+
}
|
65
122
|
}
|
66
123
|
},
|
67
124
|
'links' => [
|
@@ -73,6 +130,9 @@ class InteragentRenderTest < Minitest::Test
|
|
73
130
|
'properties' => {
|
74
131
|
'app' => {
|
75
132
|
'$ref' => '#/definitions/app'
|
133
|
+
},
|
134
|
+
'config-var' => {
|
135
|
+
'$ref' => '#/definitions/config-var'
|
76
136
|
}
|
77
137
|
},
|
78
138
|
'type' => 'object'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path('../helpers', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
module Prmd
|
4
|
+
class ReferenceLocalizerTest < Minitest::Test
|
5
|
+
def base_object
|
6
|
+
{
|
7
|
+
"type" => ["object"],
|
8
|
+
"properties" => {
|
9
|
+
"name" => {
|
10
|
+
"type" => ["nil", "string"],
|
11
|
+
"example" => "john",
|
12
|
+
},
|
13
|
+
"age" => {
|
14
|
+
"type" => ["nil", "number"],
|
15
|
+
"example" => 37,
|
16
|
+
},
|
17
|
+
},
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_no_references
|
22
|
+
object = base_object
|
23
|
+
assert_equal object, ReferenceLocalizer.localize(object)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_simple_ref
|
27
|
+
object = base_object.merge(
|
28
|
+
"properties" => base_object["properties"].merge(
|
29
|
+
"name" => { "$ref" => "#/attributes/definitions/name" },
|
30
|
+
),
|
31
|
+
)
|
32
|
+
|
33
|
+
new_object = ReferenceLocalizer.localize(object)
|
34
|
+
assert_equal "#/definitions/attributes/definitions/name",
|
35
|
+
new_object["properties"]["name"]["$ref"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_simple_href
|
39
|
+
object = base_object.merge("href" => "%23%2Fschemata%2Fhello%2Fworld")
|
40
|
+
new_object = ReferenceLocalizer.localize(object)
|
41
|
+
assert_equal "%23%2Fdefinitions%2Fhello%2Fworld", new_object["href"]
|
42
|
+
|
43
|
+
object = base_object.merge("href" => "%23%2Fhello%2Fworld")
|
44
|
+
new_object = ReferenceLocalizer.localize(object)
|
45
|
+
assert_equal "%2Fhello%2Fworld", new_object["href"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_aliases
|
49
|
+
object = base_object.merge(
|
50
|
+
"properties" => base_object["properties"].merge(
|
51
|
+
"name" => { "$ref" => "#/attributes/definitions/name" },
|
52
|
+
),
|
53
|
+
)
|
54
|
+
object["properties"]["translated_name"] = object["properties"]["name"]
|
55
|
+
|
56
|
+
new_object = ReferenceLocalizer.localize(object)
|
57
|
+
|
58
|
+
assert_equal "#/definitions/attributes/definitions/name",
|
59
|
+
new_object["properties"]["name"]["$ref"]
|
60
|
+
|
61
|
+
assert_equal "#/definitions/attributes/definitions/name",
|
62
|
+
new_object["properties"]["translated_name"]["$ref"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/test/helpers.rb
CHANGED
@@ -55,10 +55,32 @@ module CliBaseTestHelpers
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
module PrmdTestHelpers
|
59
|
+
module Paths
|
60
|
+
def self.schemas(*args)
|
61
|
+
File.join(File.expand_path('schemata', File.dirname(__FILE__)), *args)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.input_schemas(*args)
|
65
|
+
schemas('input', *args)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.output_schemas(*args)
|
69
|
+
schemas('output', *args)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def schemas_path(*args)
|
75
|
+
PrmdTestHelpers::Paths.schemas(*args)
|
76
|
+
end
|
77
|
+
|
58
78
|
def input_schemas_path(*args)
|
59
|
-
|
60
|
-
|
61
|
-
|
79
|
+
PrmdTestHelpers::Paths.input_schemas(*args)
|
80
|
+
end
|
81
|
+
|
82
|
+
def output_schemas_path(*args)
|
83
|
+
PrmdTestHelpers::Paths.output_schemas(*args)
|
62
84
|
end
|
63
85
|
|
64
86
|
def user_input_schema
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path('../helpers', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
module PrmdLoaderTests
|
4
|
+
# @abstrac
|
5
|
+
def testing_filename
|
6
|
+
#
|
7
|
+
end
|
8
|
+
|
9
|
+
# @abstract
|
10
|
+
def loader_module
|
11
|
+
#
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_test_data(data)
|
15
|
+
assert_kind_of Hash, data
|
16
|
+
assert_equal 'yes', data['test']
|
17
|
+
assert_kind_of Hash, data['object']
|
18
|
+
assert_equal 'Object', data['object']['is_a']
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_load_data
|
22
|
+
data = File.read(testing_filename)
|
23
|
+
assert_test_data loader_module.load_data(data)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_load_stream
|
27
|
+
File.open(testing_filename, 'r') do |f|
|
28
|
+
assert_test_data loader_module.load_stream(f)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_load_file
|
33
|
+
assert_test_data loader_module.load_file(testing_filename)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('common', File.dirname(__FILE__))
|
2
|
+
require 'prmd/multi_loader/json'
|
3
|
+
|
4
|
+
class PrmdMultiLoaderJsonTest < Minitest::Test
|
5
|
+
include PrmdLoaderTests
|
6
|
+
|
7
|
+
def loader_module
|
8
|
+
Prmd::MultiLoader::Json
|
9
|
+
end
|
10
|
+
|
11
|
+
def testing_filename
|
12
|
+
schemas_path('data/test.json')
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('common', File.dirname(__FILE__))
|
2
|
+
begin
|
3
|
+
require 'prmd/multi_loader/toml'
|
4
|
+
rescue LoadError
|
5
|
+
#
|
6
|
+
end
|
7
|
+
|
8
|
+
class PrmdMultiLoaderTomlTest < Minitest::Test
|
9
|
+
include PrmdLoaderTests
|
10
|
+
|
11
|
+
def loader_module
|
12
|
+
Prmd::MultiLoader::Toml
|
13
|
+
end
|
14
|
+
|
15
|
+
def testing_filename
|
16
|
+
schemas_path('data/test.toml')
|
17
|
+
end
|
18
|
+
end if defined?(TOML)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('common', File.dirname(__FILE__))
|
2
|
+
begin
|
3
|
+
require 'prmd/multi_loader/yajl'
|
4
|
+
rescue LoadError
|
5
|
+
#
|
6
|
+
end
|
7
|
+
|
8
|
+
class PrmdMultiLoaderYajlTest < Minitest::Test
|
9
|
+
include PrmdLoaderTests
|
10
|
+
|
11
|
+
def loader_module
|
12
|
+
Prmd::MultiLoader::Yajl
|
13
|
+
end
|
14
|
+
|
15
|
+
def testing_filename
|
16
|
+
schemas_path('data/test.json')
|
17
|
+
end
|
18
|
+
end if defined?(Yajl)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('common', File.dirname(__FILE__))
|
2
|
+
require 'prmd/multi_loader/yaml'
|
3
|
+
|
4
|
+
class PrmdMultiLoaderYamlTest < Minitest::Test
|
5
|
+
include PrmdLoaderTests
|
6
|
+
|
7
|
+
def loader_module
|
8
|
+
Prmd::MultiLoader::Yaml
|
9
|
+
end
|
10
|
+
|
11
|
+
def testing_filename
|
12
|
+
schemas_path('data/test.yaml')
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path('../helpers', File.dirname(__FILE__))
|
2
|
+
require 'prmd/rake_tasks/combine'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
# due to the nature of these Rake Tests, this should not be executed in a
|
6
|
+
# read-only filesystem or directory.
|
7
|
+
class PrmdRakeTaskCombineTest < Minitest::Test
|
8
|
+
def test_define_wo_options
|
9
|
+
paths = [input_schemas_path('rake_combine')]
|
10
|
+
#output_file = output_schemas_path('rake_combine_with_options.json')
|
11
|
+
output_file = nil
|
12
|
+
File.delete(output_file) if File.exist?(output_file) if output_file
|
13
|
+
Prmd::RakeTasks::Combine.new do |t|
|
14
|
+
t.name = :combine_wo_options
|
15
|
+
t.options[:meta] = input_schemas_path('rake-meta.json')
|
16
|
+
t.paths.concat(paths)
|
17
|
+
t.output_file = output_file
|
18
|
+
end
|
19
|
+
Rake::Task['combine_wo_options'].invoke
|
20
|
+
assert File.exist?(output_file) if output_file
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_define_with_options
|
24
|
+
paths = [input_schemas_path('rake_combine')]
|
25
|
+
#output_file = output_schemas_path('rake_combine_with_options.json')
|
26
|
+
output_file = nil
|
27
|
+
options = {
|
28
|
+
meta: input_schemas_path('rake-meta.json')
|
29
|
+
}
|
30
|
+
File.delete(output_file) if File.exist?(output_file) if output_file
|
31
|
+
Prmd::RakeTasks::Combine.new(name: :combine_with_options,
|
32
|
+
paths: paths,
|
33
|
+
output_file: output_file,
|
34
|
+
options: options)
|
35
|
+
Rake::Task['combine_with_options'].invoke
|
36
|
+
assert File.exist?(output_file) if output_file
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../helpers', File.dirname(__FILE__))
|
2
|
+
require 'prmd/rake_tasks/doc'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
# due to the nature of these Rake Tests, this should not be executed in a
|
6
|
+
# read-only filesystem or directory.
|
7
|
+
class PrmdRakeTaskDocTest < Minitest::Test
|
8
|
+
def test_define_wo_options
|
9
|
+
input_file = input_schemas_path('rake_doc.json')
|
10
|
+
#output_file = output_schemas_path('rake_doc_with_options.md')
|
11
|
+
output_file = nil
|
12
|
+
File.delete(output_file) if File.exist?(output_file) if output_file
|
13
|
+
Prmd::RakeTasks::Doc.new do |t|
|
14
|
+
t.name = :doc_wo_options
|
15
|
+
t.files = { input_file => output_file }
|
16
|
+
end
|
17
|
+
Rake::Task['doc_wo_options'].invoke
|
18
|
+
assert File.exist?(output_file) if output_file
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_define_with_options
|
22
|
+
input_file = input_schemas_path('rake_doc.json')
|
23
|
+
#output_file = output_schemas_path('rake_doc_with_options.md')
|
24
|
+
output_file = nil
|
25
|
+
File.delete(output_file) if File.exist?(output_file) if output_file
|
26
|
+
Prmd::RakeTasks::Doc.new(name: :doc_with_options,
|
27
|
+
files: { input_file => output_file })
|
28
|
+
Rake::Task['doc_with_options'].invoke
|
29
|
+
assert File.exist?(output_file) if output_file
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../helpers', File.dirname(__FILE__))
|
2
|
+
require 'prmd/rake_tasks/verify'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
# due to the nature of these Rake Tests, this should not be executed in a
|
6
|
+
# read-only filesystem or directory.
|
7
|
+
class PrmdRakeTaskVerifyTest < Minitest::Test
|
8
|
+
def test_define_wo_options
|
9
|
+
input_file = input_schemas_path('rake_verify.json')
|
10
|
+
Prmd::RakeTasks::Verify.new do |t|
|
11
|
+
t.name = :verify_wo_options
|
12
|
+
t.files = [input_file]
|
13
|
+
end
|
14
|
+
Rake::Task['verify_wo_options'].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_define_with_options
|
18
|
+
input_file = input_schemas_path('rake_verify.json')
|
19
|
+
Prmd::RakeTasks::Verify.new(name: :verify_with_options,
|
20
|
+
files: [input_file])
|
21
|
+
Rake::Task['verify_with_options'].invoke
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://json-schema.org/draft-04/hyper-schema",
|
3
|
+
"title": "Post",
|
4
|
+
"definitions": {
|
5
|
+
"id": {
|
6
|
+
"description": "unique identifier of post",
|
7
|
+
"example": "01234567-89ab-cdef-0123-456789abcdef",
|
8
|
+
"format": "uuid",
|
9
|
+
"type": [
|
10
|
+
"string"
|
11
|
+
]
|
12
|
+
},
|
13
|
+
"identity": {
|
14
|
+
"$ref": "/schemata/post#/definitions/id"
|
15
|
+
},
|
16
|
+
"created_at": {
|
17
|
+
"description": "when post was created",
|
18
|
+
"example": "2012-01-01T12:00:00Z",
|
19
|
+
"format": "date-time",
|
20
|
+
"type": [
|
21
|
+
"string"
|
22
|
+
]
|
23
|
+
},
|
24
|
+
"updated_at": {
|
25
|
+
"description": "when post was updated",
|
26
|
+
"example": "2012-01-01T12:00:00Z",
|
27
|
+
"format": "date-time",
|
28
|
+
"type": [
|
29
|
+
"string"
|
30
|
+
]
|
31
|
+
}
|
32
|
+
},
|
33
|
+
"description": "FIXME",
|
34
|
+
"links": [
|
35
|
+
{
|
36
|
+
"description": "Create a new post.",
|
37
|
+
"href": "/posts",
|
38
|
+
"method": "POST",
|
39
|
+
"rel": "create",
|
40
|
+
"schema": {
|
41
|
+
"properties": {
|
42
|
+
},
|
43
|
+
"type": [
|
44
|
+
"object"
|
45
|
+
]
|
46
|
+
},
|
47
|
+
"title": "Create"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"description": "Delete an existing post.",
|
51
|
+
"href": "/posts/{(%2Fschemata%2Fpost%23%2Fdefinitions%2Fidentity)}",
|
52
|
+
"method": "DELETE",
|
53
|
+
"rel": "destroy",
|
54
|
+
"title": "Delete"
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"description": "Info for existing post.",
|
58
|
+
"href": "/posts/{(%2Fschemata%2Fpost%23%2Fdefinitions%2Fidentity)}",
|
59
|
+
"method": "GET",
|
60
|
+
"rel": "self",
|
61
|
+
"title": "Info"
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"description": "List existing posts.",
|
65
|
+
"href": "/posts",
|
66
|
+
"method": "GET",
|
67
|
+
"rel": "instances",
|
68
|
+
"title": "List"
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"description": "Update an existing post.",
|
72
|
+
"href": "/posts/{(%2Fschemata%2Fpost%23%2Fdefinitions%2Fidentity)}",
|
73
|
+
"method": "PATCH",
|
74
|
+
"rel": "update",
|
75
|
+
"schema": {
|
76
|
+
"properties": {
|
77
|
+
},
|
78
|
+
"type": [
|
79
|
+
"object"
|
80
|
+
]
|
81
|
+
},
|
82
|
+
"title": "Update"
|
83
|
+
}
|
84
|
+
],
|
85
|
+
"properties": {
|
86
|
+
"created_at": {
|
87
|
+
"$ref": "/schemata/post#/definitions/created_at"
|
88
|
+
},
|
89
|
+
"id": {
|
90
|
+
"$ref": "/schemata/post#/definitions/id"
|
91
|
+
},
|
92
|
+
"updated_at": {
|
93
|
+
"$ref": "/schemata/post#/definitions/updated_at"
|
94
|
+
}
|
95
|
+
},
|
96
|
+
"type": [
|
97
|
+
"object"
|
98
|
+
],
|
99
|
+
"id": "schemata/post"
|
100
|
+
}
|