Sha256: a87556ee5c972d64869e4a5500da8804a4d520481d98613c06cfbd7586b5a45f

Contents?: true

Size: 1.54 KB

Versions: 7

Compression:

Stored size: 1.54 KB

Contents

require 'grape-swagger'
require 'active_support' #/core_ext/module/aliasing'
require 'camel_snake_keys'

if IntrospectiveGrape.config.camelize_parameters 
  # Camelize the parameters in the swagger documentation.
  if Gem::Version.new( GrapeSwagger::VERSION ) <= Gem::Version.new('0.11.0')
    Grape::API.class_eval do 
      class << self
        private
        def create_documentation_class_with_camelized
          doc = create_documentation_class_without_camelized
          doc.class_eval do
            class << self
              def parse_params_with_camelized(params, path, method, _options = {})
                parsed_params = parse_params_without_camelized(params, path, method)
                parsed_params.each_with_index do |param|
                  param[:name] = param[:name]
                                 .camelize(:lower)
                                 .gsub(/Destroy/,'_destroy')
                end
                parsed_params
              end

              alias_method_chain :parse_params, :camelized
            end
          end
          doc
        end
        alias_method_chain :create_documentation_class, :camelized
      end
    end
  else Gem::Version.new( GrapeSwagger::VERSION ) > Gem::Version.new('0.11.0')
    # Grape::Swagger 0.20.xx is not yet compatible with Grape >0.14 and will alter
    # the way it parses params, so will not be compatible with introspective_grape,
    # and produces swagger docs for SwaggerUI 2.1.4 that don't appear to be
    # backwards compatible swagger.js 2.0.41, so this is pending.
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
introspective_grape-0.2.6 lib/introspective_grape/camel_snake.rb
introspective_grape-0.2.5 lib/introspective_grape/camel_snake.rb
introspective_grape-0.2.4 lib/introspective_grape/camel_snake.rb
introspective_grape-0.2.3 lib/introspective_grape/camel_snake.rb
introspective_grape-0.2.2 lib/introspective_grape/camel_snake.rb
introspective_grape-0.2.0 lib/introspective_grape/camel_snake.rb
introspective_grape-0.1.9 lib/introspective_grape/camel_snake.rb