Rswag: Missing body parameters

Created on 6 Feb 2019  路  1Comment  路  Source: rswag/rswag

Here is my example:

require 'swagger_helper'

describe 'Sessions API', swagger_doc: 'carmen/v1/swagger.json' do
  path '/session' do
    post 'Creates a session' do
      tags 'Sessions'
      parameter name: :user, in: :body, schema: {
        '$ref' => '#/definitions/user'
      }

      response '201', 'session created' do
        let(:user) do
          { email: '[email protected]', password: 'Test1234' }
        end
        run_test!
      end
    end
  end
end

When executing the spec user params are missing on the server:

(byebug) params
<ActionController::Parameters {"controller"=>"api/platform/carmen/v1/sessions", "action"=>"create"} permitted: false>

Swagger root configuration:

config.swagger_docs = {
  'carmen/v1/swagger.json' => {
    swagger: '2.0',
    info: {
      title: 'Carmen API V1',
      version: 'v1'
    },
    consumes: 'application/json',
    produces: 'application/json',
    paths: {},
    host: Settings.host('api'),
    basePath: '/platform/carmen/v1',
    securityDefinitions: {
      apiKey: {
        type: :apiKey,
        name: 'api_key',
        in:   :header
      }
    },
    definitions: {
      user: {
        type:       :object,
        properties: {
          email:    { type: :string },
          password: { type: :string }
        },
        required:   ['email', 'password']
      }
    }
  }
}

rails 5.1.6
rswag-specs 2.0.5
rspec-rails 3.8.2

Most helpful comment

I noticed request content type was "a", so I figured out my problem was that I had:

consumes: 'application/json',
produces: 'application/json',

Should be:

consumes: ['application/json'],
produces: ['application/json'],

Looks like somewhere in the code it calls root[:consumes].first.

>All comments

I noticed request content type was "a", so I figured out my problem was that I had:

consumes: 'application/json',
produces: 'application/json',

Should be:

consumes: ['application/json'],
produces: ['application/json'],

Looks like somewhere in the code it calls root[:consumes].first.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnmcdowall picture johnmcdowall  路  5Comments

martio picture martio  路  4Comments

nicwillemse picture nicwillemse  路  4Comments

PhilippeChab picture PhilippeChab  路  4Comments

zlesnr picture zlesnr  路  4Comments