葡萄招摇没有显示示例参数



我正在使用葡萄招摇的宝石来为疏浚制作招摇的文档。

我有这样的参数:

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

葡萄招摇忽略示例param.
而不是这个:

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

我得到了这个:

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

如何发送示例值以进行测试?

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

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' }

最新更新