prmd 0.7.0 → 0.8.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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CONTRIBUTORS.md +11 -0
  4. data/README.md +21 -4
  5. data/bin/prmd +2 -2
  6. data/docs/schemata.md +4 -0
  7. data/lib/prmd/cli/base.rb +2 -2
  8. data/lib/prmd/cli/combine.rb +2 -2
  9. data/lib/prmd/cli/doc.rb +3 -3
  10. data/lib/prmd/cli/generate.rb +2 -2
  11. data/lib/prmd/cli/render.rb +2 -2
  12. data/lib/prmd/cli/verify.rb +2 -2
  13. data/lib/prmd/cli.rb +6 -6
  14. data/lib/prmd/commands/combine.rb +3 -3
  15. data/lib/prmd/commands/init.rb +2 -2
  16. data/lib/prmd/commands/render.rb +1 -1
  17. data/lib/prmd/commands.rb +4 -4
  18. data/lib/prmd/core/combiner.rb +6 -36
  19. data/lib/prmd/core/generator.rb +1 -1
  20. data/lib/prmd/core/reference_localizer.rb +93 -0
  21. data/lib/prmd/core/renderer.rb +1 -1
  22. data/lib/prmd/link.rb +56 -0
  23. data/lib/prmd/load_schema_file.rb +3 -14
  24. data/lib/prmd/multi_loader/json.rb +19 -0
  25. data/lib/prmd/multi_loader/loader.rb +128 -0
  26. data/lib/prmd/multi_loader/toml.rb +19 -0
  27. data/lib/prmd/multi_loader/yajl.rb +19 -0
  28. data/lib/prmd/multi_loader/yaml.rb +19 -0
  29. data/lib/prmd/multi_loader/yml.rb +2 -0
  30. data/lib/prmd/multi_loader.rb +2 -0
  31. data/lib/prmd/rake_tasks/base.rb +33 -5
  32. data/lib/prmd/rake_tasks/combine.rb +20 -4
  33. data/lib/prmd/rake_tasks/doc.rb +25 -8
  34. data/lib/prmd/rake_tasks/verify.rb +17 -5
  35. data/lib/prmd/schema.rb +24 -1
  36. data/lib/prmd/templates/combine_head.json +3 -3
  37. data/lib/prmd/templates/init_default.json +5 -3
  38. data/lib/prmd/templates/init_resource.json.erb +17 -4
  39. data/lib/prmd/templates/schemata/helper.erb +78 -5
  40. data/lib/prmd/templates/schemata/link.md.erb +9 -3
  41. data/lib/prmd/templates/schemata/link_curl_example.md.erb +8 -5
  42. data/lib/prmd/templates/schemata.md.erb +13 -6
  43. data/lib/prmd/url_generator.rb +2 -2
  44. data/lib/prmd/version.rb +1 -1
  45. data/lib/prmd.rb +8 -7
  46. data/schemas/interagent-hyper-schema.json +4 -1
  47. data/test/commands/render_test.rb +110 -1
  48. data/test/commands/verify_test.rb +2 -2
  49. data/test/core/reference_localizer_test.rb +65 -0
  50. data/test/helpers.rb +117 -3
  51. data/test/link_test.rb +41 -0
  52. data/test/multi_loader/common.rb +35 -0
  53. data/test/multi_loader/json_test.rb +14 -0
  54. data/test/multi_loader/toml_test.rb +18 -0
  55. data/test/multi_loader/yajl_test.rb +18 -0
  56. data/test/multi_loader/yaml_test.rb +14 -0
  57. data/test/rake_tasks/combine_test.rb +38 -0
  58. data/test/rake_tasks/doc_test.rb +31 -0
  59. data/test/rake_tasks/verify_test.rb +23 -0
  60. data/test/schemata/data/test.json +6 -0
  61. data/test/schemata/data/test.toml +4 -0
  62. data/test/schemata/data/test.yaml +3 -0
  63. data/test/schemata/input/rake-meta.json +9 -0
  64. data/test/schemata/input/rake_combine/post.json +100 -0
  65. data/test/schemata/input/rake_combine/user.json +100 -0
  66. data/test/schemata/input/rake_doc.json +223 -0
  67. data/test/schemata/input/rake_verify.json +223 -0
  68. data/test/schemata/input/user.json +10 -1
  69. metadata +47 -3
  70. data/Gemfile.lock +0 -23
@@ -0,0 +1,19 @@
1
+ require_relative 'loader'
2
+ require 'toml'
3
+
4
+ module Prmd #:nodoc:
5
+ module MultiLoader #:nodoc:
6
+ # TOML MultiLoader
7
+ module Toml
8
+ extend Prmd::MultiLoader::Loader
9
+
10
+ # @see (Prmd::MultiLoader::Loader#load_data)
11
+ def self.load_data(data)
12
+ ::TOML.load(data)
13
+ end
14
+
15
+ # register this loader for all .toml files
16
+ extensions '.toml'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'loader'
2
+ require 'yajl'
3
+
4
+ module Prmd #:nodoc:
5
+ module MultiLoader #:nodoc:
6
+ # JSON MultiLoader using Yajl
7
+ module Yajl
8
+ extend Prmd::MultiLoader::Loader
9
+
10
+ # @see (Prmd::MultiLoader::Loader#load_data)
11
+ def self.load_data(data)
12
+ ::Yajl::Parser.parse(data)
13
+ end
14
+
15
+ # register this loader for all .json files
16
+ extensions '.json'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'loader'
2
+ require 'yaml'
3
+
4
+ module Prmd #:nodoc:
5
+ module MultiLoader #:nodoc:
6
+ # YAML MultiLoader
7
+ module Yaml
8
+ extend Prmd::MultiLoader::Loader
9
+
10
+ # @see (Prmd::MultiLoader::Loader#load_data)
11
+ def self.load_data(data)
12
+ ::YAML.load(data)
13
+ end
14
+
15
+ # register this loader for all .yaml and .yml files
16
+ extensions '.yaml', '.yml'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,2 @@
1
+ # alias for yaml
2
+ require_relative 'yaml'
@@ -0,0 +1,2 @@
1
+ require_relative 'multi_loader/json'
2
+ require_relative 'multi_loader/yaml'
@@ -14,20 +14,48 @@ module Prmd
14
14
  attr_accessor :name
15
15
 
16
16
  # Options to pass to command
17
- # @return [Hash<Symbol, Object>] the options passed to the command
17
+ # @return [Hash<Symbol, Object>] the options passed to the Prmd command
18
18
  attr_accessor :options
19
19
 
20
20
  # Creates a new task with name +name+.
21
21
  #
22
- # @param [String, Symbol] name the name of the rake task
23
- def initialize(name)
24
- @name = name
25
- @options = {}
22
+ # @param [Hash<Symbol, Object>] options
23
+ # .option [String, Symbol] name the name of the rake task
24
+ # .option [String, Symbol] options options to pass to the Prmd command
25
+ def initialize(options = {})
26
+ @name = options.fetch(:name, default_name)
27
+ @options = options.fetch(:options) { {} }
26
28
 
27
29
  yield self if block_given?
28
30
 
29
31
  define
30
32
  end
33
+
34
+ private
35
+
36
+ # This method will be removed in the future
37
+ # @api private
38
+ def legacy_parameters(*args)
39
+ if args.size == 0
40
+ return {}
41
+ else
42
+ arg, = *args
43
+ case arg
44
+ when String, Symbol
45
+ warn "#{self.class}.new(name) has been deprecated, use .new(name: name) instead"
46
+ return { name: arg }
47
+ else
48
+ return arg
49
+ end
50
+ end
51
+ end
52
+
53
+ # Default name of the rake task
54
+ #
55
+ # @return [Symbol]
56
+ def default_name
57
+ :base
58
+ end
31
59
  end
32
60
  end
33
61
  end
@@ -24,10 +24,26 @@ module Prmd
24
24
 
25
25
  # Creates a new task with name +name+.
26
26
  #
27
- # @param [String, Symbol] name the name of the rake task
28
- def initialize(name = :combine)
29
- @paths = []
30
- super
27
+ # @overload initialize(name)
28
+ # @param [String]
29
+ # @overload initialize(options)
30
+ # @param [Hash<Symbol, Object>] options
31
+ # .option [String] output_file
32
+ # .option [Array<String>] paths
33
+ def initialize(*args, &block)
34
+ options = legacy_parameters(*args)
35
+ @paths = options.fetch(:paths) { [] }
36
+ @output_file = options[:output_file]
37
+ super options, &block
38
+ end
39
+
40
+ private
41
+
42
+ # Default name of the rake task
43
+ #
44
+ # @return [Symbol]
45
+ def default_name
46
+ :combine
31
47
  end
32
48
 
33
49
  protected
@@ -1,6 +1,7 @@
1
1
  require 'prmd/commands/render'
2
2
  require 'prmd/rake_tasks/base'
3
3
  require 'prmd/load_schema_file'
4
+ require 'prmd/url_generator'
4
5
  require 'prmd/template'
5
6
  require 'prmd/schema'
6
7
 
@@ -15,21 +16,33 @@ module Prmd
15
16
  # t.files = { 'schema/api.json' => 'schema/api.md' }
16
17
  # end
17
18
  class Doc < Base
18
- # Schema files that should be verified
19
+ # Schema files that should be rendered
19
20
  # @return [Array<String>, Hash<String, String>] list of files
20
21
  attr_accessor :files
21
22
 
22
23
  # Creates a new task with name +name+.
23
24
  #
24
- # @param [String, Symbol] name the name of the rake task
25
- def initialize(name = :doc, &block)
26
- @files = []
27
- super name, &block
25
+ # @overload initialize(name)
26
+ # @param [String]
27
+ # @overload initialize(options)
28
+ # @param [Hash<Symbol, Object>] options
29
+ # .option [Array<String>, Hash<String, String>] files schema files
30
+ def initialize(*args, &block)
31
+ options = legacy_parameters(*args)
32
+ @files = options.fetch(:files) { [] }
33
+ super options, &block
28
34
  @options[:template] ||= Prmd::Template.template_dirname
29
35
  end
30
36
 
31
37
  private
32
38
 
39
+ # Default name of the rake task
40
+ #
41
+ # @return [Symbol]
42
+ def default_name
43
+ :doc
44
+ end
45
+
33
46
  # Render file to markdown
34
47
  #
35
48
  # @param [String] filename
@@ -40,13 +53,17 @@ module Prmd
40
53
  Prmd.render(schema, options)
41
54
  end
42
55
 
56
+ # Render +infile+ to +outfile+
57
+ #
43
58
  # @param [String] infile
44
59
  # @param [String] outfile
45
60
  # @return [void]
46
61
  def render_to_file(infile, outfile)
47
62
  result = render_file(infile)
48
- File.open(outfile, 'w') do |file|
49
- file.write(result)
63
+ if outfile
64
+ File.open(outfile, 'w') do |file|
65
+ file.write(result)
66
+ end
50
67
  end
51
68
  end
52
69
 
@@ -55,7 +72,7 @@ module Prmd
55
72
  # Defines the rake task
56
73
  # @return [void]
57
74
  def define
58
- desc 'Verifying schemas' unless Rake.application.last_comment
75
+ desc 'Generate documentation' unless Rake.application.last_comment
59
76
  task(name) do
60
77
  if files.is_a?(Hash)
61
78
  files.each do |infile, outfile|
@@ -19,14 +19,26 @@ module Prmd
19
19
 
20
20
  # Creates a new task with name +name+.
21
21
  #
22
- # @param [String, Symbol] name the name of the rake task
23
- def initialize(name = :verify)
24
- @files = []
25
- super
22
+ # @overload initialize(name)
23
+ # @param [String]
24
+ # @overload initialize(options)
25
+ # @param [Hash<Symbol, Object>] options
26
+ # .option [Array<String>] files schema files to verify
27
+ def initialize(*args, &block)
28
+ options = legacy_parameters(*args)
29
+ @files = options.fetch(:files) { [] }
30
+ super options, &block
26
31
  end
27
32
 
28
33
  private
29
34
 
35
+ # Default name of the rake task
36
+ #
37
+ # @return [Symbol]
38
+ def default_name
39
+ :verify
40
+ end
41
+
30
42
  # Defines the rake task
31
43
  #
32
44
  # @param [String] filename
@@ -46,7 +58,7 @@ module Prmd
46
58
  # Defines the rake task
47
59
  # @return [void]
48
60
  def define
49
- desc 'Verifying schemas' unless Rake.application.last_comment
61
+ desc 'Verify schemas' unless Rake.application.last_comment
50
62
  task(name) do
51
63
  all_errors = []
52
64
  files.each do |filename|
data/lib/prmd/schema.rb CHANGED
@@ -3,6 +3,21 @@ require 'yaml'
3
3
 
4
4
  # :nodoc:
5
5
  module Prmd
6
+ # @api private
7
+ DefaultExamples = {
8
+ "boolean" => true,
9
+ "integer" => 42,
10
+ "number" => 42.0,
11
+ "string" => "example",
12
+
13
+ "date-time" => "2015-01-01T12:00:00Z",
14
+ "email" => "username@example.com",
15
+ "hostname" => "example.com",
16
+ "ipv4" => "192.0.2.1",
17
+ "ipv6" => "2001:DB8::1",
18
+ "uuid" => "01234567-89ab-cdef-0123-456789abcdef",
19
+ }
20
+
6
21
  # Schema object
7
22
  class Schema
8
23
  # @return [Hash] data
@@ -103,10 +118,18 @@ module Prmd
103
118
  elsif value.key?('items') # array of objects
104
119
  _, items = dereference(value['items'])
105
120
  if value['items'].key?('example')
106
- [items['example']]
121
+ if items["example"].is_a?(Array)
122
+ items["example"]
123
+ else
124
+ [items['example']]
125
+ end
107
126
  else
108
127
  [schema_example(items)]
109
128
  end
129
+ elsif DefaultExamples.key?(value["format"])
130
+ DefaultExamples[value["format"]]
131
+ elsif DefaultExamples.key?(value["type"][0])
132
+ DefaultExamples[value["type"][0]]
110
133
  end
111
134
  end
112
135
 
@@ -1,6 +1,6 @@
1
1
  {
2
- "$schema": "http://json-schema.org/draft-04/hyper-schema",
2
+ "$schema": "http://interagent.github.io/interagent-hyper-schema",
3
+ "type": ["object"],
3
4
  "definitions": {},
4
- "properties": {},
5
- "type": ["object"]
5
+ "properties": {}
6
6
  }
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-04/hyper-schema",
3
3
  "title": "FIXME",
4
- "definitions": {},
5
4
  "description": "FIXME",
5
+ "stability": "prototype",
6
+ "strictProperties": true,
7
+ "type": ["object"],
8
+ "definitions": {},
6
9
  "links": [],
7
- "properties": {},
8
- "type": ["object"]
10
+ "properties": {}
9
11
  }
@@ -4,22 +4,32 @@
4
4
  "definitions": {
5
5
  "id": {
6
6
  "description": "unique identifier of <%= resource %>",
7
- "example": "01234567-89ab-cdef-0123-456789abcdef",
7
+ "readOnly": true,
8
8
  "format": "uuid",
9
9
  "type": ["string"]
10
10
  },
11
+ "name": {
12
+ "description": "unique name of <%= resource %>",
13
+ "readOnly": true,
14
+ "type": ["string"]
15
+ },
11
16
  "identity": {
12
- "$ref": "/schemata/<%= resource %>#/definitions/id"
17
+ "anyOf": [
18
+ {
19
+ "$ref": "/schemata/<%= resource %>#/definitions/id"
20
+ },
21
+ {
22
+ "$ref": "/schemata/<%= resource %>#/definitions/name"
23
+ }
24
+ ]
13
25
  },
14
26
  "created_at": {
15
27
  "description": "when <%= resource %> was created",
16
- "example": "2012-01-01T12:00:00Z",
17
28
  "format": "date-time",
18
29
  "type": ["string"]
19
30
  },
20
31
  "updated_at": {
21
32
  "description": "when <%= resource %> was updated",
22
- "example": "2012-01-01T12:00:00Z",
23
33
  "format": "date-time",
24
34
  "type": ["string"]
25
35
  }
@@ -31,6 +41,9 @@
31
41
  "id": {
32
42
  "$ref": "/schemata/<%= resource %>#/definitions/id"
33
43
  },
44
+ "name": {
45
+ "$ref": "/schemata/<%= resource %>#/definitions/name"
46
+ },
34
47
  "updated_at": {
35
48
  "$ref": "/schemata/<%= resource %>#/definitions/updated_at"
36
49
  }
@@ -2,6 +2,8 @@
2
2
  def extract_attributes(schema, properties)
3
3
  attributes = []
4
4
 
5
+ _, properties = schema.dereference(properties)
6
+
5
7
  properties.each do |key, value|
6
8
  # found a reference to another element:
7
9
  _, value = schema.dereference(value)
@@ -42,21 +44,74 @@
42
44
  attribute[0] = "#{key}:#{attribute[0]}"
43
45
  end
44
46
  attributes.concat(nested)
47
+
45
48
  # found an array with nested objects
46
- elsif value['items'] && value['items']['properties']
47
- nested = extract_attributes(schema, value['items']['properties'])
48
- nested.each do |attribute|
49
- attribute[0] = "#{key}/#{attribute[0]}"
49
+ elsif value['items']
50
+ if value['items']['properties']
51
+ nested = extract_attributes(schema, value['items']['properties'])
52
+ nested.each do |attribute|
53
+ attribute[0] = "#{key}/#{attribute[0]}"
54
+ end
55
+ attributes.concat(nested)
50
56
  end
51
- attributes.concat(nested)
57
+ if value['items']['oneOf']
58
+ value['items']['oneOf'].each_with_index do |oneof, index|
59
+ ref, oneof_definition = schema.dereference(oneof)
60
+ oneof_name = ref ? ref.split('/').last : index
61
+ nested = extract_attributes(schema, oneof_definition['properties'])
62
+ nested.each do |attribute|
63
+ attribute[0] = "#{key}/[#{oneof_name.upcase}].#{attribute[0]}"
64
+ end
65
+ attributes.concat(nested)
66
+ end
67
+ end
68
+
52
69
  # just a regular attribute
53
70
  else
54
71
  attributes << build_attribute(schema, key, value)
55
72
  end
56
73
  end
74
+ attributes.map! { |key, type, description, example|
75
+ if example.nil? && Prmd::DefaultExamples.key?(type)
76
+ example = "`%s`" % Prmd::DefaultExamples[type].to_json
77
+ end
78
+ [key, type, description, example]
79
+ }
57
80
  return attributes
58
81
  end
59
82
 
83
+ def extract_schemata_refs(schema, properties)
84
+ ret = []
85
+ properties.each do |_, value|
86
+ ref, value = schema.dereference(value)
87
+ if value['properties']
88
+ refs = extract_schemata_refs(schema, value['properties'])
89
+ elsif value['items'] && value['items']['properties']
90
+ refs = extract_schemata_refs(schema, value['items']['properties'])
91
+ else
92
+ refs = [ref]
93
+ end
94
+ if value.has_key?('type') && value['type'].include?('null') && (value.has_key?('items') || value.has_key?('properties'))
95
+ # A nullable object usually isn't a reference to another schema. It's
96
+ # either not a reference at all, or it's a reference within the same
97
+ # schema. Instead, the definition of the nullable object might contain
98
+ # references to specific properties.
99
+ #
100
+ # If all properties refer to the same schema, we'll use that as the
101
+ # reference. This might even overwrite an actual, intra-schema
102
+ # reference.
103
+
104
+ l = refs.map {|v| v && v.split("/")[0..2]}
105
+ if l.uniq.size == 1 && l[0] != nil
106
+ ref = l[0].join("/")
107
+ end
108
+ ret << ref
109
+ end
110
+ ret.concat(refs)
111
+ end
112
+ ret
113
+ end
114
+
60
115
  def build_attribute(schema, key, value)
61
116
  description = value['description'] || ""
62
117
  if value['default']
@@ -85,6 +140,24 @@
85
140
  description += "<br/> **pattern:** <code>#{value['pattern'].gsub /\|/, '&#124;'}</code>"
86
141
  end
87
142
 
143
+ if value['minLength'] || value['maxLength']
144
+ description += "<br/> **Length:** `"
145
+ if value['minLength']
146
+ description += "#{value['minLength'].to_json}"
147
+ end
148
+ unless value['minLength'] == value['maxLength']
149
+ if value['maxLength']
150
+ unless value['minLength']
151
+ description += "0"
152
+ end
153
+ description += "..#{value['maxLength'].to_json}"
154
+ else
155
+ description += "..∞"
156
+ end
157
+ end
158
+ description += "`"
159
+ end
160
+
88
161
  if value.has_key?('example')
89
162
  example = if value['example'].is_a?(Hash) && value['example'].has_key?('oneOf')
90
163
  value['example']['oneOf'].map { |e| "`#{e.to_json}`" }.join(" or ")
@@ -4,6 +4,7 @@
4
4
  link_schema_properties_template = Prmd::Template.load_template('link_schema_properties.md.erb', options[:template])
5
5
  -%>
6
6
  ### <%= title %> <%= link['title'] %>
7
+
7
8
  <%= link['description'] %>
8
9
 
9
10
  ```
@@ -12,22 +13,23 @@
12
13
 
13
14
  <%- if link.has_key?('schema') && link['schema'].has_key?('properties') %>
14
15
  <%-
15
- required, optional = link['schema']['properties'].partition do |k, v|
16
- (link['schema']['required'] || []).include?(k)
17
- end.map { |partition| Hash[partition] }
16
+ required, optional = Prmd::Link.new(link).required_and_optional_parameters
18
17
  %>
19
18
  <%- unless required.empty? %>
20
19
  #### Required Parameters
20
+
21
21
  <%= link_schema_properties_template.result(params: required, schema: schema, options: options) %>
22
22
 
23
23
  <%- end %>
24
24
  <%- unless optional.empty? %>
25
25
  #### Optional Parameters
26
+
26
27
  <%= link_schema_properties_template.result(params: optional, schema: schema, options: options) %>
27
28
  <%- end %>
28
29
  <%- end %>
29
30
 
30
31
  #### Curl Example
32
+
31
33
  <%=
32
34
  curl_options = options.dup
33
35
  http_header = link['http_header'] || {}
@@ -43,6 +45,7 @@
43
45
  %>
44
46
 
45
47
  #### Response Example
48
+
46
49
  ```
47
50
  <%- if response_example %>
48
51
  <%= response_example['head'] %>
@@ -58,6 +61,8 @@ HTTP/1.1 <%=
58
61
  end %>
59
62
  <%- end %>
60
63
  ```
64
+
65
+ <%- if response_example || link['rel'] != 'empty' %>
61
66
  ```json
62
67
  <%- if response_example %>
63
68
  <%= response_example['body'] %>
@@ -72,3 +77,4 @@ HTTP/1.1 <%=
72
77
  <%- end %>
73
78
  <%- end %>
74
79
  ```
80
+ <%- end %>
@@ -1,13 +1,13 @@
1
1
  ```bash
2
2
  <%-
3
- data = {}
3
+ data = nil
4
4
  path = path.gsub(/{([^}]*)}/) {|match| '$' + match.gsub(/[{}]/, '').upcase}
5
5
  get_params = []
6
6
 
7
7
  if link.has_key?('schema')
8
- data.merge!(schema.schema_example(link['schema']))
8
+ data = schema.schema_example(link['schema'])
9
9
 
10
- if link['method'].upcase == 'GET' && !data.empty?
10
+ if link['method'].upcase == 'GET' && !data.nil?
11
11
  get_params << Prmd::UrlGenerator.new({schema: schema, link: link, options: options}).url_params
12
12
  end
13
13
  end
@@ -16,14 +16,17 @@
16
16
  options[:http_header] = { 'Content-Type' => options[:content_type] }.merge(options[:http_header])
17
17
  end
18
18
  %>
19
+ <%- if link['method'].upcase != 'GET' %>
19
20
  $ curl -n -X <%= link['method'] %> <%= schema.href %><%= path -%><%- unless options[:http_header].empty? %> \<%- end %>
21
+ <%- else %>
22
+ $ curl -n <%= schema.href %><%= path -%><%- unless options[:http_header].empty? %> \<%- end %>
23
+ <%- end %>
20
24
  <%- options[:http_header].each do |key, value| %>
21
25
  -H "<%= key %>: <%= value %>" \
22
26
  <%- end %>
23
- <%- if !data.empty? && link['method'].upcase != 'GET' %> \
27
+ <%- if !data.nil? && link['method'].upcase != 'GET' %> \
24
28
  -d '<%= JSON.pretty_generate(data) %>'
25
29
  <%- elsif !get_params.empty? && link['method'].upcase == 'GET' %> -G \
26
30
  -d <%= get_params.join(" \\\n -d ") %>
27
31
  <%- end %>
28
-
29
32
  ```
@@ -1,6 +1,4 @@
1
1
  <%-
2
- return unless schemata.has_key?('links') && !schemata['links'].empty?
3
-
4
2
  Prmd::Template.render('schemata/helper.erb', options[:template], {
5
3
  options: options,
6
4
  resource: resource,
@@ -11,19 +9,28 @@
11
9
  title = schemata['title'].split(' - ', 2).last
12
10
  -%>
13
11
  <%- unless options[:doc][:disable_title_and_description] %>
14
- ## <%= title %>
12
+ ## <a name="resource-<%= resource %>"></a><%= title %>
13
+
15
14
  <%= schemata['description'] %>
16
15
  <%- end -%>
17
16
 
18
17
  <%- if schemata['properties'] && !schemata['properties'].empty? %>
19
18
  ### Attributes
19
+
20
20
  | Name | Type | Description | Example |
21
21
  | ------- | ------- | ------- | ------- |
22
- <%- extract_attributes(schema, schemata['properties']).each do |(key, type, description, example)| %>
23
- | **<%= key %>** | *<%= type %>* | <%= description %> | <%= example %> |
22
+ <%- refs = extract_schemata_refs(schema, schemata['properties']).map {|v| v && v.split("/")} %>
23
+ <%- extract_attributes(schema, schemata['properties']).each_with_index do |(key, type, description, example), i| %>
24
+ <%- if refs[i] && refs[i][1] == "definitions" && refs[i][2] != resource %>
25
+ <%- name = '[%s](#%s)' % [key, 'resource-' + refs[i][2]] %>
26
+ <%- else %>
27
+ <%- name = key %>
24
28
  <%- end %>
29
+ | **<%= name %>** | *<%= type %>* | <%= description %> | <%= example %> |
30
+ <%- end %>
31
+
25
32
  <%- end %>
26
- <%- schemata['links'].each do |link, datum| %>
33
+ <%- (schemata['links'] || []).each do |link, datum| %>
27
34
  <%=
28
35
  Prmd::Template.render('schemata/link.md.erb', options[:template], {
29
36
  options: options,
@@ -1,5 +1,5 @@
1
- require 'prmd/url_generators/generators/default'
2
- require 'prmd/url_generators/generators/json'
1
+ require_relative 'url_generators/generators/default'
2
+ require_relative 'url_generators/generators/json'
3
3
 
4
4
  # :nodoc:
5
5
  module Prmd
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, 7, 0, nil
5
+ MAJOR, MINOR, TEENY, PATCH = 0, 8, 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
@@ -1,7 +1,8 @@
1
- require 'prmd/version'
2
- require 'prmd/load_schema_file'
3
- require 'prmd/commands'
4
- require 'prmd/schema'
5
- require 'prmd/template'
6
- require 'prmd/url_generator'
7
- require 'prmd/hash_helpers'
1
+ require_relative 'prmd/version'
2
+ require_relative 'prmd/load_schema_file'
3
+ require_relative 'prmd/commands'
4
+ require_relative 'prmd/schema'
5
+ require_relative 'prmd/link'
6
+ require_relative 'prmd/template'
7
+ require_relative 'prmd/url_generator'
8
+ require_relative 'prmd/hash_helpers'