prmd 0.11.9 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +6 -4
  3. data/README.md +2 -1
  4. data/docs/schemata.md +7 -1
  5. data/lib/prmd.rb +1 -0
  6. data/lib/prmd/cli/base.rb +4 -4
  7. data/lib/prmd/cli/combine.rb +5 -1
  8. data/lib/prmd/cli/generate.rb +6 -1
  9. data/lib/prmd/commands/combine.rb +4 -4
  10. data/lib/prmd/core/combiner.rb +2 -1
  11. data/lib/prmd/core/renderer.rb +2 -1
  12. data/lib/prmd/rake_tasks/doc.rb +7 -0
  13. data/lib/prmd/schema.rb +13 -6
  14. data/lib/prmd/templates/schema.erb +10 -1
  15. data/lib/prmd/templates/schemata.md.erb +9 -1
  16. data/lib/prmd/templates/schemata/helper.erb +8 -4
  17. data/lib/prmd/templates/schemata/link.md.erb +6 -0
  18. data/lib/prmd/templates/table_of_contents.erb +11 -0
  19. data/lib/prmd/utils.rb +19 -0
  20. data/lib/prmd/version.rb +1 -1
  21. data/prmd.gemspec +2 -2
  22. data/schemas/interagent-hyper-schema.json +1 -5
  23. data/test/cli/combine_test.rb +1 -1
  24. data/test/cli/doc_test.rb +1 -1
  25. data/test/cli/generate_test.rb +1 -1
  26. data/test/cli/render_test.rb +1 -1
  27. data/test/cli/verify_test.rb +1 -1
  28. data/test/commands/combine_test.rb +1 -1
  29. data/test/commands/init_test.rb +1 -1
  30. data/test/commands/render_test.rb +39 -15
  31. data/test/commands/verify_test.rb +1 -1
  32. data/test/core/reference_localizer_test.rb +1 -1
  33. data/test/link_test.rb +3 -2
  34. data/test/multi_loader/common.rb +1 -1
  35. data/test/multi_loader/json_test.rb +1 -1
  36. data/test/multi_loader/toml_test.rb +1 -1
  37. data/test/multi_loader/yajl_test.rb +1 -1
  38. data/test/multi_loader/yaml_test.rb +1 -1
  39. data/test/rake_tasks/combine_test.rb +1 -1
  40. data/test/rake_tasks/doc_test.rb +1 -1
  41. data/test/rake_tasks/verify_test.rb +1 -1
  42. data/test/schema_test.rb +1 -1
  43. data/test/utils_test.rb +16 -0
  44. metadata +13 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bf244e4467c2fade05c42fc6eb2bff364124fc27
4
- data.tar.gz: 6926f672aed9899c68285bec8781bb2f8f789295
2
+ SHA256:
3
+ metadata.gz: 7d549096116bdd614f84c9956e2de37d34d09721c8d67be4d189beab98787934
4
+ data.tar.gz: ecbd1909e6258876c49165bfdaaab02a6fcd99397bdd7470ec6b033c99381113
5
5
  SHA512:
6
- metadata.gz: e8a2a5ee7f81121f96ba3f467929dc2d75c756611689909e6d2e8829cf31009683423b178bff4497d629de2917ad6256c36c6473862bbbef45b6fff4d4b11103
7
- data.tar.gz: caab74ead784edd5adaaa34af492a16efef66c4acc9ae5839b296fa3932611c87cbdbc955dbe75ae4914d576f74d1ed4ce11665778e3c299cded3540ba77730b
6
+ metadata.gz: 92c5e9081ae01609eac6223fe89e1a487bf9924001d60ef14baf3557c7ea053ecefe010ab4ae2ba7f771c82266abc6c891cb610662c1d5d32b426331bb2dce0b
7
+ data.tar.gz: 9874013f4b85083bf9405dad926be63584a5856fa6810463f727bec82a81d363d350117a122db2fd90e865306f3dc3ec9f29e8a8de57d74d7c9512414dcb8d55
@@ -1,11 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0
4
- - 2.1
5
- - 2.2
3
+ - 2.3.8
4
+ - 2.4.10
5
+ - 2.5.8
6
+ - 2.6.6
7
+ - 2.7.2
6
8
  - ruby-head
7
9
  before_install:
8
- - gem install bundler -v '~> 1.10'
10
+ - gem install bundler -v '~> 2.0'
9
11
  script: "bundle exec rake"
10
12
  notifications:
11
13
  email: false
data/README.md CHANGED
@@ -129,7 +129,8 @@ Available options (and their defaults)
129
129
  {
130
130
  "doc": {
131
131
  "url_style": "default", // can also be "json"
132
- "disable_title_and_description": false // remove the title and the description, useful when using your own custom header
132
+ "disable_title_and_description": false, // remove the title and the description, useful when using your own custom header
133
+ "toc": false // insert the table of content for json scheme documentation to the top of the file. (default disable)
133
134
  }
134
135
  }
135
136
  ```
@@ -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
 
@@ -55,6 +55,11 @@ Examples:
55
55
  "format": "uuid",
56
56
  "type": ["string"]
57
57
  },
58
+ "identity": {
59
+ "anyOf": [
60
+ { "$ref": "/schemata/example#/definitions/id" }
61
+ ]
62
+ },
58
63
  "url": {
59
64
  "description": "URL of resource",
60
65
  "example": "http://example.com",
@@ -138,6 +143,7 @@ Links that expect a custom http header MUST include the following attributes:
138
143
  },
139
144
  "title": "Update"
140
145
  }
146
+ ]
141
147
  }
142
148
  ```
143
149
 
@@ -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'
@@ -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(parser, argv)
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(parser, argv)
72
+ argv = execute_parser(argv)
73
73
  opts[:argv] = argv
74
74
  opts
75
75
  end
@@ -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)
@@ -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
- write_result Prmd.init(name, options), options
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
@@ -32,8 +32,7 @@ module Prmd
32
32
  end
33
33
  files.flatten!
34
34
  files.delete(options[:meta])
35
- # sort by name without extension for stable order
36
- files.sort_by {|file| file.split('.', 2).first}
35
+ files
37
36
  end
38
37
 
39
38
  # @api private
@@ -64,7 +63,8 @@ module Prmd
64
63
  # @return (see .load_files)
65
64
  def self.load_schemas(paths, options = {})
66
65
  files = crawl_map(paths, options)
67
- schemata = load_files(files, options)
66
+ # sort for stable loading across platforms
67
+ schemata = load_files(files.sort, options)
68
68
  handle_faulty_load(schemata, files) unless options[:faulty_load]
69
69
  schemata
70
70
  end
@@ -119,7 +119,7 @@ module Prmd
119
119
  end
120
120
  meta ||= {}
121
121
  end
122
- combiner = Prmd::Combiner.new(meta: meta, base: base, schema: schema)
122
+ combiner = Prmd::Combiner.new(meta: meta, base: base, schema: schema, options: options)
123
123
  combiner.combine(*schemata)
124
124
  end
125
125
 
@@ -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
@@ -28,7 +28,8 @@ module Prmd
28
28
  def append_default_options(options)
29
29
  options[:doc] = {
30
30
  url_style: 'default',
31
- disable_title_and_description: false
31
+ disable_title_and_description: false,
32
+ toc: false
32
33
  }.merge(options[:doc])
33
34
  end
34
35
 
@@ -5,6 +5,7 @@ require 'prmd/url_generator'
5
5
  require 'prmd/template'
6
6
  require 'prmd/schema'
7
7
  require 'prmd/link'
8
+ require_relative '../hash_helpers'
8
9
 
9
10
  # :nodoc:
10
11
  module Prmd
@@ -21,6 +22,8 @@ module Prmd
21
22
  # @return [Array<String>, Hash<String, String>] list of files
22
23
  attr_accessor :files
23
24
 
25
+ attr_accessor :toc
26
+
24
27
  # Creates a new task with name +name+.
25
28
  #
26
29
  # @overload initialize(name)
@@ -32,6 +35,10 @@ module Prmd
32
35
  options = legacy_parameters(*args)
33
36
  @files = options.fetch(:files) { [] }
34
37
  super options, &block
38
+ if @options[:settings].is_a? String
39
+ settings = Prmd.load_schema_file(@options[:settings])
40
+ @options.merge! HashHelpers.deep_symbolize_keys(settings)
41
+ end
35
42
  @options[:template] ||= Prmd::Template.template_dirname
36
43
  end
37
44
 
@@ -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
- hash[k] = convert_type_to_array(v)
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
@@ -113,6 +118,8 @@ module Prmd
113
118
  end
114
119
  ref = id_ref || value['anyOf'].first
115
120
  schema_example(ref)
121
+ elsif value.key?('allOf')
122
+ value['allOf'].map { |ref| schema_example(ref) }.reduce({}, &:merge)
116
123
  elsif value.key?('properties') # nested properties
117
124
  schema_example(value)
118
125
  elsif value.key?('items') # array of objects
@@ -1,7 +1,16 @@
1
+ <%- if options[:doc][:toc] -%>
2
+ <%=
3
+ Prmd::Template::load('table_of_contents.erb', options[:template]).result({
4
+ options: options,
5
+ schema: schema
6
+ })
7
+ %>
8
+ <%- end -%>
1
9
  <%=
2
10
  schemata_template = Prmd::Template::load('schemata.md.erb', options[:template])
3
11
 
4
- schema['properties'].map do |resource, property|
12
+ schema['properties'].keys.sort.map do |key|
13
+ resource, property = key, schema['properties'][key]
5
14
  begin
6
15
  _, schemata = schema.dereference(property)
7
16
  schemata_template.result({
@@ -9,7 +9,8 @@
9
9
  title = schemata['title'].split(' - ', 2).last
10
10
  -%>
11
11
  <%- unless options[:doc][:disable_title_and_description] %>
12
- ## <a name="resource-<%= resource %>"><%= title %></a>
12
+ <a name="#resource-<%= resource %>"></a>
13
+ ## <%= title %>
13
14
 
14
15
  <%- if schemata['stability'] && !schemata['stability'].empty? %>
15
16
  Stability: `<%= schemata['stability'] %>`
@@ -19,8 +20,13 @@ Stability: `<%= schemata['stability'] %>`
19
20
  <%- end -%>
20
21
 
21
22
  <%- if schemata['properties'] && !schemata['properties'].empty? %>
23
+
22
24
  ### Attributes
23
25
 
26
+ <details>
27
+ <summary>Details</summary>
28
+
29
+
24
30
  | Name | Type | Description | Example |
25
31
  | ------- | ------- | ------- | ------- |
26
32
  <%- refs = extract_schemata_refs(schema, schemata['properties']).map {|v| v && v.split("/")} %>
@@ -33,6 +39,8 @@ Stability: `<%= schemata['stability'] %>`
33
39
  | **<%= name %>** | *<%= type %>* | <%= description %> | <%= example %> |
34
40
  <%- end %>
35
41
 
42
+ </details>
43
+
36
44
  <%- end %>
37
45
  <%- (schemata['links'] || []).each do |link, datum| %>
38
46
  <%=
@@ -81,7 +81,8 @@
81
81
 
82
82
  def extract_schemata_refs(schema, properties)
83
83
  ret = []
84
- properties.each do |_, value|
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,10 @@
136
137
  end
137
138
 
138
139
  if value['pattern']
139
- description += "<br/> **pattern:** `#{value['pattern'].gsub /\|/, '&#124;'}`"
140
+ # Prevent the pipe regex pattern characters from being interpreted as markdown table:
141
+ pattern = value['pattern'].gsub(/\|/, '&#x7c;')
142
+
143
+ description += "<br/> **pattern:** <pre>#{pattern}</pre>"
140
144
  end
141
145
 
142
146
  if value['minLength'] || value['maxLength']
@@ -174,7 +178,7 @@
174
178
  else
175
179
  ''
176
180
  end
177
- type += (value['format'] || (value['type'] - ['null']).first)
181
+ type += (value['format'] || (value['type'] - ['null']).join(' or '))
178
182
  [key, type, description, example]
179
183
  end
180
184
 
@@ -182,8 +186,8 @@
182
186
  def build_link_path(schema, link)
183
187
  link['href'].gsub(%r|(\{\([^\)]+\)\})|) do |ref|
184
188
  ref = ref.gsub('%2F', '/').gsub('%23', '#').gsub(%r|[\{\(\)\}]|, '')
185
- ref_resource = ref.split('#/definitions/').last.split('/').first.gsub('-','_')
186
189
  identity_key, identity_value = schema.dereference(ref)
190
+ ref_resource = identity_key.split('#/definitions/').last.split('/').first.gsub('-','_')
187
191
  if identity_value.has_key?('anyOf')
188
192
  '{' + ref_resource + '_' + identity_value['anyOf'].map {|r| r['$ref'].split('/').last}.join('_or_') + '}'
189
193
  else
@@ -3,8 +3,12 @@
3
3
  response_example = link['response_example']
4
4
  link_schema_properties_template = Prmd::Template.load_template('link_schema_properties.md.erb', options[:template])
5
5
  -%>
6
+ <a name="link-<%= link['method'] %>-<%= resource %>-<%= link['href'] %>"></a>
6
7
  ### <%= title %> <%= link['title'] %>
7
8
 
9
+ <details>
10
+ <summary>Details</summary>
11
+
8
12
  <%= link['description'] %>
9
13
 
10
14
  ```
@@ -78,3 +82,5 @@ HTTP/1.1 <%=
78
82
  <%- end %>
79
83
  ```
80
84
  <%- end %>
85
+
86
+ </details>
@@ -0,0 +1,11 @@
1
+ <%- Prmd::Template.render('schemata/helper.erb', options[:template]) -%>
2
+ ## The table of contents
3
+
4
+ <% schema['properties'].keys.sort.map do |key| %>
5
+ <% resource, property = key, schema['properties'][key] %>
6
+ <% _, schemata = schema.dereference(property) %>
7
+ - <a href="#resource-<%= resource %>"><%= schemata['title'].split(' - ', 2).last %></a>
8
+ <% schemata.fetch('links', []).each do |l| %>
9
+ - <a href="#link-<%= l['method'] %>-<%= resource %>-<%= l['href'] %>"><%= l['method'] %> <%= build_link_path(schema, l) %></a>
10
+ <% end %>
11
+ <% end %>
@@ -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
@@ -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, 9, nil
5
+ MAJOR, MINOR, TEENY, PATCH = 0, 14, 0, nil
6
6
  # version string
7
7
  # @return [String]
8
8
  STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'erubis', '~> 2.7'
22
22
  spec.add_dependency 'json_schema', '~> 0.3', '>= 0.3.1'
23
23
 
24
- spec.add_development_dependency 'bundler', '~> 1.3'
25
- spec.add_development_dependency 'rake', '~> 10.3'
24
+ spec.add_development_dependency 'bundler', '~> 2.0'
25
+ spec.add_development_dependency 'rake', '>= 12.3.3'
26
26
  spec.add_development_dependency 'minitest', '~> 5.4'
27
27
  end
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "properties": {
68
68
  "patternProperties": {
69
- "^[a-z][a-zA-Z_]*[a-zA-Z]$": {
69
+ "^[a-z0-9][a-zA-Z0-9_]*[a-zA-Z0-9]$": {
70
70
  "$ref": "#/definitions/resourceProperty"
71
71
  }
72
72
  },
@@ -90,10 +90,6 @@
90
90
  {
91
91
  "required": ["example", "type"]
92
92
  },
93
- {
94
- "required": ["type"],
95
- "type": ["array"]
96
- },
97
93
  {
98
94
  "required": ["type"],
99
95
  "type": ["object"]
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
1
+ require_relative '../helpers'
2
2
  require 'prmd/cli/combine'
3
3
 
4
4
  class PrmdCliCombineTest < Minitest::Test
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
1
+ require_relative '../helpers'
2
2
  require 'prmd/cli/doc'
3
3
 
4
4
  class PrmdCliDocTest < Minitest::Test
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
1
+ require_relative '../helpers'
2
2
  require 'prmd/cli/generate'
3
3
 
4
4
  class PrmdCliGenerateTest < Minitest::Test
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
1
+ require_relative '../helpers'
2
2
  require 'prmd/cli/render'
3
3
 
4
4
  class PrmdCliRenderTest < Minitest::Test
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
1
+ require_relative '../helpers'
2
2
  require 'prmd/cli/verify'
3
3
 
4
4
  class PrmdCliVerifyTest < Minitest::Test
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
1
+ require_relative '../helpers'
2
2
 
3
3
  require 'json_pointer'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
1
+ require_relative '../helpers'
2
2
 
3
3
  class PrmdInitTest < Minitest::Test
4
4
  def test_init
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
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 /An app in our PaaS ecosystem./, markdown
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,18 +21,27 @@ class InteragentRenderTest < Minitest::Test
21
21
  }
22
22
  })
23
23
  markdown = render
24
- assert_match /version.*v10\.9\.rc1/, markdown
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 /\*\*options\/\[OPTION1\]\.type\*\*/, markdown
32
- assert_match /\*\*options\/\[OPTION2\]\.type\*\*/, markdown
31
+ assert_match(/\*\*options\/\[OPTION1\]\.type\*\*/, markdown)
32
+ assert_match(/\*\*options\/\[OPTION2\]\.type\*\*/, markdown)
33
33
  end
34
34
 
35
+ def test_render_for_toc
36
+ schema = Prmd::Schema.new(data)
37
+ template = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'prmd', 'templates'))
38
+ markdown = Prmd.render(schema, template: template, doc: { toc: true })
35
39
 
40
+ assert_match /^## The table of contents/, markdown
41
+ assert_match '<a href="#resource-app"', markdown
42
+ assert_match '- <a href="#link-POST-app-/apps">POST /apps', markdown
43
+ assert_match '<a name="link-POST-app-/apps"></a>', markdown
44
+ end
36
45
 
37
46
  def test_render_for_example_as_an_array
38
47
  # matches -d '[{...}]' taking into account line breaks and spacing
@@ -41,6 +50,12 @@ class InteragentRenderTest < Minitest::Test
41
50
  assert_match expression, markdown
42
51
  end
43
52
 
53
+ def test_render_for_regex_patterns_with_pipes
54
+ expression = /<pre>\(\^first\$&#x7c;\^second\$\)<\/pre> \| \`"second"\` \|\n/
55
+ markdown = render
56
+ assert_match expression, markdown
57
+ end
58
+
44
59
  private
45
60
 
46
61
  def data
@@ -95,37 +110,43 @@ class InteragentRenderTest < Minitest::Test
95
110
  'example' => 'example'
96
111
  },
97
112
  'option-type1' => {
98
- 'type' => 'string',
99
- 'example' => 'OPTION1',
100
- 'enum' => 'OPTION1'
113
+ 'type' => 'string',
114
+ 'example' => 'OPTION1',
115
+ 'enum' => 'OPTION1'
101
116
  },
102
117
  'option-type2' => {
103
- 'type' => 'string',
118
+ 'type' => 'string',
104
119
  'example' => 'OPTION2',
105
120
  'enum' => 'OPTION2'
106
121
  },
122
+ 'patterned-string' => {
123
+ 'description' => 'A string with a regex pattern applied to it.',
124
+ 'type' => 'string',
125
+ 'example' => 'second',
126
+ 'pattern' => '(^first$|^second$)'
127
+ },
107
128
  'option1' => {
108
129
  'properties' => {
109
130
  'type' => {
110
- '$ref' => '#/definitions/config-var/definitions/option-type1'
131
+ '$ref' => '#/definitions/config-var/definitions/option-type1'
111
132
  }
112
133
  }
113
134
  },
114
135
  'option2' => {
115
136
  'properties' => {
116
137
  'type' => {
117
- '$ref' => '#/definitions/config-var/definitions/option-type2'
138
+ '$ref' => '#/definitions/config-var/definitions/option-type2'
118
139
  }
119
140
  }
120
141
  },
121
- 'options' => {
142
+ 'options' => {
122
143
  'items' => {
123
144
  'example'=> 'CHOICE1',
124
145
  'oneOf' => [
125
- {
146
+ {
126
147
  '$ref' => '#/definitions/config-var/definitions/option1'
127
148
  },
128
- {
149
+ {
129
150
  '$ref' => '#/definitions/config-var/definitions/option2'
130
151
  }
131
152
  ]
@@ -166,7 +187,10 @@ class InteragentRenderTest < Minitest::Test
166
187
  },
167
188
  'options' => {
168
189
  '$ref' => '#/definitions/config-var/definitions/options'
169
- }
190
+ },
191
+ 'patterned-string' => {
192
+ '$ref' => '#/definitions/config-var/definitions/patterned-string'
193
+ },
170
194
  }
171
195
  }
172
196
  },
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helpers'))
1
+ require_relative '../helpers'
2
2
 
3
3
  require 'json_pointer'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../helpers', File.dirname(__FILE__))
1
+ require_relative '../helpers'
2
2
 
3
3
  module Prmd
4
4
  class ReferenceLocalizerTest < Minitest::Test
@@ -1,4 +1,5 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '.', 'helpers'))
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
  }
@@ -1,4 +1,4 @@
1
- require File.expand_path('../helpers', File.dirname(__FILE__))
1
+ require_relative '../helpers'
2
2
 
3
3
  module PrmdLoaderTests
4
4
  # @abstrac
@@ -1,4 +1,4 @@
1
- require File.expand_path('common', File.dirname(__FILE__))
1
+ require_relative 'common'
2
2
  require 'prmd/multi_loader/json'
3
3
 
4
4
  class PrmdMultiLoaderJsonTest < Minitest::Test
@@ -1,4 +1,4 @@
1
- require File.expand_path('common', File.dirname(__FILE__))
1
+ require_relative 'common'
2
2
  begin
3
3
  require 'prmd/multi_loader/toml'
4
4
  rescue LoadError
@@ -1,4 +1,4 @@
1
- require File.expand_path('common', File.dirname(__FILE__))
1
+ require_relative 'common'
2
2
  begin
3
3
  require 'prmd/multi_loader/yajl'
4
4
  rescue LoadError
@@ -1,4 +1,4 @@
1
- require File.expand_path('common', File.dirname(__FILE__))
1
+ require_relative 'common'
2
2
  require 'prmd/multi_loader/yaml'
3
3
 
4
4
  class PrmdMultiLoaderYamlTest < Minitest::Test
@@ -1,4 +1,4 @@
1
- require File.expand_path('../helpers', File.dirname(__FILE__))
1
+ require_relative '../helpers'
2
2
  require 'prmd/rake_tasks/combine'
3
3
  require 'rake'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../helpers', File.dirname(__FILE__))
1
+ require_relative '../helpers'
2
2
  require 'prmd/rake_tasks/doc'
3
3
  require 'rake'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../helpers', File.dirname(__FILE__))
1
+ require_relative '../helpers'
2
2
  require 'prmd/rake_tasks/verify'
3
3
  require 'rake'
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), 'helpers'))
1
+ require_relative 'helpers'
2
2
 
3
3
  class SchemaTest < Minitest::Test
4
4
  def test_dereference_with_ref
@@ -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.11.9
4
+ version: 0.14.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-05-12 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -50,28 +50,28 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '1.3'
53
+ version: '2.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '1.3'
60
+ version: '2.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: '10.3'
67
+ version: 12.3.3
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: '10.3'
74
+ version: 12.3.3
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: minitest
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -149,9 +149,11 @@ files:
149
149
  - lib/prmd/templates/schemata/helper.erb
150
150
  - lib/prmd/templates/schemata/link.md.erb
151
151
  - lib/prmd/templates/schemata/link_curl_example.md.erb
152
+ - lib/prmd/templates/table_of_contents.erb
152
153
  - lib/prmd/url_generator.rb
153
154
  - lib/prmd/url_generators/generators/default.rb
154
155
  - lib/prmd/url_generators/generators/json.rb
156
+ - lib/prmd/utils.rb
155
157
  - lib/prmd/version.rb
156
158
  - prmd.gemspec
157
159
  - schemas/hyper-schema.json
@@ -189,6 +191,7 @@ files:
189
191
  - test/schemata/input/rake_doc.json
190
192
  - test/schemata/input/rake_verify.json
191
193
  - test/schemata/input/user.json
194
+ - test/utils_test.rb
192
195
  homepage: https://github.com/heroku/prmd
193
196
  licenses:
194
197
  - MIT
@@ -208,8 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
211
  - !ruby/object:Gem::Version
209
212
  version: '0'
210
213
  requirements: []
211
- rubyforge_project:
212
- rubygems_version: 2.5.1
214
+ rubygems_version: 3.1.4
213
215
  signing_key:
214
216
  specification_version: 4
215
217
  summary: JSON Schema tooling
@@ -246,3 +248,4 @@ test_files:
246
248
  - test/schemata/input/rake_doc.json
247
249
  - test/schemata/input/rake_verify.json
248
250
  - test/schemata/input/user.json
251
+ - test/utils_test.rb