rails_api_documentation 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/app/assets/javascripts/table.js.coffee +8 -3
- data/app/assets/stylesheets/rails_api_doc/application.css +1 -0
- data/app/assets/stylesheets/rails_api_doc/default.sass +31 -0
- data/app/assets/stylesheets/rails_api_doc/side_menu.sass +12 -23
- data/app/assets/stylesheets/rails_api_doc/table.sass +104 -84
- data/app/controllers/rails_api_doc/api_docs_controller.rb +19 -18
- data/app/models/rails_api_doc/api_datum.rb +8 -0
- data/app/views/layouts/rails_api_doc/application.slim +10 -9
- data/app/views/rails_api_doc/api_docs/_request_api_table.slim +4 -3
- data/app/views/rails_api_doc/api_docs/_response_api_table.slim +13 -6
- data/app/views/rails_api_doc/api_docs/index.slim +15 -20
- data/app/views/shared/_param_inputs.slim +8 -0
- data/app/views/shared/_side_menu.slim +9 -0
- data/app/views/shared/_table.slim +37 -17
- data/lib/generators/rails_api_doc/install_generator.rb +23 -0
- data/lib/generators/rails_api_doc/templates/api_datum_migration.rb +15 -0
- data/lib/rails_api_doc/config/validate_ary_object.rb +1 -1
- data/lib/rails_api_doc/config/validate_enum.rb +1 -1
- data/lib/rails_api_doc/config/validate_type.rb +1 -1
- data/lib/rails_api_doc/config/validator.rb +0 -4
- data/lib/rails_api_doc/config.rb +0 -2
- data/lib/rails_api_doc/controller/request/dsl.rb +60 -0
- data/lib/rails_api_doc/controller/request/headers.rb +56 -0
- data/lib/rails_api_doc/controller/request/param.rb +81 -0
- data/lib/rails_api_doc/controller/{parameter → request}/repository.rb +3 -1
- data/lib/rails_api_doc/controller/{response_factory.rb → response/factory.rb} +2 -2
- data/lib/rails_api_doc/controller/response/headers.rb +30 -0
- data/lib/rails_api_doc/controller/response/param.rb +14 -0
- data/lib/rails_api_doc/controller/response/rabl.rb +3 -1
- data/lib/rails_api_doc/controller/response/rabl_compiler.rb +4 -13
- data/lib/rails_api_doc/controller/strong_params/dsl.rb +17 -0
- data/lib/rails_api_doc/controller/strong_params/permitted_params.rb +88 -0
- data/lib/rails_api_doc/engine.rb +0 -12
- data/lib/rails_api_doc/{controller → model}/attribute_parser.rb +1 -1
- data/lib/rails_api_doc/railtie.rb +5 -2
- data/lib/rails_api_doc/version.rb +1 -1
- data/lib/rails_api_doc.rb +48 -1
- metadata +18 -16
- data/app/views/rails_api_doc/api_docs/_edit_field.slim +0 -9
- data/app/views/rails_api_doc/api_docs/_side_menu.slim +0 -9
- data/app/views/rails_api_doc/api_docs/_title.slim +0 -4
- data/app/views/rails_api_doc/api_docs/edit.js.erb +0 -0
- data/app/views/rails_api_doc/api_docs/example.html.erb +0 -32
- data/app/views/rails_api_doc/api_docs/new.js.erb +0 -0
- data/app/views/shared/_response_table.slim +0 -30
- data/lib/rails_api_doc/controller/parameter/repository/param.rb +0 -68
- data/lib/rails_api_doc/controller/parameter.rb +0 -54
- data/lib/rails_api_doc/controller/strong_params.rb +0 -71
- data/lib/rails_api_doc/controller.rb +0 -6
@@ -1,9 +0,0 @@
|
|
1
|
-
.row
|
2
|
-
= form_tag(api_doc_path, method: 'post', remote: true, class: 'form-horizontal') do
|
3
|
-
- ([:name] + headers).each do |field_name|
|
4
|
-
div.field(class="col-md-#{col_num - 1}")
|
5
|
-
/ Add parameter name second argument
|
6
|
-
= text_field_tag field_name, nil, placeholder: field_name, class: 'form-control'
|
7
|
-
|
8
|
-
div.actions(class="col-md-#{col_num - 1}")
|
9
|
-
= button_tag 'Add table parameter', class: 'btn btn-primary'
|
@@ -1,9 +0,0 @@
|
|
1
|
-
nav.bs-docs-sidebar.hidden-print.hidden-sm.hidden-xs
|
2
|
-
ul.side-menu.nav.bs-docs-sidenav
|
3
|
-
- locals[:models].each do |model|
|
4
|
-
li
|
5
|
-
a[href=('#' + model.to_s)] = model.to_s
|
6
|
-
span = '('
|
7
|
-
a[href=('#' + model.to_s + '.request')] req,
|
8
|
-
a[href=('#' + model.to_s + '.response')] resp
|
9
|
-
span = ')'
|
@@ -1,4 +0,0 @@
|
|
1
|
-
.bs-docs-section
|
2
|
-
h1#grid.page-header
|
3
|
-
a.anchorjs-link[href="#grid" aria-label="Anchor link for: grid" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: inherit; position: absolute; margin-left: -1em; padding-right: 0.5em;"]
|
4
|
-
| Api documentation
|
File without changes
|
@@ -1,32 +0,0 @@
|
|
1
|
-
<table class="table table-condensed">
|
2
|
-
<thead class="thead-default">
|
3
|
-
<tr>
|
4
|
-
<th>#</th>
|
5
|
-
<th>First Name</th>
|
6
|
-
<th>Last Name</th>
|
7
|
-
<th>Username</th>
|
8
|
-
</tr>
|
9
|
-
</thead>
|
10
|
-
<tbody>
|
11
|
-
<tr class="success">
|
12
|
-
<th scope="row">1</th>
|
13
|
-
<td>Mark</td>
|
14
|
-
<td>Otto</td>
|
15
|
-
<td>@mdo</td>
|
16
|
-
</tr>
|
17
|
-
<tr class="active">
|
18
|
-
<th scope="row">2</th>
|
19
|
-
<td>Jacob</td>
|
20
|
-
<td>Thornton</td>
|
21
|
-
<td>@fat</td>
|
22
|
-
</tr>
|
23
|
-
<tr>
|
24
|
-
<th scope="row" class="warning">3</th>
|
25
|
-
<td>Larry</td>
|
26
|
-
<td>the Bird</td>
|
27
|
-
<td>@twitter</td>
|
28
|
-
</tr>
|
29
|
-
</tbody>
|
30
|
-
</table>
|
31
|
-
|
32
|
-
|
File without changes
|
@@ -1,30 +0,0 @@
|
|
1
|
-
- nesting = locals[:nesting] || []
|
2
|
-
|
3
|
-
div.flex-table
|
4
|
-
|
5
|
-
= form_tag(api_doc_url(nesting: nesting), method: :put, remote: true, class: 'flex-line row') do
|
6
|
-
/ Угловой елемент
|
7
|
-
div.flex-item
|
8
|
-
// TODO: use icon with + to indicate adding
|
9
|
-
span.add-ico = '( + )'
|
10
|
-
= text_field_tag 'name', nil, placeholder: 'Enter param name'
|
11
|
-
span Parameter
|
12
|
-
|
13
|
-
div.flex-item Value
|
14
|
-
|
15
|
-
= submit_tag 'Save', class: 'flex-item mod-submit'
|
16
|
-
|
17
|
-
- locals[:rows].each do |row_name, node|
|
18
|
-
= form_tag(api_doc_url(nesting: nesting), method: :put, remote: true, class: 'flex-line row') do
|
19
|
-
div.flex-item
|
20
|
-
span.edit-ico = '(edit)'
|
21
|
-
= text_field_tag 'name', row_name, placeholder: 'Enter param name'
|
22
|
-
span #{row_name}
|
23
|
-
- if node.nested?
|
24
|
-
div.flex-item.next-is-nested #{node.attr}(Nested)
|
25
|
-
- else
|
26
|
-
div.flex-item #{node.attr}
|
27
|
-
= submit_tag 'Save', class: 'flex-item mod-submit'
|
28
|
-
|
29
|
-
- if node.nested?
|
30
|
-
= render 'shared/response_table', locals: { rows: node.nested, nesting: nesting + [row_name] }
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# author: Vadim Shaveiko <@vshaveyko>
|
3
|
-
class RailsApiDoc::Controller::Parameter::Repository::Param
|
4
|
-
|
5
|
-
NESTED_TYPES = [:ary_object, :object, :model, Object].freeze
|
6
|
-
|
7
|
-
STRAIGHT_TYPES = [:bool, :string, :integer, :array, :datetime, :enum, String, Object, Integer, Array, DateTime].freeze
|
8
|
-
|
9
|
-
ACCEPTED_TYPES = (NESTED_TYPES + STRAIGHT_TYPES).freeze
|
10
|
-
|
11
|
-
# @type - type to check
|
12
|
-
def self.accepted_nested_type?(type)
|
13
|
-
type.in?(NESTED_TYPES)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.valid_type?(type)
|
17
|
-
return if type.nil? || type.in?(ACCEPTED_TYPES)
|
18
|
-
raise ArgumentError, "Wrong type: #{type}. " \
|
19
|
-
"Correct types are: #{ACCEPTED_TYPES}."
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.valid_enum?(type, enum)
|
23
|
-
return false unless type == :enum
|
24
|
-
return if enum.is_a?(Array)
|
25
|
-
raise ArgumentError, 'Enum must be an array.'
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.valid_nested?(type, block_given)
|
29
|
-
return false unless accepted_nested_type?(type)
|
30
|
-
return true if block_given
|
31
|
-
raise ArgumentError, 'Empty object passed.'
|
32
|
-
end
|
33
|
-
|
34
|
-
def initialize(name, store)
|
35
|
-
@name = name
|
36
|
-
@store = store
|
37
|
-
end
|
38
|
-
|
39
|
-
def enum?
|
40
|
-
@store[:type] == :enum && @store[:enum].present?
|
41
|
-
end
|
42
|
-
|
43
|
-
def ary_object?
|
44
|
-
@store[:type] == :ary_object
|
45
|
-
end
|
46
|
-
|
47
|
-
def nested?
|
48
|
-
self.class.accepted_nested_type?(@store[:type])
|
49
|
-
end
|
50
|
-
|
51
|
-
def nesting
|
52
|
-
@store[:nested]
|
53
|
-
end
|
54
|
-
|
55
|
-
def required?
|
56
|
-
@store[:required]
|
57
|
-
end
|
58
|
-
|
59
|
-
def method_missing(name, *args)
|
60
|
-
return @store.public_send(name, *args) if respond_to_missing?(name)
|
61
|
-
super
|
62
|
-
end
|
63
|
-
|
64
|
-
def respond_to_missing?(name, *)
|
65
|
-
@store.respond_to?(name)
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# author: Vadim Shaveiko <@vshaveyko>
|
3
|
-
module RailsApiDoc::Controller::Parameter
|
4
|
-
|
5
|
-
VALID_KEYS = [:type, :required, :enum, :model].freeze #:nodoc:
|
6
|
-
|
7
|
-
# Use parameter in controller to defined REQUEST parameter.
|
8
|
-
# Adds it to repository: RailsApiDoc::Controller::Parameter::Repository
|
9
|
-
def parameter(name, options = {}, &block)
|
10
|
-
raise ArgumentError, 'Parameter already defined.' if repo.key?(name)
|
11
|
-
|
12
|
-
validate_options(options, block_given?)
|
13
|
-
|
14
|
-
define_parameter(name, options, &block)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def validate_options(options, block_given)
|
20
|
-
options.assert_valid_keys(VALID_KEYS)
|
21
|
-
|
22
|
-
Repository::Param.valid_type?(options[:type])
|
23
|
-
end
|
24
|
-
|
25
|
-
# default repo can be reassigned to deal with nested parameters
|
26
|
-
# see nested_parameter
|
27
|
-
def repo
|
28
|
-
@repo || Repository[self]
|
29
|
-
end
|
30
|
-
|
31
|
-
# adjust parameter values depending on parameter type
|
32
|
-
# 1. if nested - add nested values to parameter_data on :nested key
|
33
|
-
# 2. if enum - transform all values to_s
|
34
|
-
# bcs all incoming controller parameters will be strings and there can be errors
|
35
|
-
def define_parameter(name, parameter_data, &block)
|
36
|
-
if Repository::Param.valid_nested?(parameter_data[:type], block_given?)
|
37
|
-
parameter_data = nested_parameter(parameter_data, &block)
|
38
|
-
elsif Repository::Param.valid_enum?(parameter_data[:type], parameter_data[:enum])
|
39
|
-
parameter_data[:enum].map!(:to_s)
|
40
|
-
end
|
41
|
-
|
42
|
-
repo[name] = Repository::Param.new(name, parameter_data)
|
43
|
-
end
|
44
|
-
|
45
|
-
def nested_parameter(parameter_data)
|
46
|
-
_backup_repo = @repo
|
47
|
-
@repo = {}
|
48
|
-
yield
|
49
|
-
parameter_data.merge(nested: @repo)
|
50
|
-
ensure
|
51
|
-
@repo = _backup_repo
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# author: Vadim Shaveiko <@vshaveyko>
|
2
|
-
# frozen_string_literal: true
|
3
|
-
module RailsApiDoc::Controller::StrongParams
|
4
|
-
|
5
|
-
ParamIsRequired = Class.new(StandardError)
|
6
|
-
|
7
|
-
def resource_params
|
8
|
-
# accepted_params for permit
|
9
|
-
params.permit(params_to_permit)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def params_to_permit
|
15
|
-
accepted_params = [{}]
|
16
|
-
|
17
|
-
loop_params(params, permitted_params, accepted_params)
|
18
|
-
|
19
|
-
accepted_params
|
20
|
-
end
|
21
|
-
|
22
|
-
# loop through current level of params and add to permit level if all requirements are met
|
23
|
-
#
|
24
|
-
# requirements are: 1) if required is set - param must be present and not empty => or error is raised
|
25
|
-
# 2) if enum is set - param must equal predefined value => see Config::ValidateEnum
|
26
|
-
# 3) if ary_object => see Config::ValidateAryObject
|
27
|
-
# 3) if config.check_params_type is set - param must be of required type
|
28
|
-
#
|
29
|
-
# @accepted_params = [{}] - array with last member hash for nesting
|
30
|
-
# @level_params - current nesting level params
|
31
|
-
# @level_permitted_params - data for params permission
|
32
|
-
def loop_params(params, level_permitted_params, accepted_params)
|
33
|
-
level_permitted_params.each do |param_name, api_param_data|
|
34
|
-
controller_param = params[param_name]
|
35
|
-
|
36
|
-
check_required(param_name, controller_param, api_param_data)
|
37
|
-
#
|
38
|
-
# no value present && not required => go next
|
39
|
-
next unless controller_param
|
40
|
-
|
41
|
-
next unless RailsApiDoc::Config::Validator.valid_param?(controller_param, api_param_data)
|
42
|
-
|
43
|
-
# if settings is array
|
44
|
-
if api_param_data.ary_object?
|
45
|
-
controller_param.each do |single_controller_param|
|
46
|
-
_next_nesting_level(single_controller_param, param_data: api_param_data, current_accepted_params: accepted_params, param_name: param_name)
|
47
|
-
end
|
48
|
-
elsif api_param_data.nested?
|
49
|
-
_next_nesting_level(controller_param, param_data: api_param_data, current_accepted_params: accepted_params, param_name: param_name)
|
50
|
-
else
|
51
|
-
accepted_params.unshift(param_name)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def _next_nesting_level(controller_param, param_data:, current_accepted_params:, param_name:)
|
57
|
-
level_accepted_params = current_accepted_params.last[param_name] = [{}]
|
58
|
-
|
59
|
-
loop_params(controller_param, param_data.nesting, level_accepted_params)
|
60
|
-
end
|
61
|
-
|
62
|
-
def permitted_params
|
63
|
-
::RailsApiDoc::Controller::Parameter::Repository[self.class]
|
64
|
-
end
|
65
|
-
|
66
|
-
def check_required(param_name, param_data, param_config)
|
67
|
-
return unless param_config.required? && param_data.blank?
|
68
|
-
raise RailsApiDoc::Exception::ParamRequired, param_name
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|