I was tempted to use rswag with rspec to document REST API and write test at the same time.
I am trying to fallow tutorials and documentations but I cannot get sign\_in endpoint working ( [devise - session](https://github.com/heartcombo/devise/blob/master/app/controllers/devise/sessions_controller.rb#L17) ).

When I do run rspec than I receive status code error.

```
require 'swagger_helper'
require 'rails_helper'
require 'shared_context'

describe 'Sonaaar REST API', type: :request do

...

  path '/users/sign_in' do
    post 'Sign In' do
      tags 'Session'
      consumes 'application/json'
      produces 'application/json'
      parameter name: :user, in: :body, schema: {
        type: :object,
        properties: {
          email: { type: :string },
          password: { type: :string },
        },
        required: ['email', 'password']
      }

     response '201', 'sign in', { 'HTTP_ACCEPT' => "application/json" } do
         response '201', 'sign in', { 'HTTP_ACCEPT' => "application/json" } do
        #
        # let(:user) do
        #   create(:user,  email: 'email@domain.com', password: 'Password1')
        # end
        #Error
        # Failure/Error:
        #        raise UnexpectedResponse,
        #          "Expected response code '#{response.code}' to match '#{expected}'\n" \
        #            "Response body: #{response.body}"
        #
        #      Rswag::Specs::UnexpectedResponse:
        #        Expected response code '401' to match '201'
        #        Response body: {"error":"You need to sign in or sign up before continuing."}

        let(:user) { { user: { login: 'email@domain.com', password: 'Password1' } } }
        # Rswag::Specs::UnexpectedResponse:
        #   Expected response code '401' to match '201'
        #   Response body: {"error":"You need to sign in or sign up before continuing."}
        #   /Users/filip/.rvm/gems/ruby-2.7.1/gems/rswag-specs-2.4.0/lib/rswag/specs/r
        run_test!
      end

```

Than i do have RSpec error:

```
1) Sonaaar REST API /users/sign_in post sign in returns a 201 response
     Failure/Error:
       raise UnexpectedResponse,
         "Expected response code '#{response.code}' to match '#{expected}'\n" \
           "Response body: #{response.body}"

     Rswag::Specs::UnexpectedResponse:
       Expected response code '401' to match '201'
       Response body: {"error":"You need to sign in or sign up before continuing."}

```

Authentication: JWT-token
Content Type: application/json
Stack/Gems:

* Ruby on Rails (Rails 6.1.2.1)
* devise (4.7.3)
* devise-jwt (0.7.0)
* rspec-rails (4.0.2)
* rswag (2.4.0) - <https://github.com/rswag/rswag>