ruby-on-rails - rails gem rswag 自定义参数
问题描述
如何在我的 rswag 规范中添加自定义参数?
Rswag 似乎只包含作为字段存在的参数
但我需要添加一个自定义参数。所以无论我做什么 - 我只能在控制器参数中看到我的模型的字段。
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
解决方案
您可以使用您喜欢的任何名称添加任何参数,然后您可以在响应块中为这些参数赋值,如下所示:
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) }
}
end
推荐阅读
- python - 无法通过 python paramiko 导航到 SFTP 目录
- java - AspectJ - 从另一个项目调用方面函数会引发 NoClassDefFoundError: org/aspectj/lang/JoinPoint
- spring - 将 Spring Vault 与 Hashicorp Vault 以外的 Vault Provider 一起使用
- typescript - 我想用打字稿上的其他类型将类型保护为 const
- node.js - setTimeout 函数 Object.assign 分配一个变量 - 但对变量的突变会带回原始变量
- mysql - mysql 在我的 macos 中没有盯着 xampp,我现在该怎么办?
- python - 在提交python Selenium时从模态中提取信息
- json - 通过将 dict2items 和 JMESPath 与 ansible 相结合,从复杂的 json 中查询键
- javascript - 在本机反应中需要正则表达式的替代解决方案吗?
- django - Django Admin:如何添加外键关系其他整数字段?