Skip to content

Instantly share code, notes, and snippets.

@T-Dnzt
Last active April 21, 2016 05:20
Show Gist options
  • Save T-Dnzt/3ad80984329a9dd67a2f7ee1c35ed6d6 to your computer and use it in GitHub Desktop.
Save T-Dnzt/3ad80984329a9dd67a2f7ee1c35ed6d6 to your computer and use it in GitHub Desktop.
Extract APIPIE documentation from your controllers
# api/documentation/spaceships/index.rb
module Api::Documentation::Spaceships::Index
extend ActiveSupport::Concern
included do
api :GET, "/api/spaceships", "Get a list of awesome spaceships!"
param :limit, Integer, desc: "How many awesome spaceships do you want?"
param :offset, Integer, desc: "By how many awesome spaceships do you want to offset your query?"
error code: 404, desc: "Spaceship not found! Must have been destroyed."
error code: 500, desc: "Unplanned Alien invasion reduced our spaceships fleet..."
description "This API endpoint is used to retrieve awesome spaceships, nothing less."
formats ['json']
example 'blabla'
end
end
# api/spaceships_controller.rb
class Api::SpaceshipsController < ApplicationController
resource_description do
short "Awesome spaceships!"
end
include Api::Documentation::Spaceships::Index
def index
# Do something cool with your spaceships!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment