【问题标题】:Grape Swagger does not show up Example paramGrape Swagger 不显示示例参数
【发布时间】:2020-06-26 15:44:56
【问题描述】:

我正在使用grape-swagger gem 为dredd 生成swagger 文档。

我有这样的参数:

params do
  requires :id, type: Integer, documentation: { x: { example: 1 } }
end

Grape swagger 忽略 example 参数。
而不是这个:

{
  "in": "path",
  "name": "id",
  "type": "integer",
  "format": "int32",
  "required": true,
  "x-example": 1
}

我知道了:

{
  "in": "path",
  "name": "id",
  "type": "integer",
  "format": "int32",
  "required": true
}

如何发送示例值用于测试目的?

【问题讨论】:

    标签: swagger grape dredd


    【解决方案1】:

    我在 dredd 问题中找到了 this。这解决了我的问题。 简而言之,解决方案如下所示:

    module MyApp
      module AddExampleToBodyParam
        module ClassMethods
          private
    
          def document_description(settings)
            super
            @parsed_param[:example] = settings[:example] if settings[:example]
          end
        end
    
        def self.prepended(base)
          class << base
            prepend ClassMethods
          end
        end
      end
    end
    
    module GrapeSwagger
      module DocMethods
        class ParseParams
          prepend MyApp::AddExampleToBodyParam
        end
      end
    end
    

    现在,我可以将 example 值代理到参数正文:

    expose :some, documentation: { example: 'test' }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-30
      • 1970-01-01
      相关资源
      最近更新 更多