prmd 0.3.1 → 0.3.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjVhYzZlMzA0ODZlNDdhM2M1NWYzYzM0MjExMzM5NTZmMDQ2NDBhMw==
4
+ MzFkN2NlODhjNzdiNjMyN2E1YTQwMTg0MWRjMTNhMDUwZWE5YTc3OA==
5
5
  data.tar.gz: !binary |-
6
- N2VlOGY4NDYwYmIwYzM4M2VhNjVjZTViZjk0MTg0YTRlMmRiNmNlZA==
6
+ OGQzODUzMzI3M2U5YjliZDNhNzQ0YjM2ZTUzNzA1MjI1ODQ3Y2NiZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDMwNDFlZWZjM2VjZDg0Yzc0YjhhNzA4MDc5NmUxM2FiMzExZjA4NzAyOTdj
10
- YjE1NjZlNDc2Nzc5ZDY4MzNjZTAyZjhmNTI4ZTdlMWY0NDBhYmQwNGM0NDAy
11
- MjI4NTQ3NDAxMDFhMmNmZjI2N2FhOWM4N2QyM2JjNTFlNTA0NTQ=
9
+ NzgxZjQyZGMxNDRhMDM3YjI0OGUyYTdiMDVjMzYzNjUzZGJkNDM4MTU0Mjg0
10
+ NzMyN2I0ODBiZDNmZTc0NDIzZjU4YWQwMWJkNWQ5NDNkOWYyYjY3MTRkODJm
11
+ NzU4OWFlM2NkMWY5NDY5MmYxYjVhN2I4NDk2OWM4NTYxNTliMTc=
12
12
  data.tar.gz: !binary |-
13
- OTAwZjNiNzI2M2ZkZTBiZDQ1OGFlMjJkMTY0YmYwNDM0NDQ5MzQ0NGJhODU1
14
- OGE2MTk5Y2M1YjBlOGJjOGNmMDBhM2FlM2ExMzhlYmY5NDgyZWQwOTlmZTlh
15
- YzQ0NzkzODE4MmEwZjQ0ZGVlMGZiNzc2Y2MzMzI0NzYxNmViNjk=
13
+ NGVkMDAxMGUxMzk4ODY5NTM4N2VlNjJjMzBjMWEyOWFhY2JhMGIyOTkwMjU0
14
+ OWUwNTkyMTlkZWE2MjM4Yjk0NDI5MzRiZDhlOGI3MTU4OWMxZWY3ZWVlNjll
15
+ ZGUxYzE0N2QyZmJjZWNjOWM4N2Q3ZGFhMzg1YjdlZjc5ZmRkNzM=
@@ -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/heroku/prmd/pulls).
9
- * Review open [issues](https://github.com/heroku/prmd/issues) for things to help on.
10
- * [Create an issue](https://github.com/heroku/prmd/issues/new) to start a discussion on additions or features.
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 `heroku/prmd` to ensure everything is up to date.
13
- * [Submit a pull request](https://github.com/heroku/prmd/compare/).
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/heroku/prmd/issues).
17
+ * Offer feedback on open [issues](https://github.com/interagent/prmd/issues).
18
18
  * Organize or volunteer at events.
@@ -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>
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prmd (0.2.0)
4
+ prmd (0.3.1)
5
5
  erubis (~> 2.7)
6
6
 
7
7
  GEM
@@ -25,34 +25,37 @@ module Prmd
25
25
  end
26
26
 
27
27
  schemata.each do |schema_file, schema_data|
28
- id_prefix, id = schema_data['id'].split('/')
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
- data['definitions'][id_prefix] ||= {}
36
- data['definitions'][id_prefix][id] = schema_data
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{(%2Fschemata%2F[^%]*%2F)}, '%23%2Fdefinitions\1')
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'][id_prefix][id])
56
+ reference_localizer.call(data['definitions'][id])
54
57
 
55
- data['properties'][id] = { '$ref' => "#/definitions/#{id_prefix}/#{id}" }
58
+ data['properties'][id] = { '$ref' => "#/definitions/#{id}" }
56
59
  end
57
60
 
58
61
  Prmd::Schema.new(data)
@@ -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
- _, schemata = schema.dereference(value)
9
- errors << verify_schema(schemata)
10
- errors << verify_definitions_and_links(schemata)
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 id links properties title type}.each do |requirement|
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`"
@@ -56,26 +56,32 @@ module Prmd
56
56
  end
57
57
  end
58
58
 
59
- def schema_example(schema)
60
- example = {}
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
- example.merge!(schema['example'])
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
- if value.has_key?('properties') # nested properties
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 |_, property|
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
- example = [*value['example']].map { |e| "<code>#{e.to_json}</code>" }.join(" or ")
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/schemata/').last.split('/').first.gsub('-','_')
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(schemata['id'])]) %>
171
+ <%= JSON.pretty_generate([schema.schemata_example(resource)]) %>
167
172
  <%- else %>
168
- <%= JSON.pretty_generate(schema.schemata_example(schemata['id'])) %>
173
+ <%= JSON.pretty_generate(schema.schemata_example(resource)) %>
169
174
  <%- end %>
170
175
  ```
171
176
  <%- end -%>
@@ -1,3 +1,3 @@
1
1
  module Prmd
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -2,7 +2,7 @@ require "minitest/autorun"
2
2
  require "prmd"
3
3
 
4
4
  def input_schemas_path
5
- @@data_path ||= File.join(File.dirname(__FILE__), 'schemas', 'input')
5
+ @@data_path ||= File.join(File.dirname(__FILE__), 'schemata', 'input')
6
6
  end
7
7
 
8
8
  def user_input_schema
@@ -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/schemata/user/definitions/id'
6
+ '$ref' => '#/definitions/user/definitions/id'
7
7
  })
8
- assert_equal(key, '#/definitions/schemata/user/definitions/id')
9
- assert_equal(value, user_input_schema['definitions']['schemata']['user']['definitions']['id'])
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/schemata/user/definitions/id')
14
- assert_equal(key, '#/definitions/schemata/user/definitions/id')
15
- assert_equal(value, user_input_schema['definitions']['schemata']['user']['definitions']['id'])
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/schemata/user/definitions/identity'
20
+ '$ref' => '#/definitions/user/definitions/identity'
21
21
  })
22
- assert_equal(key, '#/definitions/schemata/user/definitions/id')
23
- assert_equal(value, user_input_schema['definitions']['schemata']['user']['definitions']['id'])
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/schemata/user/properties/id',
28
+ '$ref' => '#/definitions/user/properties/id',
29
29
  'override' => true
30
30
  })
31
- assert_equal(key, '#/definitions/schemata/user/definitions/id')
32
- assert_equal(value, {'override' => true}.merge(user_input_schema['definitions']['schemata']['user']['definitions']['id']))
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
@@ -2,6 +2,7 @@
2
2
  "$schema": "http://json-schema.org/draft-04/hyper-schema",
3
3
  "definitions": {},
4
4
  "description": "API lets you interact with service",
5
+ "id": "schemata",
5
6
  "links": [{
6
7
  "href": "https://api.example.com",
7
8
  "rel": "self"
@@ -4,6 +4,7 @@
4
4
  "type": [
5
5
  "object"
6
6
  ],
7
+ "description": "User represents an API account.",
7
8
  "definitions": {
8
9
  "created_at": {
9
10
  "description": "when user was created",
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.1
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-13 00:00:00.000000000 Z
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/schemas/input/meta.json
103
- - test/schemas/input/user.json
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/schemas/input/meta.json
132
- - test/schemas/input/user.json
131
+ - test/schemata/input/meta.json
132
+ - test/schemata/input/user.json
133
133
  has_rdoc: