prmd 0.11.0 → 0.12.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 +4 -4
- data/.travis.yml +7 -0
- data/CONTRIBUTORS.md +15 -1
- data/LICENSE.md +1 -1
- data/docs/schemata.md +1 -1
- data/lib/prmd/cli/base.rb +4 -4
- data/lib/prmd/cli/combine.rb +5 -1
- data/lib/prmd/cli/generate.rb +6 -1
- data/lib/prmd/commands/combine.rb +34 -3
- data/lib/prmd/core/combiner.rb +2 -1
- data/lib/prmd/rake_tasks/combine.rb +1 -1
- data/lib/prmd/rake_tasks/doc.rb +1 -1
- data/lib/prmd/rake_tasks/verify.rb +1 -1
- data/lib/prmd/schema.rb +11 -6
- data/lib/prmd/templates/schema.erb +2 -1
- data/lib/prmd/templates/schemata/helper.erb +4 -3
- data/lib/prmd/templates/schemata/link_curl_example.md.erb +6 -6
- data/lib/prmd/templates/schemata.md.erb +5 -1
- data/lib/prmd/utils.rb +19 -0
- data/lib/prmd/version.rb +1 -1
- data/lib/prmd.rb +1 -0
- data/schemas/interagent-hyper-schema.json +0 -4
- data/test/cli/combine_test.rb +1 -1
- data/test/cli/doc_test.rb +1 -1
- data/test/cli/generate_test.rb +1 -1
- data/test/cli/render_test.rb +1 -1
- data/test/cli/verify_test.rb +1 -1
- data/test/commands/combine_test.rb +73 -0
- data/test/commands/init_test.rb +1 -1
- data/test/commands/render_test.rb +14 -14
- data/test/commands/verify_test.rb +1 -1
- data/test/core/reference_localizer_test.rb +1 -1
- data/test/link_test.rb +3 -2
- data/test/multi_loader/common.rb +1 -1
- data/test/multi_loader/json_test.rb +1 -1
- data/test/multi_loader/toml_test.rb +1 -1
- data/test/multi_loader/yajl_test.rb +1 -1
- data/test/multi_loader/yaml_test.rb +1 -1
- data/test/rake_tasks/combine_test.rb +1 -1
- data/test/rake_tasks/doc_test.rb +1 -1
- data/test/rake_tasks/verify_test.rb +1 -1
- data/test/schema_test.rb +1 -1
- data/test/utils_test.rb +16 -0
- metadata +8 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d1010706b78a9b6d770bb52a5a3bc0dd40cbb516
|
|
4
|
+
data.tar.gz: 0c6021aedeb0bbeaee1af485ffdddcb7c4a83ec5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 812720e3b67bcf3f524a545364129751e4b87afb10dc67c74aaf586f6d18f5de644eaa20852bbe68017439004a3a6571eb4230dee4222221344c243a1ad26c99
|
|
7
|
+
data.tar.gz: 442813d217485037daf7aa7a9854c99ec76ddd6371f4d0945c69a9d0000812a232a6b8e8acc6d793f8a4a94952f41335c83a39fd4b592cda212e9526fd5cdc81
|
data/.travis.yml
CHANGED
data/CONTRIBUTORS.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
* Adel Qalieh <aqalieh95@gmail.com>
|
|
2
2
|
* Alex Fedorov <alexey.fedorov@wimdu.com>
|
|
3
3
|
* Alex Sergeyev <alex.sergeyev@gmail.com>
|
|
4
|
+
* Alex Sulim <hello@sul.im>
|
|
4
5
|
* Alexey Fedorov <waterlink000@gmail.com>
|
|
5
6
|
* Arnold <arnoldcano@yahoo.com>
|
|
7
|
+
* Blake Visin <blake@oybro.com>
|
|
6
8
|
* Brandur <brandur@heroku.com>
|
|
7
9
|
* Brandur <brandur@mutelight.org>
|
|
10
|
+
* Brian McManus <bdmac97@gmail.com>
|
|
8
11
|
* Camilo Aguilar <camilo.aguilar@gmail.com>
|
|
9
12
|
* Cesar Andreu <cesarandreu@gmail.com>
|
|
10
13
|
* Chris Continanza <christopher.continanza@gmail.com>
|
|
@@ -14,25 +17,36 @@
|
|
|
14
17
|
* Dominik Honnef <dominik@honnef.co>
|
|
15
18
|
* Eric J. Holmes <eric@ejholmes.net>
|
|
16
19
|
* Ernesto Jiménez <me@ernesto-jimenez.com>
|
|
20
|
+
* Glenn Goodrich <glenn.goodrich@gmail.com>
|
|
17
21
|
* Guillaume Coderre <guillaume.coderre@bookwitty.com>
|
|
22
|
+
* Harry Maclean <harrymaclean@gocardless.com>
|
|
18
23
|
* Jason Rudolph <github@jasonrudolph.com>
|
|
19
24
|
* Juan Pablo Buritica <juanpablo@buritica.org>
|
|
20
25
|
* Justin Halsall <justin@juice10.com>
|
|
21
26
|
* Kousuke Ebihara <Kosuke_Ebihara@voyagegroup.com>
|
|
22
27
|
* Kousuke Ebihara <kousuke@co3k.org>
|
|
28
|
+
* Kyle Rames <kyle@shopkeep.com>
|
|
23
29
|
* Lucas Carvalho <lucas.carvalho@corp.globo.com>
|
|
24
30
|
* Mark McGranaghan <mmcgrana@gmail.com>
|
|
25
31
|
* Martin Seeler <developer@chasmo.de>
|
|
32
|
+
* Masaya Myojin <m.myojin0425@gmail.com>
|
|
33
|
+
* Mathias Jean Johansen <mathias@mjj.io>
|
|
26
34
|
* Matt Gauger <matt.gauger@gmail.com>
|
|
27
35
|
* Matthew Conway <himself@mattonrails.com>
|
|
28
36
|
* Matthew Tylee Atkinson <matatk@gmail.com>
|
|
37
|
+
* Michael Sauter <michael.sauter@experteer.com>
|
|
38
|
+
* Nate Smith <nwjsmith@gmail.com>
|
|
29
39
|
* Nikolay Markov <mainameiz@gmail.com>
|
|
30
40
|
* Olivier Lance <olance@users.noreply.github.com>
|
|
41
|
+
* Reese <reese@shinymayhem.com>
|
|
42
|
+
* Reese Wilson <reese@shinymayhem.com>
|
|
31
43
|
* Scott Clasen <scott@heroku.com>
|
|
44
|
+
* Scott Moak <scott.moak@mybrainoncode.com>
|
|
32
45
|
* Takehiro Adachi <takehiro0740@gmail.com>
|
|
33
46
|
* Timothée Peignier <timothee.peignier@tryphon.org>
|
|
34
47
|
* Wesley Beary <geemus+github@gmail.com>
|
|
35
48
|
* Wesley Beary <geemus@gmail.com>
|
|
36
49
|
* Willem Dekker <wdekker@gmail.com>
|
|
37
50
|
* Zack Shapiro <zack.shapiro@kontagent.com>
|
|
38
|
-
* geemus <geemus@gmail.com>
|
|
51
|
+
* geemus <geemus@gmail.com>
|
|
52
|
+
* yuemori <yuemori@aiming-inc.com>
|
data/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2013-
|
|
3
|
+
Copyright (c) 2013-2016 [CONTRIBUTORS.md](https://github.com/interagent/prmd/blob/master/CONTRIBUTORS.md)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
6
|
this software and associated documentation files (the "Software"), to deal in
|
data/docs/schemata.md
CHANGED
|
@@ -42,7 +42,7 @@ Each attribute MUST include the following properties:
|
|
|
42
42
|
Each attribute MAY include the following properties:
|
|
43
43
|
|
|
44
44
|
* `pattern` - a javascript regex encoded in a string that the valid values MUST match
|
|
45
|
-
* `format` - format of the value. MUST be one of spec defined `["date-time", "email", "hostname", "ipv4", "ipv6", "uri"]` or defined by us `["uuid"]`
|
|
45
|
+
* `format` - format of the value. MUST be one of spec defined `["date", "date-time", "email", "hostname", "ipv4", "ipv6", "uri"]` or defined by us `["uuid"]`
|
|
46
46
|
|
|
47
47
|
Examples:
|
|
48
48
|
|
data/lib/prmd/cli/base.rb
CHANGED
|
@@ -33,8 +33,8 @@ module Prmd
|
|
|
33
33
|
# @param [Array<String>] argv
|
|
34
34
|
# @return [Array<String>] remaining arguments
|
|
35
35
|
# @private
|
|
36
|
-
def execute_parser(
|
|
37
|
-
parser.parse(argv)
|
|
36
|
+
def execute_parser(argv)
|
|
37
|
+
@parser.parse(argv)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
# Set the given key and value in the given options Hash.
|
|
@@ -66,10 +66,10 @@ module Prmd
|
|
|
66
66
|
# @return [Hash<Symbol, Object>] parsed options
|
|
67
67
|
def parse_options(argv, options = {})
|
|
68
68
|
opts = {}
|
|
69
|
-
parser = make_parser(options) do |key, value|
|
|
69
|
+
@parser = make_parser(options) do |key, value|
|
|
70
70
|
set_option(opts, key, value)
|
|
71
71
|
end
|
|
72
|
-
argv = execute_parser(
|
|
72
|
+
argv = execute_parser(argv)
|
|
73
73
|
opts[:argv] = argv
|
|
74
74
|
opts
|
|
75
75
|
end
|
data/lib/prmd/cli/combine.rb
CHANGED
|
@@ -22,6 +22,9 @@ module Prmd
|
|
|
22
22
|
opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n|
|
|
23
23
|
yield :output_file, n
|
|
24
24
|
end
|
|
25
|
+
opts.on('-t', '--type-as-string', 'Allow type as string') do |t|
|
|
26
|
+
options[:type_as_string] = t
|
|
27
|
+
end
|
|
25
28
|
end
|
|
26
29
|
end
|
|
27
30
|
|
|
@@ -30,7 +33,8 @@ module Prmd
|
|
|
30
33
|
# @example Usage
|
|
31
34
|
# Prmd::CLI::Combine.execute(argv: ['schema/schemata/api'],
|
|
32
35
|
# meta: 'schema/meta.json',
|
|
33
|
-
# output_file: 'schema/api.json'
|
|
36
|
+
# output_file: 'schema/api.json',
|
|
37
|
+
# type-as-string)
|
|
34
38
|
#
|
|
35
39
|
# @param (see Prmd::CLI::Base#execute)
|
|
36
40
|
# @return (see Prmd::CLI::Base#execute)
|
data/lib/prmd/cli/generate.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require_relative 'base'
|
|
2
2
|
require_relative '../commands/init'
|
|
3
|
+
require_relative '../utils'
|
|
3
4
|
|
|
4
5
|
module Prmd
|
|
5
6
|
module CLI
|
|
@@ -40,7 +41,11 @@ module Prmd
|
|
|
40
41
|
# @return (see Prmd::CLI::Base#execute)
|
|
41
42
|
def self.execute(options = {})
|
|
42
43
|
name = options.fetch(:argv).first
|
|
43
|
-
|
|
44
|
+
if Prmd::Utils.blank?(name)
|
|
45
|
+
abort @parser
|
|
46
|
+
else
|
|
47
|
+
write_result Prmd.init(name, options), options
|
|
48
|
+
end
|
|
44
49
|
end
|
|
45
50
|
end
|
|
46
51
|
end
|
|
@@ -63,19 +63,49 @@ module Prmd
|
|
|
63
63
|
# @return (see .load_files)
|
|
64
64
|
def self.load_schemas(paths, options = {})
|
|
65
65
|
files = crawl_map(paths, options)
|
|
66
|
-
# sort for stable loading
|
|
66
|
+
# sort for stable loading across platforms
|
|
67
67
|
schemata = load_files(files.sort, options)
|
|
68
68
|
handle_faulty_load(schemata, files) unless options[:faulty_load]
|
|
69
69
|
schemata
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
+
# Escape '#' and '/' in 'href' keys. They need to be escaped in JSON schema,
|
|
73
|
+
# but to make it easier to write JSON schema with Prmd, those two characters
|
|
74
|
+
# are escaped automatically when they appear between '{()}'.
|
|
75
|
+
# See https://github.com/interagent/prmd/issues/106.
|
|
76
|
+
#
|
|
77
|
+
# @api private
|
|
78
|
+
# @param [Array<SchemaHash>] schema hashes
|
|
79
|
+
# @return [Array<SchemaHash>] schema hashes
|
|
80
|
+
def self.escape_hrefs(data)
|
|
81
|
+
if data.is_a? Array
|
|
82
|
+
data.map! {
|
|
83
|
+
|x| escape_hrefs(x)
|
|
84
|
+
}
|
|
85
|
+
elsif data.is_a?(Hash) || data.is_a?(Prmd::SchemaHash)
|
|
86
|
+
data.each { |k,v|
|
|
87
|
+
if k == 'href'
|
|
88
|
+
if v.is_a? String
|
|
89
|
+
v = v.gsub(/\{\(.*?\)\}/) { |x|
|
|
90
|
+
x.gsub('#', '%23').gsub('/', '%2F')
|
|
91
|
+
}
|
|
92
|
+
end
|
|
93
|
+
else
|
|
94
|
+
v = escape_hrefs(v)
|
|
95
|
+
end
|
|
96
|
+
data[k] = v
|
|
97
|
+
}
|
|
98
|
+
end
|
|
99
|
+
data
|
|
100
|
+
end
|
|
101
|
+
|
|
72
102
|
# Merges all found schema files in the given paths into a single Schema
|
|
73
103
|
#
|
|
74
104
|
# @param [Array<String>] paths
|
|
75
105
|
# @param [Hash<Symbol, Object>] options
|
|
76
106
|
# @return (see Prmd::Combiner#combine)
|
|
77
107
|
def self.combine(paths, options = {})
|
|
78
|
-
schemata = load_schemas(paths)
|
|
108
|
+
schemata = escape_hrefs(load_schemas(paths))
|
|
79
109
|
base = Prmd::Template.load_json('combine_head.json')
|
|
80
110
|
schema = base['$schema']
|
|
81
111
|
meta = {}
|
|
@@ -89,7 +119,7 @@ module Prmd
|
|
|
89
119
|
end
|
|
90
120
|
meta ||= {}
|
|
91
121
|
end
|
|
92
|
-
combiner = Prmd::Combiner.new(meta: meta, base: base, schema: schema)
|
|
122
|
+
combiner = Prmd::Combiner.new(meta: meta, base: base, schema: schema, options: options)
|
|
93
123
|
combiner.combine(*schemata)
|
|
94
124
|
end
|
|
95
125
|
|
|
@@ -99,6 +129,7 @@ module Prmd
|
|
|
99
129
|
private :load_schema_hash
|
|
100
130
|
private :load_files
|
|
101
131
|
private :load_schemas
|
|
132
|
+
private :escape_hrefs
|
|
102
133
|
end
|
|
103
134
|
end
|
|
104
135
|
|
data/lib/prmd/core/combiner.rb
CHANGED
|
@@ -13,6 +13,7 @@ module Prmd
|
|
|
13
13
|
@schema = properties.fetch(:schema)
|
|
14
14
|
@base = properties.fetch(:base, {})
|
|
15
15
|
@meta = properties.fetch(:meta, {})
|
|
16
|
+
@options = properties.fetch(:options, {})
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
# @param [Object] datum
|
|
@@ -53,7 +54,7 @@ module Prmd
|
|
|
53
54
|
reference_localizer(data['definitions'][id_ary])
|
|
54
55
|
end
|
|
55
56
|
|
|
56
|
-
Prmd::Schema.new(data)
|
|
57
|
+
Prmd::Schema.new(data, @options)
|
|
57
58
|
end
|
|
58
59
|
|
|
59
60
|
private :reference_localizer
|
|
@@ -51,7 +51,7 @@ module Prmd
|
|
|
51
51
|
# Defines the rake task
|
|
52
52
|
# @return [void]
|
|
53
53
|
def define
|
|
54
|
-
desc 'Combine schemas' unless Rake.application.
|
|
54
|
+
desc 'Combine schemas' unless Rake.application.last_description
|
|
55
55
|
task(name) do
|
|
56
56
|
result = Prmd.combine(paths, options)
|
|
57
57
|
if output_file
|
data/lib/prmd/rake_tasks/doc.rb
CHANGED
|
@@ -73,7 +73,7 @@ module Prmd
|
|
|
73
73
|
# Defines the rake task
|
|
74
74
|
# @return [void]
|
|
75
75
|
def define
|
|
76
|
-
desc 'Generate documentation' unless Rake.application.
|
|
76
|
+
desc 'Generate documentation' unless Rake.application.last_description
|
|
77
77
|
task(name) do
|
|
78
78
|
if files.is_a?(Hash)
|
|
79
79
|
files.each do |infile, outfile|
|
|
@@ -58,7 +58,7 @@ module Prmd
|
|
|
58
58
|
# Defines the rake task
|
|
59
59
|
# @return [void]
|
|
60
60
|
def define
|
|
61
|
-
desc 'Verify schemas' unless Rake.application.
|
|
61
|
+
desc 'Verify schemas' unless Rake.application.last_description
|
|
62
62
|
task(name) do
|
|
63
63
|
all_errors = []
|
|
64
64
|
files.each do |filename|
|
data/lib/prmd/schema.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Prmd
|
|
|
10
10
|
"number" => 42.0,
|
|
11
11
|
"string" => "example",
|
|
12
12
|
|
|
13
|
+
"date" => "2015-01-01",
|
|
13
14
|
"date-time" => "2015-01-01T12:00:00Z",
|
|
14
15
|
"email" => "username@example.com",
|
|
15
16
|
"hostname" => "example.com",
|
|
@@ -24,24 +25,28 @@ module Prmd
|
|
|
24
25
|
attr_reader :data
|
|
25
26
|
|
|
26
27
|
# @param [Hash<String, Object>] new_data
|
|
27
|
-
def initialize(new_data = {})
|
|
28
|
-
@data = convert_type_to_array(new_data)
|
|
28
|
+
def initialize(new_data = {}, options = {})
|
|
29
|
+
@data = convert_type_to_array(new_data, options)
|
|
29
30
|
@schemata_examples = {}
|
|
30
31
|
end
|
|
31
32
|
|
|
32
33
|
#
|
|
33
34
|
# @param [Object] datum
|
|
34
35
|
# @return [Object] same type as the input object
|
|
35
|
-
def convert_type_to_array(datum)
|
|
36
|
+
def convert_type_to_array(datum, options)
|
|
36
37
|
case datum
|
|
37
38
|
when Array
|
|
38
|
-
datum.map { |element| convert_type_to_array(element) }
|
|
39
|
+
datum.map { |element| convert_type_to_array(element, options) }
|
|
39
40
|
when Hash
|
|
40
|
-
if datum.key?('type') && datum['type'].is_a?(String)
|
|
41
|
+
if datum.key?('type') && datum['type'].is_a?(String) && !options[:type_as_string]
|
|
41
42
|
datum['type'] = [*datum['type']]
|
|
42
43
|
end
|
|
43
44
|
datum.each_with_object({}) do |(k, v), hash|
|
|
44
|
-
|
|
45
|
+
if k != 'example'
|
|
46
|
+
hash[k] = convert_type_to_array(v, options)
|
|
47
|
+
else
|
|
48
|
+
hash[k] = v
|
|
49
|
+
end
|
|
45
50
|
end
|
|
46
51
|
else
|
|
47
52
|
datum
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<%=
|
|
2
2
|
schemata_template = Prmd::Template::load('schemata.md.erb', options[:template])
|
|
3
3
|
|
|
4
|
-
schema['properties'].map do |
|
|
4
|
+
schema['properties'].keys.sort.map do |key|
|
|
5
|
+
resource, property = key, schema['properties'][key]
|
|
5
6
|
begin
|
|
6
7
|
_, schemata = schema.dereference(property)
|
|
7
8
|
schemata_template.result({
|
|
@@ -76,12 +76,13 @@
|
|
|
76
76
|
end
|
|
77
77
|
[key, type, description, example]
|
|
78
78
|
}
|
|
79
|
-
return attributes
|
|
79
|
+
return attributes.sort
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def extract_schemata_refs(schema, properties)
|
|
83
83
|
ret = []
|
|
84
|
-
properties.each do |
|
|
84
|
+
properties.keys.sort.each do |key|
|
|
85
|
+
value = properties[key]
|
|
85
86
|
ref, value = schema.dereference(value)
|
|
86
87
|
if value['properties']
|
|
87
88
|
refs = extract_schemata_refs(schema, value['properties'])
|
|
@@ -136,7 +137,7 @@
|
|
|
136
137
|
end
|
|
137
138
|
|
|
138
139
|
if value['pattern']
|
|
139
|
-
description += "<br/> **pattern:**
|
|
140
|
+
description += "<br/> **pattern:** `#{value['pattern'].gsub /\|/, '|'}`"
|
|
140
141
|
end
|
|
141
142
|
|
|
142
143
|
if value['minLength'] || value['maxLength']
|
|
@@ -21,12 +21,12 @@ $ curl -n -X <%= link['method'] %> <%= schema.href %><%= path -%><%- unless opti
|
|
|
21
21
|
<%- else %>
|
|
22
22
|
$ curl -n <%= schema.href %><%= path -%><%- unless options[:http_header].empty? %> \<%- end %>
|
|
23
23
|
<%- end %>
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
<%- end %>
|
|
27
|
-
<%- if !data.nil? && link['method'].upcase != 'GET' %> \
|
|
28
|
-
-d '<%= JSON.pretty_generate(data) %>'
|
|
24
|
+
<%- if !data.nil? && link['method'].upcase != 'GET' %>
|
|
25
|
+
-d '<%= JSON.pretty_generate(data) %>'<%- unless options[:http_header].empty? %> \<%- end %>
|
|
29
26
|
<%- elsif !get_params.empty? && link['method'].upcase == 'GET' %> -G \
|
|
30
|
-
-d <%= get_params.join(" \\\n -d ") %>
|
|
27
|
+
-d <%= get_params.join(" \\\n -d ") %><%- unless options[:http_header].empty? %> \<%- end %>
|
|
28
|
+
<%- end %>
|
|
29
|
+
<%- options[:http_header].each do |key, value| %>
|
|
30
|
+
-H "<%= key %>: <%= value %>"<%- if key != options[:http_header].keys.last %> \<%- end %>
|
|
31
31
|
<%- end %>
|
|
32
32
|
```
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
title = schemata['title'].split(' - ', 2).last
|
|
10
10
|
-%>
|
|
11
11
|
<%- unless options[:doc][:disable_title_and_description] %>
|
|
12
|
-
## <a name="resource-<%= resource %>"
|
|
12
|
+
## <a name="resource-<%= resource %>"><%= title %></a>
|
|
13
|
+
|
|
14
|
+
<%- if schemata['stability'] && !schemata['stability'].empty? %>
|
|
15
|
+
Stability: `<%= schemata['stability'] %>`
|
|
16
|
+
<%- end -%>
|
|
13
17
|
|
|
14
18
|
<%= schemata['description'] %>
|
|
15
19
|
<%- end -%>
|
data/lib/prmd/utils.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Prmd
|
|
2
|
+
# For any tid bits, or core extension methods, without the "core" extension
|
|
3
|
+
module Utils
|
|
4
|
+
# For checking if the string contains only spaces
|
|
5
|
+
BLANK_REGEX = /\A\s+\z/
|
|
6
|
+
|
|
7
|
+
def self.blank?(obj)
|
|
8
|
+
if obj.nil?
|
|
9
|
+
true
|
|
10
|
+
elsif obj.is_a?(String)
|
|
11
|
+
obj.empty? || !!(obj =~ BLANK_REGEX)
|
|
12
|
+
elsif obj.respond_to?(:empty?)
|
|
13
|
+
obj.empty?
|
|
14
|
+
else
|
|
15
|
+
false
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
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, 12, 0, nil
|
|
6
6
|
# version string
|
|
7
7
|
# @return [String]
|
|
8
8
|
STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze
|
data/lib/prmd.rb
CHANGED
|
@@ -3,6 +3,7 @@ require_relative 'prmd/load_schema_file'
|
|
|
3
3
|
require_relative 'prmd/commands'
|
|
4
4
|
require_relative 'prmd/schema'
|
|
5
5
|
require_relative 'prmd/link'
|
|
6
|
+
require_relative 'prmd/utils'
|
|
6
7
|
require_relative 'prmd/template'
|
|
7
8
|
require_relative 'prmd/url_generator'
|
|
8
9
|
require_relative 'prmd/hash_helpers'
|
data/test/cli/combine_test.rb
CHANGED
data/test/cli/doc_test.rb
CHANGED
data/test/cli/generate_test.rb
CHANGED
data/test/cli/render_test.rb
CHANGED
data/test/cli/verify_test.rb
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require_relative '../helpers'
|
|
2
|
+
|
|
3
|
+
require 'json_pointer'
|
|
4
|
+
|
|
5
|
+
class InteragentHyperSchemaCombineTest < Minitest::Test
|
|
6
|
+
|
|
7
|
+
#
|
|
8
|
+
# resource link readable href
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
def test_resource_link_href_escaping
|
|
12
|
+
pointer('#/definitions/app/links/0').merge!({
|
|
13
|
+
'href' => '/apps/{(#/definitions/app)}'
|
|
14
|
+
})
|
|
15
|
+
assert_equal "/apps/{(%23%2Fdefinitions%2Fapp)}", escaped_href
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_resource_link_href_no_double_escaping
|
|
19
|
+
pointer('#/definitions/app/links/0').merge!({
|
|
20
|
+
'href' => '/apps/{(%23%2Fdefinitions%2Fapp)}'
|
|
21
|
+
})
|
|
22
|
+
assert_equal "/apps/{(%23%2Fdefinitions%2Fapp)}", escaped_href
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_resource_link_href_no_side_effects
|
|
26
|
+
pointer('#/definitions/app/links/0').merge!({
|
|
27
|
+
'href' => '/apps/foo#bar'
|
|
28
|
+
})
|
|
29
|
+
assert_equal "/apps/foo#bar", escaped_href
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def data
|
|
35
|
+
@data ||= {
|
|
36
|
+
'$schema' => 'http://interagent.github.io/interagent-hyper-schema',
|
|
37
|
+
'description' => 'My simple example API.',
|
|
38
|
+
'id' => 'http://example.com/schema',
|
|
39
|
+
'title' => 'Example API',
|
|
40
|
+
'definitions' => {
|
|
41
|
+
'app' => {
|
|
42
|
+
'description' => 'An app in our PaaS ecosystem.',
|
|
43
|
+
'title' => 'App',
|
|
44
|
+
'type' => 'object',
|
|
45
|
+
'definitions' => {},
|
|
46
|
+
'links' => [
|
|
47
|
+
{
|
|
48
|
+
'description' => 'Create a new app.',
|
|
49
|
+
'href' => '/apps',
|
|
50
|
+
'method' => 'POST',
|
|
51
|
+
'rel' => 'create',
|
|
52
|
+
'title' => 'Create App'
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
'properties' => {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
'links' => [],
|
|
60
|
+
'properties' => {},
|
|
61
|
+
'type' => 'object'
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def pointer(path)
|
|
66
|
+
JsonPointer.evaluate(data, path)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def escaped_href
|
|
70
|
+
escaped = Prmd::Combine.__send__(:escape_hrefs, data)
|
|
71
|
+
escaped["definitions"]["app"]["links"][0]["href"]
|
|
72
|
+
end
|
|
73
|
+
end
|
data/test/commands/init_test.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative '../helpers'
|
|
2
2
|
|
|
3
3
|
require 'json_pointer'
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ class InteragentRenderTest < Minitest::Test
|
|
|
6
6
|
def test_render_for_valid_schema
|
|
7
7
|
markdown = render
|
|
8
8
|
|
|
9
|
-
assert_match
|
|
9
|
+
assert_match(/An app in our PaaS ecosystem./, markdown)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def test_render_for_schema_with_property_defined_with_anyOf
|
|
@@ -21,15 +21,15 @@ class InteragentRenderTest < Minitest::Test
|
|
|
21
21
|
}
|
|
22
22
|
})
|
|
23
23
|
markdown = render
|
|
24
|
-
assert_match
|
|
24
|
+
assert_match(/version.*v10\.9\.rc1/, markdown)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def test_render_for_schema_with_property_defined_with_oneOf
|
|
29
29
|
markdown = render
|
|
30
30
|
|
|
31
|
-
assert_match
|
|
32
|
-
assert_match
|
|
31
|
+
assert_match(/\*\*options\/\[OPTION1\]\.type\*\*/, markdown)
|
|
32
|
+
assert_match(/\*\*options\/\[OPTION2\]\.type\*\*/, markdown)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
|
|
@@ -95,37 +95,37 @@ class InteragentRenderTest < Minitest::Test
|
|
|
95
95
|
'example' => 'example'
|
|
96
96
|
},
|
|
97
97
|
'option-type1' => {
|
|
98
|
-
'type' => 'string',
|
|
99
|
-
'example' => 'OPTION1',
|
|
100
|
-
'enum' => 'OPTION1'
|
|
98
|
+
'type' => 'string',
|
|
99
|
+
'example' => 'OPTION1',
|
|
100
|
+
'enum' => 'OPTION1'
|
|
101
101
|
},
|
|
102
102
|
'option-type2' => {
|
|
103
|
-
'type' => 'string',
|
|
103
|
+
'type' => 'string',
|
|
104
104
|
'example' => 'OPTION2',
|
|
105
105
|
'enum' => 'OPTION2'
|
|
106
106
|
},
|
|
107
107
|
'option1' => {
|
|
108
108
|
'properties' => {
|
|
109
109
|
'type' => {
|
|
110
|
-
'$ref' => '#/definitions/config-var/definitions/option-type1'
|
|
110
|
+
'$ref' => '#/definitions/config-var/definitions/option-type1'
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
},
|
|
114
114
|
'option2' => {
|
|
115
115
|
'properties' => {
|
|
116
116
|
'type' => {
|
|
117
|
-
'$ref' => '#/definitions/config-var/definitions/option-type2'
|
|
117
|
+
'$ref' => '#/definitions/config-var/definitions/option-type2'
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
},
|
|
121
|
-
'options' => {
|
|
121
|
+
'options' => {
|
|
122
122
|
'items' => {
|
|
123
123
|
'example'=> 'CHOICE1',
|
|
124
124
|
'oneOf' => [
|
|
125
|
-
{
|
|
125
|
+
{
|
|
126
126
|
'$ref' => '#/definitions/config-var/definitions/option1'
|
|
127
127
|
},
|
|
128
|
-
{
|
|
128
|
+
{
|
|
129
129
|
'$ref' => '#/definitions/config-var/definitions/option2'
|
|
130
130
|
}
|
|
131
131
|
]
|
data/test/link_test.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helpers'
|
|
2
|
+
|
|
2
3
|
module Prmd
|
|
3
4
|
class LinkTest < MiniTest::Test
|
|
4
5
|
include PrmdLinkTestHelpers
|
|
@@ -22,7 +23,7 @@ module Prmd
|
|
|
22
23
|
{
|
|
23
24
|
title: "multiple_nested_required" ,
|
|
24
25
|
optional: {"user:name" => "string"},
|
|
25
|
-
required: {"user:email" => "string",
|
|
26
|
+
required: {"user:email" => "string",
|
|
26
27
|
"address:street" => "string",
|
|
27
28
|
"address:zip" => "string"}
|
|
28
29
|
}
|
data/test/multi_loader/common.rb
CHANGED
data/test/rake_tasks/doc_test.rb
CHANGED
data/test/schema_test.rb
CHANGED
data/test/utils_test.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require_relative 'helpers'
|
|
2
|
+
|
|
3
|
+
class UtilsTest < Minitest::Test
|
|
4
|
+
def test_blank?
|
|
5
|
+
assert_equal true, Prmd::Utils.blank?(nil)
|
|
6
|
+
assert_equal true, Prmd::Utils.blank?([])
|
|
7
|
+
assert_equal true, Prmd::Utils.blank?({})
|
|
8
|
+
assert_equal true, Prmd::Utils.blank?("")
|
|
9
|
+
assert_equal true, Prmd::Utils.blank?(" ")
|
|
10
|
+
assert_equal true, Prmd::Utils.blank?(" ")
|
|
11
|
+
assert_equal false, Prmd::Utils.blank?([nil])
|
|
12
|
+
assert_equal false, Prmd::Utils.blank?({ a: nil })
|
|
13
|
+
assert_equal false, Prmd::Utils.blank?("A")
|
|
14
|
+
assert_equal false, Prmd::Utils.blank?(Object.new)
|
|
15
|
+
end
|
|
16
|
+
end
|
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.12.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- geemus
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: erubis
|
|
@@ -152,6 +152,7 @@ files:
|
|
|
152
152
|
- lib/prmd/url_generator.rb
|
|
153
153
|
- lib/prmd/url_generators/generators/default.rb
|
|
154
154
|
- lib/prmd/url_generators/generators/json.rb
|
|
155
|
+
- lib/prmd/utils.rb
|
|
155
156
|
- lib/prmd/version.rb
|
|
156
157
|
- prmd.gemspec
|
|
157
158
|
- schemas/hyper-schema.json
|
|
@@ -162,6 +163,7 @@ files:
|
|
|
162
163
|
- test/cli/generate_test.rb
|
|
163
164
|
- test/cli/render_test.rb
|
|
164
165
|
- test/cli/verify_test.rb
|
|
166
|
+
- test/commands/combine_test.rb
|
|
165
167
|
- test/commands/init_test.rb
|
|
166
168
|
- test/commands/render_test.rb
|
|
167
169
|
- test/commands/verify_test.rb
|
|
@@ -188,6 +190,7 @@ files:
|
|
|
188
190
|
- test/schemata/input/rake_doc.json
|
|
189
191
|
- test/schemata/input/rake_verify.json
|
|
190
192
|
- test/schemata/input/user.json
|
|
193
|
+
- test/utils_test.rb
|
|
191
194
|
homepage: https://github.com/heroku/prmd
|
|
192
195
|
licenses:
|
|
193
196
|
- MIT
|
|
@@ -208,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
208
211
|
version: '0'
|
|
209
212
|
requirements: []
|
|
210
213
|
rubyforge_project:
|
|
211
|
-
rubygems_version: 2.
|
|
214
|
+
rubygems_version: 2.5.1
|
|
212
215
|
signing_key:
|
|
213
216
|
specification_version: 4
|
|
214
217
|
summary: JSON Schema tooling
|
|
@@ -218,6 +221,7 @@ test_files:
|
|
|
218
221
|
- test/cli/generate_test.rb
|
|
219
222
|
- test/cli/render_test.rb
|
|
220
223
|
- test/cli/verify_test.rb
|
|
224
|
+
- test/commands/combine_test.rb
|
|
221
225
|
- test/commands/init_test.rb
|
|
222
226
|
- test/commands/render_test.rb
|
|
223
227
|
- test/commands/verify_test.rb
|
|
@@ -244,4 +248,4 @@ test_files:
|
|
|
244
248
|
- test/schemata/input/rake_doc.json
|
|
245
249
|
- test/schemata/input/rake_verify.json
|
|
246
250
|
- test/schemata/input/user.json
|
|
247
|
-
|
|
251
|
+
- test/utils_test.rb
|