Forum Discussion

cookie's avatar
cookie
Occasional Visitor
5 years ago

Return data from database rather than static json

I'm using swagger-blocks: https://github.com/fotinakis/swagger-blocks The following:

swagger_path '/articles' do
                operation :get do
                    key :summary, 'Display all articles'
                    response 200 do
                        key :description, ''
                        schema do
                            property :title do
                                key :type, :string
                            end
                            property :body do
                                key :type, :string
                            end
                        end
                    end
                end
            end

returns json like thus:

{
  "title": "string",
  "body": "string"
}

That's great but what I really want is to return data from my database rather than static json - using a call to active record like thus:

def index
                articles = Article.order('created_at DESC')
                render json: {status: 'SUCCESS', message: 'loaded articles', data: articles}, status: :OK
            end

I'm using Swagger v2. Are you able to help me with a swagger_path definition/code syntax i.e.?

swagger_path '/articles' do
   response 200 do
     // Get database results here...
   end
end

Thanks in advance.

No RepliesBe the first to reply