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
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Prmd
|
5
|
+
# :nodoc:
|
6
|
+
class UrlGenerator
|
7
|
+
# :nodoc:
|
8
|
+
module Generators
|
9
|
+
# Default URL Generator
|
10
|
+
#
|
11
|
+
# @api private
|
12
|
+
class Default
|
13
|
+
# @param [Hash<Symbol, Object>] params
|
14
|
+
def self.generate(params)
|
15
|
+
data = {}
|
16
|
+
data.merge!(params[:schema].schema_example(params[:link]['schema']))
|
17
|
+
generate_params(data)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param [String] key
|
21
|
+
# @param [String] prefix
|
22
|
+
# @return [String]
|
23
|
+
def self.param_name(key, prefix, array = false)
|
24
|
+
result = if prefix
|
25
|
+
"#{prefix}[#{key}]"
|
26
|
+
else
|
27
|
+
key
|
28
|
+
end
|
29
|
+
|
30
|
+
result += '[]' if array
|
31
|
+
result
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [Hash] obj
|
35
|
+
# @param [String] prefix
|
36
|
+
# @return [String]
|
37
|
+
def self.generate_params(obj, prefix = nil)
|
38
|
+
result = []
|
39
|
+
obj.each do |key,value|
|
40
|
+
if value.is_a?(Hash)
|
41
|
+
newprefix = if prefix
|
42
|
+
"#{prefix}[#{key}]"
|
43
|
+
else
|
44
|
+
key
|
45
|
+
end
|
46
|
+
result << generate_params(value, newprefix)
|
47
|
+
elsif value.is_a?(Array)
|
48
|
+
value.each do |val|
|
49
|
+
result << [param_name(key, prefix, true), CGI.escape(val.to_s)].join('=')
|
50
|
+
end
|
51
|
+
else
|
52
|
+
next unless value # ignores parameters with empty examples
|
53
|
+
result << [param_name(key, prefix), CGI.escape(value.to_s)].join('=')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
result.flatten
|
57
|
+
end
|
58
|
+
|
59
|
+
class << self
|
60
|
+
private :param_name
|
61
|
+
private :generate_params
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Prmd
|
5
|
+
# :nodoc:
|
6
|
+
class UrlGenerator
|
7
|
+
# :nodoc:
|
8
|
+
module Generators
|
9
|
+
# JSON URL Generator
|
10
|
+
#
|
11
|
+
# @api private
|
12
|
+
class JSON
|
13
|
+
# @param [Hash<Symbol, Object>] params
|
14
|
+
def self.generate(params)
|
15
|
+
data = {}
|
16
|
+
data.merge!(params[:schema].schema_example(params[:link]['schema']))
|
17
|
+
|
18
|
+
result = []
|
19
|
+
data.sort_by {|k,_| k.to_s }.each do |key, values|
|
20
|
+
[values].flatten.each do |value|
|
21
|
+
result << [key.to_s, CGI.escape(value.to_s)].join('=')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
result
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/prmd/version.rb
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# :nodoc:
|
1
2
|
module Prmd
|
2
|
-
|
3
|
+
# Well, duh, its a Version module, what did you expect?
|
4
|
+
module Version
|
5
|
+
MAJOR, MINOR, TEENY, PATCH = 0, 7, 0, nil
|
6
|
+
# version string
|
7
|
+
# @return [String]
|
8
|
+
STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze
|
9
|
+
end
|
10
|
+
# @return [String]
|
11
|
+
VERSION = Version::STRING
|
3
12
|
end
|
data/prmd.gemspec
CHANGED
@@ -4,24 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'prmd/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'prmd'
|
8
8
|
spec.version = Prmd::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['geemus']
|
10
|
+
spec.email = ['geemus@gmail.com']
|
11
|
+
spec.description = 'scaffold, verify and generate docs from JSON Schema'
|
12
|
+
spec.summary = 'JSON Schema tooling'
|
13
|
+
spec.homepage = 'https://github.com/heroku/prmd'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(
|
18
|
-
spec.test_files = spec.files.grep(
|
19
|
-
spec.require_paths = [
|
17
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'erubis', '~> 2.7'
|
22
|
+
spec.add_dependency 'json_schema', '~> 0.3', '>= 0.3.1'
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.3'
|
26
|
+
spec.add_development_dependency 'minitest', '~> 5.4'
|
27
27
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
|
2
|
+
require 'prmd/cli/combine'
|
3
|
+
|
4
|
+
class PrmdCliCombineTest < Minitest::Test
|
5
|
+
include CliBaseTestHelpers
|
6
|
+
|
7
|
+
def command_module
|
8
|
+
Prmd::CLI::Combine
|
9
|
+
end
|
10
|
+
|
11
|
+
def argv_for_test_run
|
12
|
+
['-m', 'schema/meta.json',
|
13
|
+
'schema/schemata',
|
14
|
+
'-o', 'schema/api.json']
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate_parse_options(options)
|
18
|
+
assert_equal 'schema/meta.json', options[:meta]
|
19
|
+
assert_equal 'schema/api.json', options[:output_file]
|
20
|
+
assert_equal ['schema/schemata'], options[:argv]
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
|
2
|
+
require 'prmd/cli/doc'
|
3
|
+
|
4
|
+
class PrmdCliDocTest < Minitest::Test
|
5
|
+
include CliBaseTestHelpers
|
6
|
+
|
7
|
+
def command_module
|
8
|
+
Prmd::CLI::Doc
|
9
|
+
end
|
10
|
+
|
11
|
+
def argv_for_test_run
|
12
|
+
['-s', input_schemas_path('doc-settings.json'),
|
13
|
+
'-p', 'overview.txt',
|
14
|
+
'schema/api.json',
|
15
|
+
'-o', 'schema/verified-api.json']
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate_parse_options(options)
|
19
|
+
assert_equal 'application/bread', options[:content_type]
|
20
|
+
assert_equal ['overview.txt'], options[:prepend]
|
21
|
+
assert_equal 'schema/verified-api.json', options[:output_file]
|
22
|
+
assert_equal ['schema/api.json'], options[:argv]
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
|
2
|
+
require 'prmd/cli/generate'
|
3
|
+
|
4
|
+
class PrmdCliGenerateTest < Minitest::Test
|
5
|
+
include CliBaseTestHelpers
|
6
|
+
|
7
|
+
def command_module
|
8
|
+
Prmd::CLI::Generate
|
9
|
+
end
|
10
|
+
|
11
|
+
def argv_for_test_run
|
12
|
+
['-y',
|
13
|
+
'bread',
|
14
|
+
'-o', 'schema/bread.yml']
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate_parse_options(options)
|
18
|
+
assert_equal true, options[:yaml]
|
19
|
+
assert_equal ['bread'], options[:argv]
|
20
|
+
assert_equal 'schema/bread.yml', options[:output_file]
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
|
2
|
+
require 'prmd/cli/render'
|
3
|
+
|
4
|
+
class PrmdCliRenderTest < Minitest::Test
|
5
|
+
include CliBaseTestHelpers
|
6
|
+
|
7
|
+
def command_module
|
8
|
+
Prmd::CLI::Render
|
9
|
+
end
|
10
|
+
|
11
|
+
def argv_for_test_run
|
12
|
+
['-p', 'overview.txt,somethin.txt',
|
13
|
+
'-t', 'templates',
|
14
|
+
'-o', 'schema/bread.md',
|
15
|
+
'schema/bread.json']
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate_parse_options(options)
|
19
|
+
assert_equal ['overview.txt', 'somethin.txt'], options[:prepend]
|
20
|
+
assert_equal 'templates', options[:template]
|
21
|
+
assert_equal 'schema/bread.md', options[:output_file]
|
22
|
+
assert_equal ['schema/bread.json'], options[:argv]
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
|
2
|
+
require 'prmd/cli/verify'
|
3
|
+
|
4
|
+
class PrmdCliVerifyTest < Minitest::Test
|
5
|
+
include CliBaseTestHelpers
|
6
|
+
|
7
|
+
def command_module
|
8
|
+
Prmd::CLI::Verify
|
9
|
+
end
|
10
|
+
|
11
|
+
def argv_for_test_run
|
12
|
+
['-o', 'schema/buttered-bread.json',
|
13
|
+
'schema/bread.json']
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate_parse_options(options)
|
17
|
+
assert_equal 'schema/buttered-bread.json', options[:output_file]
|
18
|
+
assert_equal ['schema/bread.json'], options[:argv]
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
|
2
|
+
|
3
|
+
require 'json_pointer'
|
4
|
+
|
5
|
+
class InteragentRenderTest < Minitest::Test
|
6
|
+
def test_render_for_valid_schema
|
7
|
+
markdown = render
|
8
|
+
|
9
|
+
assert_match /An app in our PaaS ecosystem./, markdown
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_render_for_schema_with_property_defined_with_anyOf
|
13
|
+
pointer('#/definitions/app').merge!({
|
14
|
+
'properties' => {
|
15
|
+
'version' => {
|
16
|
+
'anyOf' => [
|
17
|
+
{ 'type' => 'string', 'example' => 'v10.9.rc1', 'minLength' => 1 },
|
18
|
+
{ 'type' => 'number', 'minimum' => 0 }
|
19
|
+
]
|
20
|
+
}
|
21
|
+
}
|
22
|
+
})
|
23
|
+
|
24
|
+
markdown = render
|
25
|
+
assert_match /version.*v10\.9\.rc1/, markdown
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def data
|
31
|
+
@data ||= {
|
32
|
+
'$schema' => 'http://interagent.github.io/interagent-hyper-schema',
|
33
|
+
'description' => 'My simple example API.',
|
34
|
+
'id' => 'http://example.com/schema',
|
35
|
+
'title' => 'Example API',
|
36
|
+
'definitions' => {
|
37
|
+
'app' => {
|
38
|
+
'description' => 'An app in our PaaS ecosystem.',
|
39
|
+
'title' => 'App',
|
40
|
+
'type' => 'object',
|
41
|
+
'definitions' => {
|
42
|
+
'identity' => {
|
43
|
+
'anyOf' => [
|
44
|
+
{
|
45
|
+
'$ref' => '#/definitions/app/definitions/name'
|
46
|
+
}
|
47
|
+
]
|
48
|
+
},
|
49
|
+
'name' => {
|
50
|
+
'description' => 'The app\'s name.',
|
51
|
+
'type' => 'string'
|
52
|
+
}
|
53
|
+
},
|
54
|
+
'links' => [
|
55
|
+
{
|
56
|
+
'description' => 'Create a new app.',
|
57
|
+
'href' => '/apps',
|
58
|
+
'method' => 'POST',
|
59
|
+
'rel' => 'create',
|
60
|
+
'title' => 'Create App'
|
61
|
+
}
|
62
|
+
],
|
63
|
+
'properties' => {
|
64
|
+
}
|
65
|
+
}
|
66
|
+
},
|
67
|
+
'links' => [
|
68
|
+
{
|
69
|
+
'href' => 'https://example.com',
|
70
|
+
'rel' => 'self'
|
71
|
+
}
|
72
|
+
],
|
73
|
+
'properties' => {
|
74
|
+
'app' => {
|
75
|
+
'$ref' => '#/definitions/app'
|
76
|
+
}
|
77
|
+
},
|
78
|
+
'type' => 'object'
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def pointer(path)
|
83
|
+
JsonPointer.evaluate(data, path)
|
84
|
+
end
|
85
|
+
|
86
|
+
def render
|
87
|
+
schema = Prmd::Schema.new(data)
|
88
|
+
|
89
|
+
template = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'prmd', 'templates'))
|
90
|
+
|
91
|
+
Prmd.render(schema, template: template)
|
92
|
+
end
|
93
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'json_pointer'
|
4
4
|
|
5
5
|
class InteragentHyperSchemaVerifyTest < Minitest::Test
|
6
6
|
def test_verifies
|
@@ -12,20 +12,20 @@ class InteragentHyperSchemaVerifyTest < Minitest::Test
|
|
12
12
|
#
|
13
13
|
|
14
14
|
def test_api_required
|
15
|
-
data.delete(
|
15
|
+
data.delete('title')
|
16
16
|
errors = verify
|
17
17
|
assert_equal 1, errors.count
|
18
|
-
assert_match
|
19
|
-
assert_match
|
18
|
+
assert_match /^#: /, errors[0]
|
19
|
+
assert_match /"title" wasn't supplied\./, errors[0]
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_api_property_format
|
23
|
-
pointer(
|
24
|
-
|
23
|
+
pointer('#/properties').merge!({
|
24
|
+
'app' => {}
|
25
25
|
})
|
26
26
|
errors = verify
|
27
27
|
assert_match %r{^#/properties/app: }, errors[0]
|
28
|
-
assert_match
|
28
|
+
assert_match /"\$ref" wasn't supplied\./, errors[0]
|
29
29
|
end
|
30
30
|
|
31
31
|
#
|
@@ -33,50 +33,50 @@ class InteragentHyperSchemaVerifyTest < Minitest::Test
|
|
33
33
|
#
|
34
34
|
|
35
35
|
def test_resource_required
|
36
|
-
pointer(
|
36
|
+
pointer('#/definitions/app').delete('title')
|
37
37
|
errors = verify
|
38
38
|
assert_equal 1, errors.count
|
39
39
|
assert_match %r{^#/definitions/app: }, errors[0]
|
40
|
-
assert_match
|
40
|
+
assert_match /"title" wasn't supplied\./, errors[0]
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_resource_identity_format
|
44
|
-
pointer(
|
45
|
-
|
44
|
+
pointer('#/definitions/app/definitions/identity').merge!({
|
45
|
+
'type' => 'string'
|
46
46
|
})
|
47
47
|
errors = verify
|
48
48
|
assert_equal 1, errors.count
|
49
49
|
assert_match %r{^#/definitions/app/definitions/identity: }, errors[0]
|
50
|
-
assert_match
|
50
|
+
assert_match /No subschema in "anyOf" matched\./, errors[0]
|
51
51
|
end
|
52
52
|
|
53
53
|
# an empty schema can be specified to bypass the identity check
|
54
54
|
def test_resource_identity_format_empty
|
55
|
-
pointer(
|
56
|
-
|
55
|
+
pointer('#/definitions/app/definitions').merge!({
|
56
|
+
'identity' => {}
|
57
57
|
})
|
58
58
|
assert_equal [], verify
|
59
59
|
end
|
60
60
|
|
61
61
|
# "my-property" does match fit our regex of lowercase letters and underscores only
|
62
62
|
def test_resource_property_format
|
63
|
-
pointer(
|
64
|
-
|
63
|
+
pointer('#/definitions/app/properties').merge!({
|
64
|
+
'my-property' => {}
|
65
65
|
})
|
66
66
|
errors = verify
|
67
67
|
assert_equal 1, errors.count
|
68
68
|
assert_match %r{^#/definitions/app/properties: }, errors[0]
|
69
|
-
assert_match
|
69
|
+
assert_match /"my-property" is not a permitted key\./, errors[0]
|
70
70
|
end
|
71
71
|
|
72
72
|
def test_resource_strict_properties
|
73
|
-
pointer(
|
74
|
-
|
73
|
+
pointer('#/definitions/app').merge!({
|
74
|
+
'strictProperties' => false
|
75
75
|
})
|
76
76
|
errors = verify
|
77
77
|
assert_equal 1, errors.count
|
78
78
|
assert_match %r{^#/definitions/app/strictProperties: }, errors[0]
|
79
|
-
assert_match
|
79
|
+
assert_match /false is not a member of \[true\]/, errors[0]
|
80
80
|
end
|
81
81
|
|
82
82
|
#
|
@@ -84,21 +84,21 @@ class InteragentHyperSchemaVerifyTest < Minitest::Test
|
|
84
84
|
#
|
85
85
|
|
86
86
|
def test_resource_definition_no_links
|
87
|
-
pointer(
|
88
|
-
|
87
|
+
pointer('#/definitions/app/definitions/name').merge!({
|
88
|
+
'links' => []
|
89
89
|
})
|
90
90
|
errors = verify
|
91
91
|
assert_equal 1, errors.count
|
92
92
|
assert_match %r{^#/definitions/app/definitions/name: }, errors[0]
|
93
|
-
assert_match
|
93
|
+
assert_match /Matched "not" subschema/, errors[0]
|
94
94
|
end
|
95
95
|
|
96
96
|
def test_resource_definition_required
|
97
|
-
pointer(
|
97
|
+
pointer('#/definitions/app/definitions/name').delete('description')
|
98
98
|
errors = verify
|
99
99
|
assert_equal 1, errors.count
|
100
100
|
assert_match %r{^#/definitions/app/definitions/name: }, errors[0]
|
101
|
-
assert_match
|
101
|
+
assert_match /"description" wasn't supplied\./, errors[0]
|
102
102
|
end
|
103
103
|
|
104
104
|
#
|
@@ -106,74 +106,74 @@ class InteragentHyperSchemaVerifyTest < Minitest::Test
|
|
106
106
|
#
|
107
107
|
|
108
108
|
def test_resource_link_href_format
|
109
|
-
pointer(
|
110
|
-
|
109
|
+
pointer('#/definitions/app/links/0').merge!({
|
110
|
+
'href' => '/my_apps'
|
111
111
|
})
|
112
112
|
errors = verify
|
113
113
|
assert_equal 1, errors.count
|
114
114
|
assert_match %r{^#/definitions/app/links/0/href: }, errors[0]
|
115
|
-
assert_match
|
115
|
+
assert_match /\/my_apps does not match /, errors[0]
|
116
116
|
end
|
117
117
|
|
118
118
|
def test_resource_link_required
|
119
|
-
pointer(
|
119
|
+
pointer('#/definitions/app/links/0').delete('method')
|
120
120
|
errors = verify
|
121
121
|
assert_equal 1, errors.count
|
122
122
|
assert_match %r{^#/definitions/app/links/0: }, errors[0]
|
123
|
-
assert_match
|
123
|
+
assert_match /"method" wasn't supplied\./, errors[0]
|
124
124
|
end
|
125
125
|
|
126
126
|
private
|
127
127
|
|
128
128
|
def data
|
129
129
|
@data ||= {
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
130
|
+
'$schema' => 'http://interagent.github.io/interagent-hyper-schema',
|
131
|
+
'description' => 'My simple example API.',
|
132
|
+
'id' => 'http://example.com/schema',
|
133
|
+
'title' => 'Example API',
|
134
|
+
'definitions' => {
|
135
|
+
'app' => {
|
136
|
+
'description' => 'An app in our PaaS ecosystem.',
|
137
|
+
'title' => 'App',
|
138
|
+
'type' => 'object',
|
139
|
+
'definitions' => {
|
140
|
+
'identity' => {
|
141
|
+
'anyOf' => [
|
142
142
|
{
|
143
|
-
|
143
|
+
'$ref' => '#/definitions/app/definitions/name'
|
144
144
|
}
|
145
145
|
]
|
146
146
|
},
|
147
|
-
|
148
|
-
|
149
|
-
|
147
|
+
'name' => {
|
148
|
+
'description' => 'The app\'s name.',
|
149
|
+
'type' => 'string'
|
150
150
|
}
|
151
151
|
},
|
152
|
-
|
152
|
+
'links' => [
|
153
153
|
{
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
154
|
+
'description' => 'Create a new app.',
|
155
|
+
'href' => '/apps',
|
156
|
+
'method' => 'POST',
|
157
|
+
'rel' => 'create',
|
158
|
+
'title' => 'Create App'
|
159
159
|
}
|
160
160
|
],
|
161
|
-
|
161
|
+
'properties' => {
|
162
162
|
}
|
163
163
|
}
|
164
164
|
},
|
165
|
-
|
165
|
+
'links' => [
|
166
166
|
{
|
167
|
-
|
168
|
-
|
167
|
+
'href' => 'https://example.com',
|
168
|
+
'rel' => 'self'
|
169
169
|
}
|
170
170
|
],
|
171
|
-
|
172
|
-
|
173
|
-
|
171
|
+
'properties' => {
|
172
|
+
'app' => {
|
173
|
+
'$ref' => '#/definitions/app'
|
174
174
|
}
|
175
175
|
},
|
176
|
-
|
176
|
+
'type' => 'object'
|
177
177
|
}
|
178
178
|
end
|
179
179
|
|