ruby-on-railsrspecruby-on-rails-5rspec-railsrswag

rswag gem does not recognize my parameters in rspec


when running RSpec, in the action of controller,(use byebug or pry) the specific value like (email or password) did not exist in the request parameters, and so the result of the test become failed for more details, see my below code

  path '/api/v1/admin/authentications/sign_in' do
    post('admin sign_in') do
      produces 'application/json'
      parameter name: :params, in: :body, schema: {
        type: :object,
        properties: {
          email: { type: :string },
          password: { type: :string }
        },
        required: %w[email password]
      }

      let(:admin) { create(:admin) }
      response('200', 'sign in successfully') do
        let(:params) { { email: admin.email, password: '***' } }
        run_test!
      end
    end
  end

Solution

  • add consume type for your request:

    consumes 'application/json'