如何在我的rswag规范中添加一个自定义参数?
似乎只使用作为字段存在的参数。
但我需要添加一个自定义参数。因此,无论我做什么,我都可以在控制器中看到,,params,,只有我的模型的字段。
RSpec.describe Api::V1::LogsController, type: :request do
path '/api/v1/logs' do
post 'Create a Log' do
tags 'Logs'
security [ApiKeyAuth: {}]
consumes 'application/json'
produces 'application/json'
parameter name: :log, in: :body, schema: {
type: :object,
properties: {
title: { type: :string },
description: { type: :string },
my_custom_parameter: { type: :string }
},
required: %w(title description user_phone_number),
}
response '200', 'New Log created' do
let(:Authorization) { "Token token=#{company.api_key}" }
run_test!
end
end
end
end发布于 2019-11-26 12:30:25
您可以添加任何您喜欢的名称的参数,然后可以在响应块中为这些参数赋值,如下所示:
parameter name: :params, in: :body, schema: {
type: :object,
properties: {
profile_attributes: {
type: :object,
properties: {
email: { type: :string, example: Faker::Internet.email(Faker::Name.first_name) }
},
required: %w[email]
}
response('201', 'successfully') do
let(:params) do
{
profile_attributes: { email: Faker::Internet.email(Faker::Name.first_name) }
}
endhttps://stackoverflow.com/questions/58365339
复制相似问题