I'm using grape-swagger gem to produce swagger documentation for dredd.
I have such params:
params do
requires :id, type: Integer, documentation: { x: { example: 1 } }
end
Grape swagger ignores example param.
Instead of this:
{
"in": "path",
"name": "id",
"type": "integer",
"format": "int32",
"required": true,
"x-example": 1
}
I got this:
{
"in": "path",
"name": "id",
"type": "integer",
"format": "int32",
"required": true
}
How to send example values for test purposes?
I found this in dredd issues. This solves my problem. In a nutshell, the solution looks like 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
Now,I can proxy example value to params body with this:
expose :some, documentation: { example: 'test' }