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

Invalid Swagger Schema - Delete

Open lstanden opened this issue 7 years ago • 4 comments

The following example method creates an invalid schema:

params do
  options :test_ids, type: Array[String], documentation: { param_type: 'body' }
  options :rest_ids, type: Array[String], documentation: { param_type: 'body' }
end
delete do
  # ...
end

lstanden avatar Sep 27 '18 21:09 lstanden

The schema contains multiple in: "body" records, which is invalid for the swagger schema. It should have been extracted out to a ref.

lstanden avatar Sep 27 '18 21:09 lstanden

I added the following monkey patch to my app, and it appears to resolve the invalid schema issues. It seems the logic is simply flawed in these existing methods:

module GrapeSwagger
  module DocMethods
    class MoveParams
      class << self
        def can_be_moved?(params, http_verb)
          includes_body_param?(params)
        end

        def should_expose_as_array?(params)
          false
        end

        def should_correct_array?(param)
          false
        end
      end
    end
  end
end

lstanden avatar Sep 28 '18 21:09 lstanden

@lstanden The multiple in: 'body' are combined in GrapeSwagger::DocMethods::MoveParams , which not support delete method. https://github.com/ruby-grape/grape-swagger/blob/8e4a39cea858ea336f27814d433ee5b3996108a2/lib/grape-swagger/doc_methods/move_params.rb#L218-L220

darren987469 avatar Oct 01 '18 08:10 darren987469

Yes, I'm aware of this @darren987469 ... by not having DELETE included, it is generating invalid swagger schema.

lstanden avatar Oct 01 '18 10:10 lstanden