Sha256: 764ad3e554a18b3b27aa30ce862e970cfda2ae2f5b32873afd17543d943d8757

Contents?: true

Size: 1.29 KB

Versions: 24

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe 'mount override api' do
  def app
    old_api = Class.new(Grape::API) do
      desc 'old endpoint', success: { code: 200, message: 'old message' }
      params do
        optional :param, type: Integer, desc: 'old param'
      end
      get do
        'old'
      end
    end

    new_api = Class.new(Grape::API) do
      desc 'new endpoint', success: { code: 200, message: 'new message' }
      params do
        optional :param, type: String, desc: 'new param'
      end
      get do
        'new'
      end
    end

    Class.new(Grape::API) do
      mount new_api
      mount old_api

      add_swagger_documentation format: :json
    end
  end

  context 'actual api request' do
    subject do
      get '/'
      last_response.body
    end

    it 'returns data from new endpoint' do
      is_expected.to eq 'new'
    end
  end

  context 'api documentation' do
    subject do
      get '/swagger_doc'
      JSON.parse(last_response.body)['paths']['/']['get']
    end

    it 'shows documentation from new endpoint' do
      expect(subject['parameters'][0]['description']).to eql('new param')
      expect(subject['parameters'][0]['type']).to eql('string')
      expect(subject['responses']['200']['description']).to eql('new message')
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
grape-swagger-1.6.1 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.6.0 spec/swagger_v2/mount_override_api_spec.rb
gitlab-grape-swagger-1.5.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.5.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.4.2 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.4.1 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.4.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.3.1 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.3.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.2.1 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.2.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.1.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-1.0.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-0.34.2 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-0.34.1 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-0.34.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-0.33.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-0.32.1 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-0.32.0 spec/swagger_v2/mount_override_api_spec.rb
grape-swagger-0.31.1 spec/swagger_v2/mount_override_api_spec.rb