rails_api_documentation 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +41 -0
- data/app/assets/config/rails_api_doc_manifest.js +2 -0
- data/app/assets/javascripts/api_doc.js +5 -0
- data/app/assets/javascripts/components.js +1 -0
- data/app/assets/javascripts/rails_api_doc/application.js +3 -0
- data/app/assets/javascripts/table.js.coffee +8 -0
- data/app/assets/stylesheets/rails_api_doc/application.css +15 -0
- data/app/assets/stylesheets/rails_api_doc/table.sass +105 -0
- data/app/controllers/rails_api_doc/api_docs_controller.rb +51 -0
- data/app/controllers/rails_api_doc/application_controller.rb +5 -0
- data/app/helpers/rails_api_doc/application_helper.rb +4 -0
- data/app/models/rails_api_doc/application_record.rb +5 -0
- data/app/views/layouts/rails_api_doc/application.slim +20 -0
- data/app/views/rails_api_doc/api_docs/_edit_field.slim +9 -0
- data/app/views/rails_api_doc/api_docs/_request_api_table.slim +43 -0
- data/app/views/rails_api_doc/api_docs/_response_api_table.slim +7 -0
- data/app/views/rails_api_doc/api_docs/_side_menu.slim +10 -0
- data/app/views/rails_api_doc/api_docs/_title.slim +4 -0
- data/app/views/rails_api_doc/api_docs/edit.js.erb +0 -0
- data/app/views/rails_api_doc/api_docs/example.html.erb +32 -0
- data/app/views/rails_api_doc/api_docs/index.slim +23 -0
- data/app/views/rails_api_doc/api_docs/new.js.erb +0 -0
- data/app/views/shared/_response_table.slim +14 -0
- data/app/views/shared/_table.slim +20 -0
- data/config/routes.rb +10 -0
- data/lib/rails_api_doc/config/validator.rb +14 -0
- data/lib/rails_api_doc/configuration.rb +9 -0
- data/lib/rails_api_doc/controller/attribute_parser.rb +56 -0
- data/lib/rails_api_doc/controller/parameter/repository/param.rb +51 -0
- data/lib/rails_api_doc/controller/parameter/repository.rb +33 -0
- data/lib/rails_api_doc/controller/parameter.rb +57 -0
- data/lib/rails_api_doc/controller/response/rabl.rb +58 -0
- data/lib/rails_api_doc/controller/response/rabl_compiler.rb +236 -0
- data/lib/rails_api_doc/controller/response_factory.rb +19 -0
- data/lib/rails_api_doc/controller/strong_params.rb +46 -0
- data/lib/rails_api_doc/controller.rb +6 -0
- data/lib/rails_api_doc/engine.rb +40 -0
- data/lib/rails_api_doc/types.rb +7 -0
- data/lib/rails_api_doc/version.rb +5 -0
- data/lib/rails_api_doc.rb +26 -0
- data/lib/tasks/rails_api_doc_tasks.rake +4 -0
- metadata +197 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# author: Vadim Shaveiko <@vshaveyko>
|
3
|
+
# :nodoc:
|
4
|
+
class RailsApiDoc::Controller::Response
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
# TODO: add more options later depending on app settings
|
9
|
+
def repo
|
10
|
+
::RailsApiDoc::Controller::Response::Rabl.new(controllers)
|
11
|
+
end
|
12
|
+
|
13
|
+
def controllers
|
14
|
+
RailsApiDoc::Controller::Parameter::Repository.registered_controllers
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# author: Vadim Shaveiko <@vshaveyko>
|
2
|
+
# frozen_string_literal: true
|
3
|
+
module RailsApiDoc::Controller::StrongParams
|
4
|
+
|
5
|
+
def resource_params
|
6
|
+
# accepted_params for permit
|
7
|
+
accepted_params = [{}]
|
8
|
+
loop_params(params, permitted_params, accepted_params)
|
9
|
+
params.permit(accepted_params)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
# loop through current level of params and add to permit level if
|
15
|
+
# all requirements met
|
16
|
+
# requirements are: 1) if required is set - param must be present and not empty
|
17
|
+
# 2) if enum is set - param must equal predefined value
|
18
|
+
# 3) if config.check_params_type is set - param must be of required type
|
19
|
+
# @accepted_params = [{}] - array with last member hash for nesting
|
20
|
+
# @level_params - current nesting level params
|
21
|
+
# @level_permitted_params - data for params permission
|
22
|
+
def loop_params(nested_controller_params, level_permitted_params, accepted_params)
|
23
|
+
level_permitted_params.each do |param_name, api_param_data|
|
24
|
+
controller_param = nested_controller_params[param_name]
|
25
|
+
|
26
|
+
next unless RailsApiDoc::Config::Validator.valid_param?(controller_param, api_param_data)
|
27
|
+
|
28
|
+
if api_param_data.nested?
|
29
|
+
level_accepted_params = accepted_params.last[param_name] = [{}]
|
30
|
+
next loop_params(controller_param, api_param_data, level_accepted_params)
|
31
|
+
else
|
32
|
+
accepted_params.unshift(param_name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def permitted_params
|
38
|
+
Parameter::Repository[self]
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_required_ok?(param_data, param_config)
|
42
|
+
return true unless param_config.required?
|
43
|
+
!param_data.blank?
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# author: Vadism Shaveiko <@vshaveyko>
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'action_controller'
|
4
|
+
require 'action_view'
|
5
|
+
require 'jquery-rails'
|
6
|
+
require 'slim'
|
7
|
+
|
8
|
+
require_relative 'types'
|
9
|
+
require_relative 'controller'
|
10
|
+
require_relative 'controller/strong_params'
|
11
|
+
require_relative 'controller/attribute_parser'
|
12
|
+
require_relative 'controller/parameter'
|
13
|
+
require_relative 'controller/parameter/repository'
|
14
|
+
require_relative 'controller/parameter/repository/param'
|
15
|
+
|
16
|
+
require_relative 'controller/response_factory'
|
17
|
+
|
18
|
+
# add rabl support
|
19
|
+
begin
|
20
|
+
require 'rabl'
|
21
|
+
require_relative 'controller/response/rabl'
|
22
|
+
require_relative 'controller/response/rabl_compiler'
|
23
|
+
RailsApiDoc::Controller::Response::Rabl.renderer = Rabl::Renderer
|
24
|
+
rescue LoadError
|
25
|
+
end
|
26
|
+
|
27
|
+
class RailsApiDoc::Engine < ::Rails::Engine
|
28
|
+
|
29
|
+
isolate_namespace RailsApiDoc
|
30
|
+
|
31
|
+
initializer 'rails_api_doc.assets.precompile' do |app|
|
32
|
+
app.config.assets.precompile += %w(application.css application.js api_doc.js rails_api_doc/api_doc.js)
|
33
|
+
end
|
34
|
+
|
35
|
+
ActionController::Base.class_eval do
|
36
|
+
include RailsApiDoc::Controller::StrongParams
|
37
|
+
extend RailsApiDoc::Controller::Parameter
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# author: Vadim Shaveiko <@vshaveyko>
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'rails_api_doc/engine'
|
4
|
+
module RailsApiDoc
|
5
|
+
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def configure
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
@_configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset_configuration
|
19
|
+
@_configuration = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
autoload :Controller
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_api_documentation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- vs
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: actionpack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jquery-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sass-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coffee-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: slim
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Document and view nice API docs.
|
126
|
+
email:
|
127
|
+
- vshaveyko@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- README.md
|
133
|
+
- app/assets/config/rails_api_doc_manifest.js
|
134
|
+
- app/assets/javascripts/api_doc.js
|
135
|
+
- app/assets/javascripts/components.js
|
136
|
+
- app/assets/javascripts/rails_api_doc/application.js
|
137
|
+
- app/assets/javascripts/table.js.coffee
|
138
|
+
- app/assets/stylesheets/rails_api_doc/application.css
|
139
|
+
- app/assets/stylesheets/rails_api_doc/table.sass
|
140
|
+
- app/controllers/rails_api_doc/api_docs_controller.rb
|
141
|
+
- app/controllers/rails_api_doc/application_controller.rb
|
142
|
+
- app/helpers/rails_api_doc/application_helper.rb
|
143
|
+
- app/models/rails_api_doc/application_record.rb
|
144
|
+
- app/views/layouts/rails_api_doc/application.slim
|
145
|
+
- app/views/rails_api_doc/api_docs/_edit_field.slim
|
146
|
+
- app/views/rails_api_doc/api_docs/_request_api_table.slim
|
147
|
+
- app/views/rails_api_doc/api_docs/_response_api_table.slim
|
148
|
+
- app/views/rails_api_doc/api_docs/_side_menu.slim
|
149
|
+
- app/views/rails_api_doc/api_docs/_title.slim
|
150
|
+
- app/views/rails_api_doc/api_docs/edit.js.erb
|
151
|
+
- app/views/rails_api_doc/api_docs/example.html.erb
|
152
|
+
- app/views/rails_api_doc/api_docs/index.slim
|
153
|
+
- app/views/rails_api_doc/api_docs/new.js.erb
|
154
|
+
- app/views/shared/_response_table.slim
|
155
|
+
- app/views/shared/_table.slim
|
156
|
+
- config/routes.rb
|
157
|
+
- lib/rails_api_doc.rb
|
158
|
+
- lib/rails_api_doc/config/validator.rb
|
159
|
+
- lib/rails_api_doc/configuration.rb
|
160
|
+
- lib/rails_api_doc/controller.rb
|
161
|
+
- lib/rails_api_doc/controller/attribute_parser.rb
|
162
|
+
- lib/rails_api_doc/controller/parameter.rb
|
163
|
+
- lib/rails_api_doc/controller/parameter/repository.rb
|
164
|
+
- lib/rails_api_doc/controller/parameter/repository/param.rb
|
165
|
+
- lib/rails_api_doc/controller/response/rabl.rb
|
166
|
+
- lib/rails_api_doc/controller/response/rabl_compiler.rb
|
167
|
+
- lib/rails_api_doc/controller/response_factory.rb
|
168
|
+
- lib/rails_api_doc/controller/strong_params.rb
|
169
|
+
- lib/rails_api_doc/engine.rb
|
170
|
+
- lib/rails_api_doc/types.rb
|
171
|
+
- lib/rails_api_doc/version.rb
|
172
|
+
- lib/tasks/rails_api_doc_tasks.rake
|
173
|
+
homepage: https://github.com/vshaveyko/rails_api_doc
|
174
|
+
licenses:
|
175
|
+
- MIT
|
176
|
+
metadata: {}
|
177
|
+
post_install_message:
|
178
|
+
rdoc_options: []
|
179
|
+
require_paths:
|
180
|
+
- lib
|
181
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
requirements: []
|
192
|
+
rubyforge_project:
|
193
|
+
rubygems_version: 2.5.1
|
194
|
+
signing_key:
|
195
|
+
specification_version: 4
|
196
|
+
summary: Nice API doc.
|
197
|
+
test_files: []
|