jdoc 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32fedb39817ea5f19c6fdd4f058715150348b50d
4
- data.tar.gz: 046bbaaf9e08fb214ee5eca23c80c3f73ab34ebf
3
+ metadata.gz: 28bc94f091b81a3e04e106f675c00f8940275841
4
+ data.tar.gz: 8402b0802f2e5a2a59645b9d5140843964725374
5
5
  SHA512:
6
- metadata.gz: f67afb16cbcdea69460fd56253d371b84b84aacb88bdea7115331c8fd9e9b0f4633499cef1ed853f0691de56d569eb9834bc869b2211db05051b7a7c80f2515a
7
- data.tar.gz: 521e04c49a756ae3e3e86058b0c070c49b67f3be906fd21adc8219516277352e1e81a808b352c92c75f39a7c8325c938106b3c922f0e6f1b218f1d7455f3cf5c
6
+ metadata.gz: c5c1fe253da35df82c05ee7628ddeeebcb1e18dccf045006ddc75335304c70352c637480528df9401093c9d8a3f7e8cc7ea3ff86ccdef39673c2ba5ad79c00cd
7
+ data.tar.gz: 6a9df487e28224d36af6b1092f9c92c707376df84fa61640c45a96311af64e217fc4e0449080ba173e623c27c647d7acd78b610f2f2f6f690bb1fc5d5429bdb2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.2
2
+ * Add generator options to change template
3
+ * Add request parameters for each endpoint
4
+
1
5
  ## 0.3.1
2
6
  * Add error handling for ExampleNotFound
3
7
 
@@ -26,7 +26,7 @@ An app is a program to be deployed.
26
26
  * unique name of app
27
27
  * Example: `"example"`
28
28
  * Type: string
29
- * Patern: `(?-mix:^[a-z][a-z0-9-]{3,50}$)`
29
+ * Pattern: `(?-mix:^[a-z][a-z0-9-]{3,50}$)`
30
30
  * private
31
31
  * true if this resource is private use
32
32
  * Example: `false`
@@ -43,6 +43,12 @@ An app is a program to be deployed.
43
43
  ### POST /apps
44
44
  Create a new app.
45
45
 
46
+ * name
47
+ * unique name of app
48
+ * Example: `"example"`
49
+ * Type: string
50
+ * Pattern: `(?-mix:^[a-z][a-z0-9-]{3,50}$)`
51
+
46
52
  ```
47
53
  POST /apps HTTP/1.1
48
54
  Content-Type: application/json
@@ -143,6 +149,12 @@ Content-Type: application/json
143
149
  ### PATCH /apps/:id
144
150
  Update an existing app.
145
151
 
152
+ * name
153
+ * unique name of app
154
+ * Example: `"example"`
155
+ * Type: string
156
+ * Pattern: `(?-mix:^[a-z][a-z0-9-]{3,50}$)`
157
+
146
158
  ```
147
159
  PATCH /apps/01234567-89ab-cdef-0123-456789abcdef HTTP/1.1
148
160
  Content-Type: application/json
@@ -175,6 +187,11 @@ Content-Type: application/json
175
187
  ### POST /apps/:id/files
176
188
  Upload an attachment file for an app
177
189
 
190
+ * file
191
+ * an attachment of app
192
+ * Example: `"... contents of file ..."`
193
+ * Type: string
194
+
178
195
  ```
179
196
  POST /apps/01234567-89ab-cdef-0123-456789abcdef/files HTTP/1.1
180
197
  Content-Type: multipart/form-data; boundary=---BoundaryX
@@ -1,42 +1,7 @@
1
1
  module Jdoc
2
2
  class Generator
3
- HTML_TEMPLATE_PATH = File.expand_path("../../../template.html.erb", __FILE__)
4
- MARKDOWN_TEMPLATE_PATH = File.expand_path("../../../template.md.erb", __FILE__)
5
-
6
- class << self
7
- # @return [Erubis::Eruby]
8
- def markdown_renderer
9
- @markdown_renderer ||= Erubis::Eruby.new(markdown_template)
10
- end
11
-
12
- # @return [Erubis::Eruby]
13
- def html_renderer
14
- @html_renderer ||= Erubis::Eruby.new(html_template)
15
- end
16
-
17
- def redcarpet
18
- @redcarpet ||= Redcarpet::Markdown.new(
19
- Redcarpet::Render::HTML.new(
20
- filter_html: true,
21
- hard_wrap: true,
22
- with_toc_data: true,
23
- ),
24
- autolink: true,
25
- fenced_code_blocks: true,
26
- no_intra_emphasis: true,
27
- )
28
- end
29
-
30
- # @return [String] ERB template
31
- def markdown_template
32
- File.read(MARKDOWN_TEMPLATE_PATH)
33
- end
34
-
35
- # @return [String] ERB template
36
- def html_template
37
- File.read(HTML_TEMPLATE_PATH)
38
- end
39
- end
3
+ DEFAULT_HTML_TEMPLATE_PATH = File.expand_path("../../../template.html.erb", __FILE__)
4
+ DEFAULT_MARKDOWN_TEMPLATE_PATH = File.expand_path("../../../template.md.erb", __FILE__)
40
5
 
41
6
  # Utility wrapper for Jdoc::Generator#call
42
7
  # @return [String]
@@ -46,21 +11,26 @@ module Jdoc
46
11
 
47
12
  # @param schema [Hash] JSON Schema represented as a Hash
48
13
  # @param html [true, false] Pass true to render HTML docs
49
- def initialize(schema, html: false)
14
+ # @param html_template_path [String] Path to ERB template to render HTML
15
+ # @param Markdown_template_path [String] Path to ERB template to render Markdown
16
+ def initialize(schema, html: false, html_template_path: nil, markdown_template_path: nil)
50
17
  @raw_schema = schema
51
18
  @html = html
19
+ @html_template_path = html_template_path
20
+ @markdown_template_path = markdown_template_path
52
21
  end
53
22
 
54
23
  # Generates Markdown or HTML documentation from JSON schema
55
24
  # @note Add some fix to adapt to GitHub anchor style
56
- # @return [String]
25
+ # @return [String] Generated text
57
26
  def call
58
- result = self.class.markdown_renderer.result(schema: schema)
27
+ markdown = markdown_renderer.result(schema: schema)
59
28
  if @html
60
- result = self.class.html_renderer.result(body: self.class.redcarpet.render(result))
61
- result.gsub(/id="(.+)"/) {|text| text.tr("/:", "") }
29
+ html = markdown_parser.render(markdown)
30
+ html = html_renderer.result(body: html)
31
+ html.gsub(/id="(.+)"/) {|text| text.tr("/:", "") }
62
32
  else
63
- result
33
+ markdown
64
34
  end
65
35
  rescue Jdoc::Link::ExampleNotFound => exception
66
36
  abort("Error: #{exception.to_s}")
@@ -68,10 +38,53 @@ module Jdoc
68
38
 
69
39
  private
70
40
 
41
+ # @return [Erubis::Eruby] Renderer to render HTML that takes HTML string
42
+ def html_renderer
43
+ Erubis::Eruby.new(html_template)
44
+ end
45
+
46
+ # @returns [String] Path to ERB template to render HTML
47
+ def html_template_path
48
+ @html_template_path || DEFAULT_HTML_TEMPLATE_PATH
49
+ end
50
+
51
+ def html_template
52
+ File.read(html_template_path)
53
+ end
54
+
55
+ # @return [Redcarpet::Markdown] Markdown parser to convert Markdown into HTML
56
+ def markdown_parser
57
+ Redcarpet::Markdown.new(
58
+ Redcarpet::Render::HTML.new(
59
+ filter_html: true,
60
+ hard_wrap: true,
61
+ with_toc_data: true,
62
+ ),
63
+ autolink: true,
64
+ fenced_code_blocks: true,
65
+ no_intra_emphasis: true,
66
+ )
67
+ end
68
+
69
+ # @return [Erubis::Eruby] Renderer to render Markdown that takes schema data
70
+ def markdown_renderer
71
+ Erubis::Eruby.new(markdown_template)
72
+ end
73
+
74
+ # @return [String] Content of specified Markdown template
75
+ def markdown_template
76
+ File.read(markdown_template_path)
77
+ end
78
+
79
+ # @return [String] Path to ERB template to render Markdown
80
+ def markdown_template_path
81
+ @markdown_template_path || DEFAULT_MARKDOWN_TEMPLATE_PATH
82
+ end
83
+
71
84
  # @return [Jdoc::Schema]
72
85
  # @raise [JsonSchema::SchemaError] Raises if given invalid JSON Schema
73
86
  def schema
74
- @schema ||= Jdoc::Schema.new(@raw_schema)
87
+ Jdoc::Schema.new(@raw_schema)
75
88
  end
76
89
  end
77
90
  end
data/lib/jdoc/link.rb CHANGED
@@ -122,7 +122,7 @@ module Jdoc
122
122
  # @return [Hash] Example request parameters for this endpoint
123
123
  def request_parameters
124
124
  @request_parameters ||= begin
125
- if has_schema_in_link?
125
+ if request_schema
126
126
  RequestGenerator.call(request_schema.properties)
127
127
  else
128
128
  {}
@@ -130,6 +130,19 @@ module Jdoc
130
130
  end
131
131
  end
132
132
 
133
+ # @return [Array<Jdoc::Property>] Properties defined in this link's schema property.
134
+ def request_properties
135
+ @request_properties ||= begin
136
+ if request_schema
137
+ request_schema.properties.map do |name, schema|
138
+ Property.new(name: name, schema: schema)
139
+ end
140
+ else
141
+ []
142
+ end
143
+ end
144
+ end
145
+
133
146
  # @return [true, false] True if this endpoint must have request body
134
147
  def has_request_body?
135
148
  ["PATCH", "POST", "PUT"].include?(method)
@@ -166,7 +179,7 @@ module Jdoc
166
179
 
167
180
  # @return [JsonSchema::Schema] Request schema for this link
168
181
  def request_schema
169
- @raw_link.schema || @raw_link.parent
182
+ @raw_link.schema
170
183
  end
171
184
 
172
185
  # @return [Json::Link::Resource]
@@ -188,11 +201,6 @@ module Jdoc
188
201
  end
189
202
  end
190
203
 
191
- # @return [true, false] True if a given link has a schema property
192
- def has_schema_in_link?
193
- !!@raw_link.schema
194
- end
195
-
196
204
  # @return [true, false] True if response is intended to be list data
197
205
  def has_list_data?
198
206
  @raw_link.rel == "instances"
data/lib/jdoc/property.rb CHANGED
@@ -15,7 +15,7 @@ module Jdoc
15
15
  Example: example,
16
16
  Type: type,
17
17
  Format: format,
18
- Patern: pattern,
18
+ Pattern: pattern,
19
19
  ReadOnly: read_only,
20
20
  }.reject {|key, value| value.nil? }
21
21
  end
data/lib/jdoc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jdoc
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/template.md.erb CHANGED
@@ -26,6 +26,18 @@
26
26
  ### <%= link.endpoint %>
27
27
  <%= link.description %>
28
28
 
29
+ <% if link.request_schema %>
30
+ <% link.request_properties.each do |property| %>
31
+ * <%= property.name %>
32
+ <% if property.description %>
33
+ * <%= property.description %>
34
+ <% end %>
35
+ <% property.options.each do |key, value| %>
36
+ * <%= key %>: <%= value %>
37
+ <% end %>
38
+ <% end %>
39
+
40
+ <% end %>
29
41
  ```
30
42
  <%= link.method %> <%= link.example_path %><%= link.query_string %> HTTP/1.1
31
43
  <%= "Content-Type: #{link.content_type}\n" if link.has_request_body? -%>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jdoc
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
  - Ryo Nakamura