README.md in grape_fast_jsonapi-0.1.0 vs README.md in grape_fast_jsonapi-0.2.0
- old
+ new
@@ -6,18 +6,15 @@
Add the `grape` and `grape_fast_jsonapi` gems to Gemfile.
```ruby
gem 'grape'
-# gem is not published to rubygems yet
-gem 'grape_fast_jsonapi', git: 'git@github.com:EmCousin/grape_fast_jsonapi.git'
+gem 'grape_fast_jsonapi'
```
## Usage
-### Require grape_fast_jsonapi
-
### Tell your API to use Grape::Formatter::FastJsonapi
```ruby
class API < Grape::API
format :json
@@ -31,9 +28,36 @@
get "/" do
user = User.find("123")
render user, include: [:account]
end
```
+
+### Model parser for response documentation
+
+When using Grape with Swagger via [grape-swagger](https://github.com/ruby-grape/grape-swagger), you can generate response documentation automatically via the provided following model parser:
+
+```ruby
+# FastJsonapi serializer example
+# app/serializers/user_serializer.rb
+class UserSerializer
+ include FastJsonapi::ObjectSerializer
+
+ set_type :user
+ has_many :orders
+
+ attributes :name, :email
+end
+
+# config/initializers/grape_swagger.rb
+GrapeSwagger.model_parsers.register(GrapeSwagger::FastJsonapi::Parser, UserSerializer)
+
+# Your grape API endpoint
+desc 'Get current user',
+ success: { code: 200, model: UserSerializer, message: 'The current user' }
+# [...]
+```
+
+Note that you **need** the `grape-swagger` gem for this to work, otherwise it will throw an error.
## Credit
Code adapted from [grape-jsonapi-resources](https://github.com/cdunn/grape-jsonapi-resources)