json-schema-docs 0.1.1 → 0.2.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 (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -9
  3. data/Rakefile +1 -8
  4. data/json-schema-docs.gemspec +11 -0
  5. data/lib/json-schema-docs.rb +1 -0
  6. data/lib/json-schema-docs/configuration.rb +25 -2
  7. data/lib/json-schema-docs/generator.rb +93 -21
  8. data/lib/json-schema-docs/helpers.rb +17 -1
  9. data/lib/json-schema-docs/landing_pages/index.md +7 -0
  10. data/lib/json-schema-docs/layouts/assets/_sass/_content.scss +518 -0
  11. data/lib/json-schema-docs/layouts/assets/_sass/_header.scss +59 -0
  12. data/lib/json-schema-docs/layouts/assets/_sass/_links.scss +33 -0
  13. data/lib/json-schema-docs/layouts/assets/_sass/_normalize.scss +127 -0
  14. data/lib/json-schema-docs/layouts/assets/_sass/_resource.scss +23 -0
  15. data/lib/json-schema-docs/layouts/assets/_sass/_sidebar.scss +75 -0
  16. data/lib/json-schema-docs/layouts/assets/css/screen.scss +32 -0
  17. data/lib/json-schema-docs/layouts/default.html.erb +43 -0
  18. data/lib/json-schema-docs/layouts/includes/{example.md.erb → curl_example.html.erb} +3 -3
  19. data/lib/json-schema-docs/layouts/includes/resource_example.html.erb +3 -0
  20. data/lib/json-schema-docs/layouts/includes/{response.md.erb → response.html.erb} +5 -5
  21. data/lib/json-schema-docs/layouts/includes/sidebar.html.erb +31 -0
  22. data/lib/json-schema-docs/layouts/links.html.erb +73 -0
  23. data/lib/json-schema-docs/layouts/resource.html.erb +42 -0
  24. data/lib/json-schema-docs/parser.rb +12 -6
  25. data/lib/json-schema-docs/renderer.rb +67 -0
  26. data/lib/json-schema-docs/version.rb +1 -1
  27. metadata +144 -6
  28. data/lib/json-schema-docs/layouts/endpoint.md.erb +0 -39
  29. data/lib/json-schema-docs/layouts/object.md.erb +0 -17
@@ -0,0 +1,73 @@
1
+ <h1 class="resource-name"><a name="resource-<%= schemata['title'].downcase %>"><%= schemata['title'] %></a></h1>
2
+
3
+ <% schemata['links'].each do |link, datum| %>
4
+
5
+ <h2 class="link-name"><a name="link-<%= link['method'] %>-<%= link['title'] %>"><%= link['title'] %></a></h2>
6
+
7
+ <p class=link-description">
8
+ <%= markdownify.(schemata['description']) %>
9
+ </p>
10
+
11
+ <pre>
12
+ <%= link['method'] %> <%= link['link_path'] %>
13
+ </pre>
14
+
15
+ <div class="link-copy-wrapper">
16
+ <div class="link-properties">
17
+ <% if (link['required_properties'] && !link['required_properties'].empty?) || (link['optional_properties'] && !link['optional_properties'].empty?) %>
18
+ <h2 class="link-properties-title">Arguments</h2>
19
+ <ul class="link-properties-list">
20
+ <%- link['required_properties'].each do |property_ref| -%>
21
+ <li class="link-properties-item">
22
+ <h3 class="link-properties-item-label">
23
+ <span class="link-properties-item-name">
24
+ <%= property_ref[:name] %>
25
+ </span>
26
+ <span class="link-properties-item-type">
27
+ <%= property_ref[:type] %>
28
+ </span>
29
+ <span class="link-properties-required">
30
+ Required
31
+ </span>
32
+ </h3>
33
+ <div class="link-properties-item-description-and-children">
34
+ <p class="link-properties-item-description">
35
+ <span><%= markdownify.(property_ref[:description]) %></span>
36
+ </p>
37
+ </div>
38
+ </li>
39
+ <%- end -%>
40
+ <%- link['optional_properties'].each do |property_ref| -%>
41
+ <li class="link-properties-item">
42
+ <h3 class="link-properties-item-label">
43
+ <span class="link-properties-item-name">
44
+ <%= property_ref[:name] %>
45
+ </span>
46
+ <span class="link-properties-item-type">
47
+ <%= property_ref[:type] %>
48
+ </span>
49
+ <span class="link-properties-optional">
50
+ Optional
51
+ </span>
52
+ </h3>
53
+ <div class="link-properties-item-description-and-children">
54
+ <p class="link-properties-item-description">
55
+ <span><%= markdownify.(property_ref[:description]) %></span>
56
+ </p>
57
+ </div>
58
+ </li>
59
+ <%- end -%>
60
+ </ul>
61
+ <%- end -%>
62
+ </div>
63
+
64
+ <div class="link-example">
65
+
66
+ <%= include.('curl_example.html.erb', example: link['example']) %>
67
+
68
+ <%= include.('response.html.erb', response: link['response']) %>
69
+
70
+ </div>
71
+ </div>
72
+
73
+ <%- end -%>
@@ -0,0 +1,42 @@
1
+ <h1 class="resource-name"><a name="resource-<%= schemata['title'].downcase %>"><%= schemata['title'] %></a></h1>
2
+
3
+ <% if schemata['stability'] && !schemata['stability'].empty? %>
4
+ <p class="stability-info">Stability: <code class="stability-type"><%= schemata['stability'] %></code></p>
5
+ <% end %>
6
+
7
+ <p class=resource-description">
8
+ <%= markdownify.(schemata['description']) %>
9
+ </p>
10
+
11
+ <% if schemata['property_refs'] && !schemata['property_refs'].empty? %>
12
+
13
+ <div class="resource-copy-wrapper">
14
+ <div class="resource-attributes">
15
+ <h2 class="resource-attributes-title">Attributes</h2>
16
+ <ul class="resource-attributes-list">
17
+ <%- schemata['property_refs'].each do |property_ref| -%>
18
+ <li class="resource-attributes-item">
19
+ <h3 class="resource-attributes-item-label">
20
+ <span class="resource-attributes-item-name">
21
+ <%= property_ref[:name] %>
22
+ </span>
23
+ <span class="resource-attributes-item-type">
24
+ <%= property_ref[:type] %>
25
+ </span>
26
+ </h3>
27
+ <div class="resource-attributes-item-description-and-children">
28
+ <p class="resource-attributes-item-description">
29
+ <span><%= markdownify.(property_ref[:description]) %></span>
30
+ </p>
31
+ </div>
32
+ </li>
33
+ <%- end -%>
34
+ </ul>
35
+ </div>
36
+
37
+ <div class="resource-example">
38
+ <%= include.('resource_example.html.erb', example: schemata['example']) %>
39
+ </div>
40
+ </div>
41
+
42
+ <% end %>
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'prmd'
3
+ require 'neatjson'
3
4
 
4
5
  module JsonSchemaDocs
5
6
  class Parser
@@ -41,6 +42,7 @@ module JsonSchemaDocs
41
42
  property_ref[:name] = key
42
43
  end
43
44
  schemata['property_refs'].push(property_ref)
45
+ schemata['example'] = pretty_json(@schema.schemata_example(resource))
44
46
  end
45
47
  end
46
48
 
@@ -68,8 +70,8 @@ module JsonSchemaDocs
68
70
  end
69
71
 
70
72
  link['link_path'] = link_path
71
- link['required_properties'] = link_schema_required_properties
72
- link['optional_properties'] = link_schema_optional_properties
73
+ link['required_properties'] = link_schema_required_properties || []
74
+ link['optional_properties'] = link_schema_optional_properties || []
73
75
  link['example'] = generate_example(link, link_path)
74
76
  link['response'] = {
75
77
  header: generate_response_header(response_example, link),
@@ -320,7 +322,7 @@ module JsonSchemaDocs
320
322
 
321
323
  # add data, if present
322
324
  if !data.nil? && link['method'].upcase != 'GET'
323
- data = "-d '#{JSON.pretty_generate(data)}' \\"
325
+ data = "-d '#{pretty_json(data)}' \\"
324
326
  elsif !get_params.empty? && link['method'].upcase == 'GET'
325
327
  data = "-G #{get_params.join(" ss\\\n -d ")} \\"
326
328
  end
@@ -350,16 +352,20 @@ module JsonSchemaDocs
350
352
  else
351
353
  if link['rel'] == 'empty'
352
354
  elsif link.has_key?('targetSchema')
353
- JSON.pretty_generate(@schema.schema_example(link['targetSchema']))
355
+ pretty_json(@schema.schema_example(link['targetSchema']))
354
356
  elsif link['rel'] == 'instances'
355
- JSON.pretty_generate([@schema.schemata_example(resource)])
357
+ pretty_json([@schema.schemata_example(resource)])
356
358
  else
357
- JSON.pretty_generate(@schema.schemata_example(resource))
359
+ pretty_json(@schema.schemata_example(resource))
358
360
  end
359
361
  end
360
362
  else
361
363
  nil
362
364
  end
363
365
  end
366
+
367
+ def pretty_json(json)
368
+ JSON.neat_generate(json, wrap: true, sort: true)
369
+ end
364
370
  end
365
371
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+ require 'html/pipeline'
3
+ require 'yaml'
4
+ require 'extended-markdown-filter'
5
+
6
+ module JsonSchemaDocs
7
+ class Renderer
8
+ include Helpers
9
+
10
+ attr_reader :options
11
+
12
+ def initialize(parsed_schema, options)
13
+ @parsed_schema = parsed_schema
14
+ @options = options
15
+
16
+ unless @options[:templates][:default].nil?
17
+ @default_layout = ERB.new(File.read(@options[:templates][:default]))
18
+ end
19
+
20
+ @pipeline_config = @options[:pipeline_config] || {}
21
+ pipeline = @pipeline_config[:pipeline] || {}
22
+ context = @pipeline_config[:context] || {}
23
+
24
+ filters = pipeline.map do |f|
25
+ if filter?(f)
26
+ f
27
+ else
28
+ key = filter_key(f)
29
+ filter = HTML::Pipeline.constants.find { |c| c.downcase == key }
30
+ # possibly a custom filter
31
+ if filter.nil?
32
+ Kernel.const_get(f)
33
+ else
34
+ HTML::Pipeline.const_get(filter)
35
+ end
36
+ end
37
+ end
38
+
39
+ @pipeline = HTML::Pipeline.new(filters, context)
40
+ end
41
+
42
+ def render(contents, meta: {})
43
+ opts = meta.merge({ base_url: @options[:base_url], output_dir: @options[:output_dir] }).merge(helper_methods)
44
+
45
+ contents = to_html(contents, context: opts)
46
+ return contents if @default_layout.nil?
47
+ opts[:content] = contents
48
+ @default_layout.result(OpenStruct.new(opts).instance_eval { binding })
49
+ end
50
+
51
+ def to_html(string, context: {})
52
+ @pipeline.to_html(string, context)
53
+ end
54
+
55
+ private
56
+
57
+ def filter_key(s)
58
+ s.downcase
59
+ end
60
+
61
+ def filter?(f)
62
+ f < HTML::Pipeline::Filter
63
+ rescue LoadError, ArgumentError
64
+ false
65
+ end
66
+ end
67
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module JsonSchemaDocs
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema-docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-04 00:00:00.000000000 Z
11
+ date: 2019-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prmd
@@ -24,6 +24,132 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: commonmarker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.16'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gemoji
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: html-pipeline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: escape_utils
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: extended-markdown-filter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: neatjson
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: page-toc-filter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.2'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rouge
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.10'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.10'
139
+ - !ruby/object:Gem::Dependency
140
+ name: sass
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.4'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.4'
27
153
  - !ruby/object:Gem::Dependency
28
154
  name: awesome_print
29
155
  requirement: !ruby/object:Gem::Requirement
@@ -169,11 +295,23 @@ files:
169
295
  - lib/json-schema-docs/configuration.rb
170
296
  - lib/json-schema-docs/generator.rb
171
297
  - lib/json-schema-docs/helpers.rb
172
- - lib/json-schema-docs/layouts/endpoint.md.erb
173
- - lib/json-schema-docs/layouts/includes/example.md.erb
174
- - lib/json-schema-docs/layouts/includes/response.md.erb
175
- - lib/json-schema-docs/layouts/object.md.erb
298
+ - lib/json-schema-docs/landing_pages/index.md
299
+ - lib/json-schema-docs/layouts/assets/_sass/_content.scss
300
+ - lib/json-schema-docs/layouts/assets/_sass/_header.scss
301
+ - lib/json-schema-docs/layouts/assets/_sass/_links.scss
302
+ - lib/json-schema-docs/layouts/assets/_sass/_normalize.scss
303
+ - lib/json-schema-docs/layouts/assets/_sass/_resource.scss
304
+ - lib/json-schema-docs/layouts/assets/_sass/_sidebar.scss
305
+ - lib/json-schema-docs/layouts/assets/css/screen.scss
306
+ - lib/json-schema-docs/layouts/default.html.erb
307
+ - lib/json-schema-docs/layouts/includes/curl_example.html.erb
308
+ - lib/json-schema-docs/layouts/includes/resource_example.html.erb
309
+ - lib/json-schema-docs/layouts/includes/response.html.erb
310
+ - lib/json-schema-docs/layouts/includes/sidebar.html.erb
311
+ - lib/json-schema-docs/layouts/links.html.erb
312
+ - lib/json-schema-docs/layouts/resource.html.erb
176
313
  - lib/json-schema-docs/parser.rb
314
+ - lib/json-schema-docs/renderer.rb
177
315
  - lib/json-schema-docs/version.rb
178
316
  - script/bootstrap
179
317
  - script/console
@@ -1,39 +0,0 @@
1
- # <a class="header-link" name="resource-<%= slugify.(schemata['title']) %>"><%= schemata['title'] %></a>
2
-
3
- <% schemata['links'].each do |link, datum| %>
4
-
5
- ## <a class="header-link" name="link-<%= link['method'] %>-<%= resource %>-<%= link['href'] %>"><%= schemata['title'] %> <%= link['title'] %></a>
6
-
7
- <%= link['description'] %>
8
-
9
- ```
10
- <%= link['method'] %> <%= link['link_path'] %>
11
- ```
12
-
13
- <% if link['required_properties'] && !link['required_properties'].empty? %>
14
- ## Required Parameters
15
-
16
- | Name | Type | Description | Example |
17
- | ------- | ------- | ------- | ------- |
18
- <%- link['required_properties'].each do |property_ref| -%>
19
- | **<%= property_ref[:name] %>** | *<%= property_ref[:type] %>* | <%= property_ref[:description] %> | <%= property_ref[:example] %> |
20
- <%- end -%>
21
-
22
- <% end %>
23
-
24
- <% if link['optional_properties'] && !link['optional_properties'].empty? %>
25
- ## Optional Parameters
26
-
27
- | Name | Type | Description | Example |
28
- | ------- | ------- | ------- | ------- |
29
- <%- link['optional_properties'].each do |property_ref| -%>
30
- | **<%= property_ref[:name] %>** | *<%= property_ref[:type] %>* | <%= property_ref[:description] %> | <%= property_ref[:example] %> |
31
- <%- end -%>
32
-
33
- <% end %>
34
-
35
- <%= include.('example.md.erb', example: link['example']) %>
36
-
37
- <%= include.('response.md.erb', response: link['response']) %>
38
-
39
- <% end %>