0

我正在使用grape-swagger gem 为dredd 制作swagger 文档。

我有这样的参数:

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

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

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

我懂了:

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

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

4

1 回答 1

0

我在 dredd 问题中发现了这一点。这解决了我的问题。简而言之,解决方案如下所示:

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

现在,我可以使用以下方法将示例值代理到参数正文:

expose :some, documentation: { example: 'test' }
于 2020-06-29T10:44:33.347 回答