Guest User

grape swag

a guest
Nov 28th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.78 KB | None | 0 0
  1.   # Entity
  2.   module API
  3.   module Entities
  4.     class Article < Grape::Entity
  5.       expose :title, documentation: { type: 'string', desc: 'Title' }
  6.       expose :body, documentation: { type: 'string', desc: 'Body' }
  7.     end
  8.   end
  9. end
  10.  
  11.   # API
  12.   desc "Create an article"
  13.   params do
  14.     requires :article, type: API::Entities::Article, documentation: { example: "aklsdfj" }
  15.   end
  16.   post '/articles' do
  17.     puts params
  18.     article = Article.create(params(:title, :body))
  19.     represent(article, env)
  20.   end
  21.  
  22.   # Add Swagger Docs
  23.   add_swagger_documentation mount_path: 'api/doc',
  24.     api_version: 'v1',
  25.     markdown: GrapeSwagger::Markdown::KramdownAdapter,
  26.     hide_documentation_path: true,
  27.     base_path: Application.config.base_path,
  28.     models: [API::Entities::Article]
Advertisement
Add Comment
Please, Sign In to add comment