prmd 0.11.4 → 0.11.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37247187ebe2f63d0ae1420104e88476ddae1a4a
4
- data.tar.gz: d6cc52e9d913ff0a2751b56830954f46e5134598
3
+ metadata.gz: 573ad3e1fa10e064ea941c603c154006bac1b82a
4
+ data.tar.gz: c7d39916a98b4cea871768fdfada42654ca59112
5
5
  SHA512:
6
- metadata.gz: 1fb29d50c819e7046eec3797d4f3e8dbe06bdd013eb2937ffd3387f23cbf8c9f73a68713d75cb3d9f5a61b79857d69084542fb0b79b9fd298a4fdb96e588bb5a
7
- data.tar.gz: fb55e50632b5414bde83ac978189f5ec673285d69d8c8615afe6b84da1b0620ce1984cbeb31b73d11566cdda18a697a29fc6d0a5ebddc5ad41d50ec8eb066105
6
+ metadata.gz: 9de89fa807a0528ddbe07ceac525b45eb75738246f682a0120ae76b79b3cb204502a805afa4d786defff9856302efa93746f1535430f163c2f5702e803293c1a
7
+ data.tar.gz: 752b8909cd8c3d050c628378f9c4a06486711a339d129eb63fa2b894fed00a543b99a8aabcb5131b64ffba96912cdf3fae8bf580affbcbb25cb478eba8655b7c
@@ -1,4 +1,11 @@
1
1
  language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - ruby-head
7
+ before_install:
8
+ - gem install bundler -v '~> 1.10'
2
9
  script: "bundle exec rake"
3
10
  notifications:
4
11
  email: false
@@ -69,13 +69,43 @@ module Prmd
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
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 = {}
@@ -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
 
@@ -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 %>"></a><%= title %>
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 -%>
@@ -136,7 +136,7 @@
136
136
  end
137
137
 
138
138
  if value['pattern']
139
- description += "<br/> **pattern:** <code>#{value['pattern'].gsub /\|/, '&#124;'}</code>"
139
+ description += "<br/> **pattern:** `#{value['pattern'].gsub /\|/, '&#124;'}`"
140
140
  end
141
141
 
142
142
  if value['minLength'] || value['maxLength']
@@ -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, 11, 4, nil
5
+ MAJOR, MINOR, TEENY, PATCH = 0, 11, 5, nil
6
6
  # version string
7
7
  # @return [String]
8
8
  STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '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
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.11.4
4
+ version: 0.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -162,6 +162,7 @@ files:
162
162
  - test/cli/generate_test.rb
163
163
  - test/cli/render_test.rb
164
164
  - test/cli/verify_test.rb
165
+ - test/commands/combine_test.rb
165
166
  - test/commands/init_test.rb
166
167
  - test/commands/render_test.rb
167
168
  - test/commands/verify_test.rb
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
209
  version: '0'
209
210
  requirements: []
210
211
  rubyforge_project:
211
- rubygems_version: 2.4.5.1
212
+ rubygems_version: 2.5.1
212
213
  signing_key:
213
214
  specification_version: 4
214
215
  summary: JSON Schema tooling
@@ -218,6 +219,7 @@ test_files:
218
219
  - test/cli/generate_test.rb
219
220
  - test/cli/render_test.rb
220
221
  - test/cli/verify_test.rb
222
+ - test/commands/combine_test.rb
221
223
  - test/commands/init_test.rb
222
224
  - test/commands/render_test.rb
223
225
  - test/commands/verify_test.rb
@@ -244,4 +246,3 @@ test_files:
244
246
  - test/schemata/input/rake_doc.json
245
247
  - test/schemata/input/rake_verify.json
246
248
  - test/schemata/input/user.json
247
- has_rdoc: