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

Add support for documentation fields #4

Open
dblock opened this issue Jul 29, 2014 · 5 comments
Open

Add support for documentation fields #4

dblock opened this issue Jul 29, 2014 · 5 comments

Comments

@dblock
Copy link
Member

dblock commented Jul 29, 2014

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
@taybin
Copy link

taybin commented Jul 31, 2014

@dblock
Copy link
Member Author

dblock commented Jul 31, 2014

@taybin Mostly, yes.

@danielkummer
Copy link

How can I use your code to document the swagger model - I can't really get it to work. The representer shows up in the grape documentation but both type and description are missing for the defined properties…

Update: Got it! The documentation method has to look like this (the documentation values are stored under attribute[:documentation]):

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

@dblock
Copy link
Member Author

dblock commented Oct 10, 2014

Would love it if someone turned this into production code :)

@sebweaver
Copy link

👍

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

No branches or pull requests

4 participants