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
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.
Most helpful comment
I noticed request content type was "a", so I figured out my problem was that I had:
Should be:
Looks like somewhere in the code it calls
root[:consumes].first.