README.md in swagger-serializer-0.5.2 vs README.md in swagger-serializer-0.6.0
- old
+ new
@@ -46,10 +46,11 @@
```ruby
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
include Swagger::Serializer::RailsController
+ extend Swagger::DSL::RailsController
def render_ok(data)
render_as_schema 200, :json, data
end
@@ -65,25 +66,23 @@
swagger :index do
render 200 do
array! { cref! UserSerializer }
end
end
-
def index
render_ok User.all
end
swagger :show do
params do
- path :id, schema: :integer, required: true
+ path :id, schema: :integer
end
render 200 do
cref! UserSerializer
end
end
-
def show
render_ok User.find(schema_params[:id])
end
swagger :create do
@@ -102,24 +101,66 @@
end
end
end
def create
@user = User.new(schema_params[:user])
+
if @user.save
render_ok @user
else
render_bad @user.errors
end
end
+
+ swagger :update do
+ params do
+ path :id, schema: :string
+ end
+
+ body format: [:form, :json] do
+ user :object do
+ name :string
+ end
+ end
+
+ render 200 do
+ cref! UserSerializer
+ end
+ render 400 do
+ additionalProperties! do
+ array! { string! }
+ end
+ end
+ end
+ def update
+ @user = User.find(schema_params[:id])
+
+ if @user.update(schema_params[:user])
+ render_ok @user
+ else
+ render_bad @user.errors
+ end
+ end
+
+ swagger :destroy do
+ params do
+ path :id, schema: :string
+ end
+ end
+ def destroy
+ @user.destroy!
+ head :no_content
+ end
end
```
Would you want to customize serialization?
```ruby
# app/serializers/base_serializer.rb
class BaseSerializer
include Swagger::Serializer
+ extend Swagger::DSL::Serializer
end
```
```ruby
# app/serializers/user_serializer.rb