api_doc_server 1.0.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 (71) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +38 -0
  3. data/.gitignore +10 -0
  4. data/.rubocop.yml +194 -0
  5. data/.rubocop_todo.yml +0 -0
  6. data/.travis.yml +3 -0
  7. data/CHANGELOG.md +10 -0
  8. data/Gemfile +5 -0
  9. data/MIT-LICENSE +20 -0
  10. data/README.md +96 -0
  11. data/Rakefile +30 -0
  12. data/api_doc_server.gemspec +25 -0
  13. data/app/assets/javascripts/api_doc_server/application.js +1 -0
  14. data/app/assets/javascripts/api_doc_server/redoc.js +35833 -0
  15. data/app/assets/javascripts/api_doc_server/redoc.min.js +8 -0
  16. data/app/assets/javascripts/api_doc_server/redoc.min.map +1 -0
  17. data/app/controllers/api_doc_server/application_controller.rb +18 -0
  18. data/app/controllers/api_doc_server/docs_controller.rb +36 -0
  19. data/app/views/api_doc_server/docs/index.html.erb +8 -0
  20. data/app/views/api_doc_server/docs/show.html.erb +8 -0
  21. data/app/views/layouts/swagger.html.erb +26 -0
  22. data/bin/rails +12 -0
  23. data/bin/rubocop +37 -0
  24. data/config/routes.rb +13 -0
  25. data/lib/api_doc_server.rb +21 -0
  26. data/lib/api_doc_server/configuration.rb +22 -0
  27. data/lib/api_doc_server/engine.rb +14 -0
  28. data/lib/api_doc_server/version.rb +21 -0
  29. data/lib/tasks/rubocop.rake +41 -0
  30. data/package.json +9 -0
  31. data/test/controllers/api_doc_server/docs_controller_test.rb +27 -0
  32. data/test/dummy/Rakefile +6 -0
  33. data/test/dummy/app/assets/config/manifest.js +5 -0
  34. data/test/dummy/app/assets/images/.keep +0 -0
  35. data/test/dummy/app/assets/javascripts/application.js +13 -0
  36. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  37. data/test/dummy/app/controllers/application_controller.rb +3 -0
  38. data/test/dummy/app/controllers/concerns/.keep +0 -0
  39. data/test/dummy/app/helpers/application_helper.rb +2 -0
  40. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/test/dummy/bin/bundle +3 -0
  42. data/test/dummy/bin/rails +4 -0
  43. data/test/dummy/bin/rake +4 -0
  44. data/test/dummy/bin/setup +34 -0
  45. data/test/dummy/bin/update +29 -0
  46. data/test/dummy/config.ru +5 -0
  47. data/test/dummy/config/application.rb +22 -0
  48. data/test/dummy/config/boot.rb +5 -0
  49. data/test/dummy/config/environment.rb +5 -0
  50. data/test/dummy/config/environments/development.rb +46 -0
  51. data/test/dummy/config/environments/test.rb +39 -0
  52. data/test/dummy/config/initializers/api_doc_server.rb +3 -0
  53. data/test/dummy/config/locales/en.yml +2 -0
  54. data/test/dummy/config/puma.rb +47 -0
  55. data/test/dummy/config/routes.rb +3 -0
  56. data/test/dummy/config/secrets.yml +22 -0
  57. data/test/dummy/config/spring.rb +6 -0
  58. data/test/dummy/log/.keep +0 -0
  59. data/test/dummy/public/422.html +67 -0
  60. data/test/dummy/public/500.html +66 -0
  61. data/test/dummy/public/api_docs/404.html +67 -0
  62. data/test/dummy/public/api_docs/v1/NewPet.yaml +9 -0
  63. data/test/dummy/public/api_docs/v1/Pet.yaml +12 -0
  64. data/test/dummy/public/api_docs/v1/parameters.yaml +16 -0
  65. data/test/dummy/public/api_docs/v1/swagger.yml +119 -0
  66. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  67. data/test/dummy/public/apple-touch-icon.png +0 -0
  68. data/test/dummy/public/favicon.ico +0 -0
  69. data/test/test_helper.rb +17 -0
  70. data/update_assets.sh +30 -0
  71. metadata +187 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d153ce9988919aa20da7fead9e36657a14311387
4
+ data.tar.gz: 02bd746a5e8697e37abe58d217305ca2414d07df
5
+ SHA512:
6
+ metadata.gz: 43a99eb1c040c5106afc36363183927b28c6254179bc3ec6be7de34d39077197774df6e18e41a1709de322f5a408f3a1350e88987ca3c1377be8b4f7123a43f5
7
+ data.tar.gz: c2122e5452de3df800716fb884c9443aff9944960e767159e200facf44c9fd631c9bb29b1a8d6ae2b07b0198c534563d04371c388c2fae14220685fe00d13cde
data/.codeclimate.yml ADDED
@@ -0,0 +1,38 @@
1
+ ---
2
+ engines:
3
+ brakeman:
4
+ enabled: true
5
+ bundler-audit:
6
+ enabled: true
7
+ csslint:
8
+ enabled: false
9
+ duplication:
10
+ enabled: true
11
+ config:
12
+ languages:
13
+ - ruby
14
+ eslint:
15
+ enabled: false
16
+ fixme:
17
+ enabled: true
18
+ rubocop:
19
+ enabled: true
20
+ ratings:
21
+ paths:
22
+ - Gemfile.lock
23
+ - "**.erb"
24
+ - "**.haml"
25
+ - "**.rb"
26
+ - "**.rhtml"
27
+ - "**.slim"
28
+ - "**.css"
29
+ - "**.inc"
30
+ - "**.js"
31
+ - "**.jsx"
32
+ - "**.module"
33
+ - "**.php"
34
+ - "**.py"
35
+ exclude_paths:
36
+ - config/
37
+ - test/
38
+ - app/assets
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .bundle/
2
+ log/*.log
3
+ test/dummy/tmp/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ api_doc_server-*.gem
8
+ Gemfile.lock
9
+ test/dummy/log/test.log
10
+ node_modules/
data/.rubocop.yml ADDED
@@ -0,0 +1,194 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - !ruby/regexp /(vendor|bundle|bin|db)\/.*/
6
+ DisplayCopNames: true
7
+ DisplayStyleGuide: true
8
+ TargetRubyVersion: 2.4
9
+ TargetRailsVersion: 4.2
10
+ # https://github.com/bbatsov/rubocop/blob/master/manual/caching.md
11
+ # https://github.com/bbatsov/rubocop/blob/e8680418b351491e111a18cf5b453fc07a3c5239/config/default.yml#L60-L77
12
+ UseCache: true
13
+ CacheRootDirectory: tmp
14
+
15
+ Rails:
16
+ Enabled: true
17
+
18
+ Style/NumericPredicate:
19
+ Enabled: false
20
+
21
+ # Rubocop options don't align with code-style, which allows alias.
22
+ # https://github.com/bbatsov/ruby-style-guide/pull/383
23
+ # https://github.com/bbatsov/rubocop/issues/1460
24
+ # see https://github.com/bbatsov/ruby-style-guide#alias-method-lexically
25
+ # vs. https://github.com/bbatsov/ruby-style-guide#alias-method
26
+ Style/Alias:
27
+ Enabled: false
28
+
29
+ Style/SingleLineBlockParams:
30
+ Enabled: false
31
+
32
+ # SupportedStyles: line_count_based, semantic, braces_for_chaining
33
+ Style/BlockDelimiters:
34
+ Enabled: true
35
+ EnforcedStyle: line_count_based
36
+
37
+ Style/MissingElse:
38
+ Enabled: true
39
+ EnforcedStyle: case
40
+
41
+ Style/EmptyElse:
42
+ EnforcedStyle: empty
43
+
44
+ Lint/BlockAlignment:
45
+ Enabled: true
46
+ EnforcedStyleAlignWith: either
47
+
48
+ Lint/EndAlignment:
49
+ Enabled: true
50
+
51
+
52
+ Style/TrailingCommaInLiteral:
53
+ EnforcedStyleForMultiline: no_comma
54
+
55
+ Style/TrailingCommaInArguments:
56
+ EnforcedStyleForMultiline: no_comma
57
+
58
+ Style/PercentLiteralDelimiters:
59
+ PreferredDelimiters:
60
+ '%': '{}'
61
+ '%i': ()
62
+ '%q': ()
63
+ '%Q': ()
64
+ '%r': '{}'
65
+ '%s': ()
66
+ '%w': ()
67
+ '%W': ()
68
+ '%x': ()
69
+
70
+ Style/StringLiterals:
71
+ # EnforcedStyle: single_quotes
72
+ Enabled: false
73
+
74
+ Style/StringLiteralsInInterpolation:
75
+ # EnforcedStyle: single_quotes
76
+ Enabled: false
77
+
78
+ Style/RegexpLiteral:
79
+ Enabled: false
80
+
81
+ Lint/AssignmentInCondition:
82
+ # AllowSafeAssignment: true
83
+ # accepts = in condition surrounded with braces, e.g. if (test = 10)
84
+ # accepts []= in condition surrounded with braces, e.g. if (test[0] = 10)
85
+ Enabled: true
86
+
87
+ Style/VariableNumber:
88
+ Enabled: false
89
+
90
+ Rails/HttpPositionalArguments:
91
+ Enabled: false
92
+
93
+ Rails/Blank:
94
+ Enabled: false
95
+
96
+ Style/NumericLiterals:
97
+ Enabled: false
98
+
99
+ Style/Documentation:
100
+ Enabled: false
101
+
102
+ Style/DoubleNegation:
103
+ Enabled: false
104
+
105
+ Layout/IndentArray:
106
+ EnforcedStyle: consistent
107
+
108
+ Layout/SpaceInLambdaLiteral:
109
+ EnforcedStyle: require_no_space
110
+
111
+ Layout/AlignParameters:
112
+ EnforcedStyle: with_fixed_indentation
113
+ Enabled: true
114
+
115
+ Layout/AlignHash:
116
+ EnforcedHashRocketStyle: key
117
+ EnforcedColonStyle: key
118
+ EnforcedLastArgumentHashStyle: ignore_implicit
119
+
120
+ Layout/IndentHash:
121
+ EnforcedStyle: consistent
122
+
123
+ Layout/IndentationWidth:
124
+ Width: 2
125
+
126
+ Layout/MultilineOperationIndentation:
127
+ EnforcedStyle: indented
128
+
129
+ Layout/ClosingParenthesisIndentation:
130
+ Enabled: false
131
+
132
+ Layout/SpaceInsideHashLiteralBraces:
133
+ EnforcedStyle: no_space
134
+
135
+ Layout/FirstParameterIndentation:
136
+ EnforcedStyle: special_for_inner_method_call_in_parentheses
137
+
138
+ Layout/ExtraSpacing:
139
+ Enabled: true
140
+
141
+ Layout/SpaceAfterColon:
142
+ Enabled: true
143
+
144
+ Layout/SpaceAfterComma:
145
+ Enabled: true
146
+
147
+ Layout/SpaceAfterNot:
148
+ Enabled: true
149
+
150
+ Layout/SpaceAroundEqualsInParameterDefault:
151
+ EnforcedStyle: no_space
152
+
153
+ Layout/SpaceBeforeBlockBraces:
154
+ Enabled: false
155
+ # EnforcedStyle: space
156
+
157
+ Layout/SpaceInsideBlockBraces:
158
+ EnforcedStyle: space
159
+ EnforcedStyleForEmptyBraces: no_space
160
+ # Space between { and |. Overrides EnforcedStyle if there is a conflict.
161
+ SpaceBeforeBlockParameters: true
162
+
163
+ Layout/SpaceInsideBrackets:
164
+ Enabled: true
165
+
166
+ Layout/SpaceInsideParens:
167
+ Enabled: true
168
+
169
+ Layout/EmptyLines:
170
+ Enabled: true
171
+
172
+ Layout/EmptyLinesAroundAccessModifier:
173
+ Enabled: true
174
+
175
+ Layout/EmptyLinesAroundBlockBody:
176
+ EnforcedStyle: no_empty_lines
177
+
178
+ Layout/EmptyLinesAroundClassBody:
179
+ EnforcedStyle: no_empty_lines
180
+
181
+ Layout/EmptyLinesAroundModuleBody:
182
+ EnforcedStyle: no_empty_lines
183
+
184
+ Layout/EmptyLinesAroundMethodBody:
185
+ Enabled: true
186
+
187
+ Layout/EmptyLineBetweenDefs:
188
+ Enabled: true
189
+
190
+ Layout/LeadingCommentSpace:
191
+ Enabled: true
192
+
193
+ Layout/TrailingWhitespace:
194
+ Enabled: true
data/.rubocop_todo.yml ADDED
File without changes
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # ApiDocServer Changelog
2
+
3
+ ## master
4
+
5
+ ## 1.0
6
+
7
+ - Use ReDoc 1.19.1 (not SwaggerUI)
8
+ - Run tests in random order
9
+ - Support Rails 4.2
10
+ - Rename SwaggeUiEngine to ApiDocServer
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Zuzanna Stolińska
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # ApiDocServer
2
+
3
+ Include [redoc](https://github.com/Rebilly/ReDoc) as Rails engine and document your API with simple YAML files. Supports API documentation versioning.
4
+
5
+ ## Installation
6
+
7
+ Add to Gemfile
8
+
9
+ ```
10
+ gem 'api_doc_server'
11
+ ```
12
+
13
+ And then run:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Mount
22
+
23
+ Add to your `config/routes.rb`
24
+
25
+ ```
26
+ mount ApiDocServer::Engine, at: "/api_docs"
27
+ ```
28
+
29
+ You can place this route under `admin_constraint` or other restricted path, or configure basic HTTP authentication.
30
+
31
+ #### Devise auth
32
+
33
+ ```
34
+ authenticate :user, lambda { |u| u.admin? } do
35
+ mount ApiDocServer::Engine, at: "/api_docs"
36
+ end
37
+ ```
38
+
39
+ #### Basic HTTP auth
40
+
41
+ Set admin username and password in an initializer:
42
+
43
+ ```
44
+ # config/initializers/api_doc_server.rb
45
+
46
+ ApiDocServer.configure do |config|
47
+ config.authentication_proc = proc do |controller|
48
+ authenticate_or_request_with_http_basic do |username, password|
49
+ User.find_by(name: username, password: password)
50
+ end
51
+ end
52
+ end
53
+ ```
54
+
55
+ ### Initialize
56
+
57
+ #### Versioned API documentations
58
+
59
+ Set the path of your json/yaml versioned documentations in an initializer:
60
+
61
+ ```
62
+ # config/initializers/api_doc_server.rb
63
+
64
+ ApiDocServer.configure do |config|
65
+ config.swagger_urls = {
66
+ v1: 'api/v1/swagger.yaml',
67
+ v2: 'api/v2/swagger.yaml',
68
+ }
69
+ end
70
+ ```
71
+
72
+ and place your main documentation file under `/public/api` path.
73
+
74
+ #### Single API documentation
75
+
76
+
77
+ ```
78
+ # config/initializers/api_doc_server.rb
79
+
80
+ ApiDocServer.configure do |config|
81
+ config.swagger_urls = { v1: 'api/v1/swagger.yaml' }
82
+ end
83
+ ```
84
+
85
+
86
+ ### Configure
87
+ Config Name | Swagger parameter name | Description
88
+ --- | --- | ---
89
+ config.swagger_url | Hash<version_key,url> | The url pointing `swagger.yaml` (Swagger 2.0) as per [OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification/). This params requires hash value - pass your API doc version name as a key and it's main documentation url as a value.
90
+ config.doc_config | Hash<config_attribute,value> | Any of the configs specified in https://github.com/Rebilly/ReDoc#redoc-tag-attributes, e.g. `{ 'scroll-y-offset': 50 }`
91
+ config.authentication_proc = | proc | a proc that takes the current controller as an argument and halts rendering per custom strategy.
92
+
93
+
94
+ ## License
95
+
96
+ This project is available under MIT-LICENSE. :sunny:
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rdoc/task'
10
+
11
+ load 'rails/tasks/statistics.rake'
12
+ require 'bundler/gem_tasks'
13
+ require 'rake/testtask'
14
+
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << 'lib'
17
+ t.libs << 'test'
18
+ t.pattern = 'test/**/*_test.rb'
19
+ t.verbose = false
20
+ end
21
+
22
+ RDoc::Task.new(:rdoc) do |rdoc|
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = 'ApiDocServer'
25
+ rdoc.options << '--line-numbers'
26
+ rdoc.rdoc_files.include('README.rdoc')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ task default: :test
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'api_doc_server/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'api_doc_server'
7
+ s.version = ApiDocServer::VERSION
8
+ s.authors = ['Benjamin Fleischer']
9
+ s.email = ['github@benjaminfleischer.com']
10
+ s.homepage = 'https://github.com/bf4/api_doc_server'
11
+ s.summary = 'Mountable Rails engine that serves API Docs for your Swagger/OpenAPI docs.'
12
+ s.description = s.summary
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files -z`.split("\x0")
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+ s.require_paths = ['lib']
18
+ s.executables = []
19
+
20
+ s.required_ruby_version = '>= 2.1'
21
+
22
+ s.add_runtime_dependency 'rails', ['>= 4.2', '< 6']
23
+
24
+ s.add_development_dependency 'rubocop'
25
+ end