README.md in rails_api_documentation-0.3.1 vs README.md in rails_api_documentation-0.3.2
- old
+ new
@@ -20,11 +20,11 @@
## Features
+ displaying application api if used in one of correct ways
![alt tag](https://raw.githubusercontent.com/vshaveyko/rails_api_doc/master/preview.png)
+ Integration with Rabl if it is bundled
-+ ```resource_params``` method that will filter incoming params for you
++ ```strong_params``` method that will filter incoming params for you
## Usage
To display api documentation on route '/api_doc' you need to:
@@ -54,12 +54,21 @@
parameter :data_attributes, type: :object, model: 'Datum' do
parameter :creation_date, type: :datetime
parameter :comment, type: :string
end
end
- parameter :test, type: String, required: true
+ parameter :test, type: :string, required: true
+ parameter({
+ articles_attributes: { model: 'Article', type: :ary_object },
+ data_attributes: { model: 'Datum' },
+ comments_attributes: { model: 'Comment', type: :ary_object }
+ }, type: :object) do
+ parameter :id
+ parameter :name
+ end
+
end
```
3. go to localhost:3000/api_doc
## Strong params
@@ -73,17 +82,63 @@
parameter :body, type: :string
parameter :title, type: :string
# controller action
def create
- Comment.create!(resource_params)
+ Comment.create!(strong_params)
end
```
and if request is `POST '/comments', params: { body: 'Comment body', title: 'Comment title', age: 34 }`
Comment will be created with: `Comment(body='Comment body', title='Comment title', age=nil)`
+
+## Value
+
+ You can pass optional value argument to every parameter:
+
+ ```ruby
+ parameter :val, type: :integer, value: -> (request_value) { 5 }
+ ```
+
+ on every matching request value in this field will be overriden by value returned by proc.
+
+ value field expecting anything that will respond to `:call` and can accept one argument(param value from request)
+
+ you should expect that value passed can be `nil`
+
+ This can be used to force values on some fields, or modify values passed to request in some ways.
+
+ E.g. you want to force current_user_id on model creation instead of passing it from frontend.
+
+## Enum
+
+ When you defined parameter type as `:enum` you can pass `enum:` option. This will filter parameter by values provided.
+
+## Group common blocks
+
+ You can define parameters that have common fields this way:
+
+ ```ruby
+ parameter({
+ articles_attributes: { model: 'Article', type: :ary_object },
+ data_attributes: { model: 'Datum' },
+ comments_attributes: { model: 'Comment', type: :ary_object }
+ }, type: :object) do
+ parameter :id
+ parameter :name
+ end
+ ```
+
+ Pass common values as last optional arguments and uniq definitions as hash value.
+ All nesting parameters are applied to elements in blocks.
+
+ Something with same type can be defined like this:
+
+ ```ruby
+ parameter :name, :desc, type: :string
+ ```
## Types
Parameter type may be one of these: