Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grape Entity Support #54

Merged

Conversation

calebwoods
Copy link
Contributor

Inspired by the on pull request #30 by @TLmaK0, this pull request adds support for generating swagger responseClass and models per the Swagger API Declaration based on Grape Entities.

Usage would look like the following

module API

  module Entities
    class Status < Grape::Entity
      expose :text, :documentation => { :type => "string", :desc => "Status update text." }
    end
  end

  class Statuses < Grape::API
    version 'v1'

    desc 'Statuses index', {
      :entity => API::Entities::Status
    }
    get '/statuses' do
      statuses = Status.all
      type = current_user.admin? ? :full : :default
      present statuses, with: API::Entities::Status, :type => type
    end
  end
end

And would generate the following swagger json

{
  "apiVersion": "0.2",
  "swaggerVersion": "1.1",
  "basePath": [..],
  "resourcePath": "/statuses.{format}"

  ...

  "apis" : [...]
  "models": {
    "Status": {
      "id": "Status",
      "name" : "Status",
      "properties": {
         "text": {
           "type": "string",
            "desc": "Status update text."
         }
      }
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants