prmd 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CONTRIBUTING.md +6 -6
- data/CONTRIBUTORS.md +3 -0
- data/Gemfile.lock +1 -1
- data/lib/prmd/commands/combine.rb +10 -7
- data/lib/prmd/commands/verify.rb +8 -11
- data/lib/prmd/schema.rb +19 -13
- data/lib/prmd/templates/schema.erb +2 -1
- data/lib/prmd/templates/schemata.erb +10 -5
- data/lib/prmd/version.rb +1 -1
- data/test/helpers.rb +1 -1
- data/test/schema_test.rb +12 -12
- data/test/{schemas → schemata}/input/meta.json +1 -0
- data/test/{schemas → schemata}/input/user.json +1 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzFkN2NlODhjNzdiNjMyN2E1YTQwMTg0MWRjMTNhMDUwZWE5YTc3OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGQzODUzMzI3M2U5YjliZDNhNzQ0YjM2ZTUzNzA1MjI1ODQ3Y2NiZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzgxZjQyZGMxNDRhMDM3YjI0OGUyYTdiMDVjMzYzNjUzZGJkNDM4MTU0Mjg0
|
10
|
+
NzMyN2I0ODBiZDNmZTc0NDIzZjU4YWQwMWJkNWQ5NDNkOWYyYjY3MTRkODJm
|
11
|
+
NzU4OWFlM2NkMWY5NDY5MmYxYjVhN2I4NDk2OWM4NTYxNTliMTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGVkMDAxMGUxMzk4ODY5NTM4N2VlNjJjMzBjMWEyOWFhY2JhMGIyOTkwMjU0
|
14
|
+
OWUwNTkyMTlkZWE2MjM4Yjk0NDI5MzRiZDhlOGI3MTU4OWMxZWY3ZWVlNjll
|
15
|
+
ZGUxYzE0N2QyZmJjZWNjOWM4N2Q3ZGFhMzg1YjdlZjc5ZmRkNzM=
|
data/CONTRIBUTING.md
CHANGED
@@ -5,14 +5,14 @@ New contributors are always welcome, when it doubt please ask questions. We stri
|
|
5
5
|
### Coding
|
6
6
|
|
7
7
|
* Pick a task:
|
8
|
-
* Offer feedback on open [pull requests](https://github.com/
|
9
|
-
* Review open [issues](https://github.com/
|
10
|
-
* [Create an issue](https://github.com/
|
8
|
+
* Offer feedback on open [pull requests](https://github.com/interagent/prmd/pulls).
|
9
|
+
* Review open [issues](https://github.com/interagent/prmd/issues) for things to help on.
|
10
|
+
* [Create an issue](https://github.com/interagent/prmd/issues/new) to start a discussion on additions or features.
|
11
11
|
* Fork the project, add your changes and tests to cover them in a topic branch.
|
12
|
-
* Commit your changes and rebase against `
|
13
|
-
* [Submit a pull request](https://github.com/
|
12
|
+
* Commit your changes and rebase against `interagent/prmd` to ensure everything is up to date.
|
13
|
+
* [Submit a pull request](https://github.com/interagent/prmd/compare/).
|
14
14
|
|
15
15
|
### Non-Coding
|
16
16
|
|
17
|
-
* Offer feedback on open [issues](https://github.com/
|
17
|
+
* Offer feedback on open [issues](https://github.com/interagent/prmd/issues).
|
18
18
|
* Organize or volunteer at events.
|
data/CONTRIBUTORS.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
* Brandur <brandur@heroku.com>
|
1
2
|
* Brandur <brandur@mutelight.org>
|
2
3
|
* Chris Continanza <christopher.continanza@gmail.com>
|
3
4
|
* Dane Harrigan <dane.harrigan@gmail.com>
|
5
|
+
* Ernesto Jiménez <me@ernesto-jimenez.com>
|
6
|
+
* Kousuke Ebihara <Kosuke_Ebihara@voyagegroup.com>
|
4
7
|
* Kousuke Ebihara <kousuke@co3k.org>
|
5
8
|
* Mark McGranaghan <mmcgrana@gmail.com>
|
6
9
|
* Olivier Lance <olance@users.noreply.github.com>
|
data/Gemfile.lock
CHANGED
@@ -25,34 +25,37 @@ module Prmd
|
|
25
25
|
end
|
26
26
|
|
27
27
|
schemata.each do |schema_file, schema_data|
|
28
|
-
|
28
|
+
id = schema_data['id'].split('/').last
|
29
29
|
|
30
30
|
if file = schemata_map[schema_data['id']]
|
31
31
|
$stderr.puts "`#{schema_data['id']}` (from #{schema_file}) was already defined in `#{file}` and will overwrite the first definition"
|
32
32
|
end
|
33
33
|
schemata_map[schema_data['id']] = schema_file
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
# schemas are now in a single scope by combine
|
36
|
+
schema_data.delete('id')
|
37
|
+
|
38
|
+
data['definitions']
|
39
|
+
data['definitions'][id] = schema_data
|
37
40
|
reference_localizer = lambda do |datum|
|
38
41
|
case datum
|
39
42
|
when Array
|
40
43
|
datum.map {|element| reference_localizer.call(element)}
|
41
44
|
when Hash
|
42
45
|
if datum.has_key?('$ref')
|
43
|
-
datum['$ref'] = '#/definitions' + datum['$ref'].gsub('#', '')
|
46
|
+
datum['$ref'] = '#/definitions' + datum['$ref'].gsub('#', '').gsub('/schemata', '')
|
44
47
|
end
|
45
48
|
if datum.has_key?('href')
|
46
|
-
datum['href'] = datum['href'].gsub('%23', '').gsub(%r{
|
49
|
+
datum['href'] = datum['href'].gsub('%23', '').gsub(%r{%2Fschemata(%2F[^%]*%2F)}, '%23%2Fdefinitions\1')
|
47
50
|
end
|
48
51
|
datum.each { |k,v| datum[k] = reference_localizer.call(v) }
|
49
52
|
else
|
50
53
|
datum
|
51
54
|
end
|
52
55
|
end
|
53
|
-
reference_localizer.call(data['definitions'][
|
56
|
+
reference_localizer.call(data['definitions'][id])
|
54
57
|
|
55
|
-
data['properties'][id] = { '$ref' => "#/definitions/#{
|
58
|
+
data['properties'][id] = { '$ref' => "#/definitions/#{id}" }
|
56
59
|
end
|
57
60
|
|
58
61
|
Prmd::Schema.new(data)
|
data/lib/prmd/commands/verify.rb
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
module Prmd
|
2
2
|
def self.verify(schema)
|
3
3
|
errors = []
|
4
|
-
errors << verify_schema(schema)
|
4
|
+
errors << verify_schema(schema['id'], schema)
|
5
5
|
schema = Prmd::Schema.new(schema)
|
6
6
|
if schema['properties']
|
7
7
|
schema['properties'].each do |key, value|
|
8
|
-
|
9
|
-
|
10
|
-
errors <<
|
8
|
+
id, schemata = schema.dereference(value)
|
9
|
+
|
10
|
+
errors << verify_schema(id, schemata)
|
11
|
+
errors << verify_definitions_and_links(id, schemata)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
errors.flatten!
|
14
15
|
end
|
15
16
|
|
16
|
-
def self.verify_schema(schema)
|
17
|
+
def self.verify_schema(id, schema)
|
17
18
|
errors = []
|
18
19
|
|
19
|
-
id = schema['id']
|
20
|
-
|
21
20
|
missing_requirements = []
|
22
|
-
%w{$schema definitions description
|
21
|
+
%w{$schema definitions description links properties title type}.each do |requirement|
|
23
22
|
unless schema.has_key?(requirement)
|
24
23
|
missing_requirements << requirement
|
25
24
|
end
|
@@ -31,11 +30,9 @@ module Prmd
|
|
31
30
|
errors
|
32
31
|
end
|
33
32
|
|
34
|
-
def self.verify_definitions_and_links(schema)
|
33
|
+
def self.verify_definitions_and_links(id, schema)
|
35
34
|
errors = []
|
36
35
|
|
37
|
-
id = schema['id']
|
38
|
-
|
39
36
|
if schema['definitions']
|
40
37
|
unless schema['definitions'].has_key?('identity')
|
41
38
|
errors << "Missing `#{id}#/definitions/identity`"
|
data/lib/prmd/schema.rb
CHANGED
@@ -56,26 +56,32 @@ module Prmd
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
60
|
-
|
59
|
+
def schema_value_example(value)
|
60
|
+
if value.has_key?('properties') # nested properties
|
61
|
+
return schema_example(value)
|
62
|
+
elsif value.has_key?('items') # array of objects
|
63
|
+
_, items = dereference(value['items'])
|
64
|
+
if value['items'].has_key?('example')
|
65
|
+
return [items['example']]
|
66
|
+
else
|
67
|
+
return [schema_example(items)]
|
68
|
+
end
|
69
|
+
else
|
70
|
+
return value['example']
|
71
|
+
end
|
72
|
+
end
|
61
73
|
|
74
|
+
def schema_example(schema)
|
62
75
|
if schema.has_key?('example')
|
63
|
-
|
76
|
+
schema['example']
|
64
77
|
elsif schema.has_key?('properties')
|
78
|
+
example = {}
|
65
79
|
schema['properties'].each do |key, value|
|
66
80
|
_, value = dereference(value)
|
67
|
-
|
68
|
-
example[key] = {}
|
69
|
-
value['properties'].each do |k,v|
|
70
|
-
example[key][k] = dereference(v).last['example']
|
71
|
-
end
|
72
|
-
else
|
73
|
-
example[key] = value['example']
|
74
|
-
end
|
81
|
+
example[key] = schema_value_example(value)
|
75
82
|
end
|
83
|
+
example
|
76
84
|
end
|
77
|
-
|
78
|
-
example
|
79
85
|
end
|
80
86
|
|
81
87
|
def schemata_example(schemata_id)
|
@@ -1,10 +1,11 @@
|
|
1
1
|
<%=
|
2
2
|
schemata_template = File.read(File.join(File.dirname(options[:template]), 'schemata.erb'))
|
3
3
|
|
4
|
-
schema['properties'].map do |
|
4
|
+
schema['properties'].map do |resource, property|
|
5
5
|
_, schemata = schema.dereference(property)
|
6
6
|
Erubis::Eruby.new(schemata_template).result({
|
7
7
|
options: options,
|
8
|
+
resource: resource,
|
8
9
|
schema: schema,
|
9
10
|
schemata: schemata
|
10
11
|
})
|
@@ -2,7 +2,6 @@
|
|
2
2
|
return unless schemata.has_key?('links') && !schemata['links'].empty?
|
3
3
|
|
4
4
|
link_schema_properties_template = File.read(File.join(File.dirname(options[:template]), 'link_schema_properties.erb'))
|
5
|
-
resource = schemata['id'].split('/').last
|
6
5
|
title = schemata['title'].split(' - ', 2).last
|
7
6
|
|
8
7
|
def extract_attributes(schema, properties)
|
@@ -52,7 +51,13 @@
|
|
52
51
|
if value['enum']
|
53
52
|
description += '<br/><b>one of:</b>' + [*value['enum']].map { |e| "<code>#{e.to_json}</code>" }.join(" or ")
|
54
53
|
end
|
55
|
-
|
54
|
+
|
55
|
+
if value.has_key?('example')
|
56
|
+
example = [*value['example']].map { |e| "<code>#{e.to_json}</code>" }.join(" or ")
|
57
|
+
elsif value['type'] == ['array'] && value.has_key?('items')
|
58
|
+
example = "<code>#{schema.schema_value_example(value)}</code>"
|
59
|
+
end
|
60
|
+
|
56
61
|
type = if value['type'].include?('null')
|
57
62
|
'nullable '
|
58
63
|
else
|
@@ -92,7 +97,7 @@
|
|
92
97
|
<%-
|
93
98
|
path = link['href'].gsub(%r|(\{\([^\)]+\)\})|) do |ref|
|
94
99
|
ref = ref.gsub('%2F', '/').gsub('%23', '#').gsub(%r|[\{\(\)\}]|, '')
|
95
|
-
ref_resource = ref.split('#/definitions/
|
100
|
+
ref_resource = ref.split('#/definitions/').last.split('/').first.gsub('-','_')
|
96
101
|
identity_key, identity_value = schema.dereference(ref)
|
97
102
|
if identity_value.has_key?('anyOf')
|
98
103
|
'{' + ref_resource + '_' + identity_value['anyOf'].map {|r| r['$ref'].split('/').last}.join('_or_') + '}'
|
@@ -163,9 +168,9 @@ HTTP/1.1 <%= case link['rel']
|
|
163
168
|
```
|
164
169
|
```javascript```
|
165
170
|
<%- if link['rel'] == 'instances' %>
|
166
|
-
<%= JSON.pretty_generate([schema.schemata_example(
|
171
|
+
<%= JSON.pretty_generate([schema.schemata_example(resource)]) %>
|
167
172
|
<%- else %>
|
168
|
-
<%= JSON.pretty_generate(schema.schemata_example(
|
173
|
+
<%= JSON.pretty_generate(schema.schemata_example(resource)) %>
|
169
174
|
<%- end %>
|
170
175
|
```
|
171
176
|
<%- end -%>
|
data/lib/prmd/version.rb
CHANGED
data/test/helpers.rb
CHANGED
data/test/schema_test.rb
CHANGED
@@ -3,32 +3,32 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helpers'))
|
|
3
3
|
class SchemaTest < Minitest::Test
|
4
4
|
def test_dereference_with_ref
|
5
5
|
key, value = user_input_schema.dereference({
|
6
|
-
'$ref' => '#/definitions/
|
6
|
+
'$ref' => '#/definitions/user/definitions/id'
|
7
7
|
})
|
8
|
-
assert_equal(key, '#/definitions/
|
9
|
-
assert_equal(value, user_input_schema['definitions']['
|
8
|
+
assert_equal(key, '#/definitions/user/definitions/id')
|
9
|
+
assert_equal(value, user_input_schema['definitions']['user']['definitions']['id'])
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_dereference_without_ref
|
13
|
-
key, value = user_input_schema.dereference('#/definitions/
|
14
|
-
assert_equal(key, '#/definitions/
|
15
|
-
assert_equal(value, user_input_schema['definitions']['
|
13
|
+
key, value = user_input_schema.dereference('#/definitions/user/definitions/id')
|
14
|
+
assert_equal(key, '#/definitions/user/definitions/id')
|
15
|
+
assert_equal(value, user_input_schema['definitions']['user']['definitions']['id'])
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_dereference_with_nested_ref
|
19
19
|
key, value = user_input_schema.dereference({
|
20
|
-
'$ref' => '#/definitions/
|
20
|
+
'$ref' => '#/definitions/user/definitions/identity'
|
21
21
|
})
|
22
|
-
assert_equal(key, '#/definitions/
|
23
|
-
assert_equal(value, user_input_schema['definitions']['
|
22
|
+
assert_equal(key, '#/definitions/user/definitions/id')
|
23
|
+
assert_equal(value, user_input_schema['definitions']['user']['definitions']['id'])
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_dereference_with_local_context
|
27
27
|
key, value = user_input_schema.dereference({
|
28
|
-
'$ref' => '#/definitions/
|
28
|
+
'$ref' => '#/definitions/user/properties/id',
|
29
29
|
'override' => true
|
30
30
|
})
|
31
|
-
assert_equal(key, '#/definitions/
|
32
|
-
assert_equal(value, {'override' => true}.merge(user_input_schema['definitions']['
|
31
|
+
assert_equal(key, '#/definitions/user/definitions/id')
|
32
|
+
assert_equal(value, {'override' => true}.merge(user_input_schema['definitions']['user']['definitions']['id']))
|
33
33
|
end
|
34
34
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- geemus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|
@@ -99,8 +99,8 @@ files:
|
|
99
99
|
- prmd.gemspec
|
100
100
|
- test/helpers.rb
|
101
101
|
- test/schema_test.rb
|
102
|
-
- test/
|
103
|
-
- test/
|
102
|
+
- test/schemata/input/meta.json
|
103
|
+
- test/schemata/input/user.json
|
104
104
|
homepage: https://github.com/heroku/prmd
|
105
105
|
licenses:
|
106
106
|
- MIT
|
@@ -128,6 +128,6 @@ summary: JSON Schema tooling
|
|
128
128
|
test_files:
|
129
129
|
- test/helpers.rb
|
130
130
|
- test/schema_test.rb
|
131
|
-
- test/
|
132
|
-
- test/
|
131
|
+
- test/schemata/input/meta.json
|
132
|
+
- test/schemata/input/user.json
|
133
133
|
has_rdoc:
|