ruby-grape / ruby-grape/grape-roar

Add support for documentation fields

Open
#4 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discuss! new feature
Dominant language
Ruby
Stars
59
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Grape exposures give you entity_name, exposures and documentation. We can add those for out-of-the-box support for https://github.com/tim-vandecasteele/grape-swagger.

module Grape
  module Roar
    module Representer
      def self.included(base)
        base.extend(ClassMethods)
      end

      module ClassMethods
        def entity_name
          self.name.split('::').last.gsub(/Presenter$/, '')
        end

        def exposures
          {}
        end

        def documentation
          Hash[representable_attrs.map do |attribute|
            property_name = attribute[:as].evaluate nil, nil
            next if property_name == '_links'
            [ property_name, { desc: attribute[:desc], type: attribute[:type] }]
          end.compact]
        end
      end
    end
  end
end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Grape::Roar::Representer::ClassMethods and compare the existing representer behavior with the proposed entity_name, exposures, and documentation entry points. Check how grape-swagger consumes these fields, then add coverage for the three fields, including the documented _links exclusion. Done means out-of-the-box grape-swagger support works for Grape exposures.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, documentation
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.