首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在RSWAG请求参数中添加组件?

如何在RSWAG请求参数中添加组件?
EN

Stack Overflow用户
提问于 2020-02-18 19:54:56
回答 2查看 652关注 0票数 0

我有一些公共参数,这些参数在几乎所有的API调用中都会被调用,所以是否可以为这些参数创建组件并在rswag请求中调用它们。

schema '$ref' => '#/definitions/parameters'这样的东西

谢谢!

EN

回答 2

Stack Overflow用户

发布于 2020-07-15 02:45:23

添加到您的swagger_helper.rb

示例:

代码语言:javascript
复制
# spec/swagger_helper.rb
config.swagger_docs = {
  'v1/swagger.json' => {
    swagger: '2.0',
    info: {
      title: 'API V1'
    },
    definitions: {
      errors_object: {
        type: 'object',
        properties: {
          errors: { '$ref' => '#/definitions/errors_map' }
        }
      },
      errors_map: {
        type: 'object',
        additionalProperties: {
          type: 'array',
          items: { type: 'string' }
        }
      }
    }
  }
}

# spec/integration/blogs_spec.rb
describe 'Blogs API' do

  path '/blogs' do

    post 'Creates a blog' do

      response 422, 'invalid request' do
        schema '$ref' => '#/definitions/errors_object'
  ...
end

# spec/integration/comments_spec.rb
describe 'Blogs API' do

  path '/blogs/{blog_id}/comments' do

    post 'Creates a comment' do

      response 422, 'invalid request' do
        schema '$ref' => '#/definitions/errors_object'
  ...
end

来自:https://www.rubydoc.info/github/domaindrivendev/rswag#referenced-parameters-and-schema-definitions

票数 0
EN

Stack Overflow用户

发布于 2021-02-06 00:34:51

您需要在spec/swagger_helper.rb中定义对象,然后在集成规范文件中定义

代码语言:javascript
复制
path '/api/client/v0/blog' do
put 'Create a blog' do
  tags :Blog

  include_examples 'header_with_recognition_definitions'

  parameter name: :input_param, in: :body, schema: { '$ref' => '#/definitions/input_parameter_object' }

  response 200, 'blog was created successfully' do
    include_examples 'header_with_recognition_lets'
     ...
    run_test!
  end
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60280341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档