grape-swagger icon indicating copy to clipboard operation
grape-swagger copied to clipboard

Regression w/ Model parser for Grape::Roar::Representer

Open dblock opened this issue 7 years ago • 1 comments

In a much older version of grape-swagger this used to work:

models: [
  Presenters::ApplicationPresenter
]

where

    module Presenters
      module ApplicationPresenter
        include Roar::JSON::HAL
        include Roar::Hypermedia
        include Grape::Roar::Representer

        property :id, type: String, desc: 'Application id.', writeable: false
        ...
      end
    end
  end
end

Even with grape-swagger-representable I am getting:

type: "other_error",
message: "No parser registered for ApplicationPresenter.",
backtrace: [
"/Users/dblock/.rvm/gems/ruby-2.3.7/bundler/gems/grape-swagger-34c969d71899/lib/grape-swagger/endpoint.rb:329:in `expose_params_from_model'",
"/Users/dblock/.rvm/gems/ruby-2.3.7/bundler/gems/grape-swagger-34c969d71899/lib/grape-swagger/endpoint.rb:93:in `block in add_definitions_from'",
"/Users/dblock/.rvm/gems/ruby-2.3.7/bundler/gems/grape-swagger-34c969d71899/lib/grape-swagger/endpoint.rb:93:in `each'",
"/Users/dblock/.rvm/gems/ruby-2.3.7/bundler/gems/grape-swagger-34c969d71899/lib/grape-swagger/endpoint.rb:93:in `add_definitions_from'",
"/Users/dblock/.rvm/gems/ruby-2.3.7/bundler/gems/grape-swagger-34c969d71899/lib/grape-swagger/endpoint.rb:86:in `path_and_definition_objects'",
"/Users/dblock/.rvm/gems/ruby-2.3.7/bundler/gems/grape-swagger-34c969d71899/lib/grape-swagger/doc_methods.rb:57:in `block in setup'",
"/Users/dblock/.rvm/gems/ruby-2.3.7/bundler/gems/grape-swagger-34c969d71899/lib/grape-swagger/doc_methods.rb:71:in `block in setup'",
"/Users/dblock/.rvm/gems/ruby-2.3.7/gems/grape-0.17.0/lib/grape/endpoint.rb:59:in `call'",

dblock avatar Sep 29 '18 20:09 dblock

Looks like, ancestors doesn't contains: Representable::Decorator

Presenters::ApplicationPresenter.ancestors
=> [Presenters::ApplicationPresenter, Grape::Roar::Representer, Roar::JSON::HAL::LinksReader, Roar::JSON::HAL::Resources, Roar::JSON::HAL::Links::InstanceMethods, Roar::Hypermedia, Roar::JSON::HAL::Links, Roar::JSON::InstanceMethods, Representable::JSON, Representable, Representable::Hash, Roar::Representer, Roar::JSON, Roar::JSON::HAL]

grape-swagger-representable, doesn't support's roar, but roar builded on representable, no warranty this should works. You can try to set representable parser for grape-roar before API initialization:

GrapeSwagger.model_parsers.register(::GrapeSwagger::Representable::Parser, ::Grape::Roar::Representer)

kzaitsev avatar Sep 29 '18 20:09 kzaitsev