Add Extensions for Params (#785)
* Add Extensions for Params * Add Documentation for `x:` in params * Remove require `pry`
This commit is contained in:
parent
498246ee20
commit
077a27441f
|
@ -3,6 +3,7 @@
|
|||
#### Features
|
||||
|
||||
* Your contribution here.
|
||||
* [#785](https://github.com/ruby-grape/grape-swagger/pull/785): Add extensions for params - [@MaximeRDY](https://github.com/MaximeRDY).
|
||||
* [#782](https://github.com/ruby-grape/grape-swagger/pull/782): Allow passing class name as string for rake task initializer - [@misdoro](https://github.com/misdoro).
|
||||
|
||||
|
||||
|
|
14
README.md
14
README.md
|
@ -1084,6 +1084,20 @@ or, for more definitions:
|
|||
route_setting :x_def, [{ for: 422, other: 'stuff' }, { for: 200, some: 'stuff' }]
|
||||
```
|
||||
|
||||
- `params` extension, add a `x` key to the `documentation` hash :
|
||||
```ruby
|
||||
requires :foo, type: String, documentation: { x: { some: 'stuff' } }
|
||||
```
|
||||
this would generate:
|
||||
```json
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "foo",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"x-some": "stuff"
|
||||
}
|
||||
```
|
||||
|
||||
#### Response examples documentation <a name="response-examples"></a>
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ module GrapeSwagger
|
|||
document_range_values(settings) unless value_type[:is_array]
|
||||
document_required(settings)
|
||||
document_additional_properties(settings)
|
||||
document_add_extensions(settings)
|
||||
|
||||
@parsed_param
|
||||
end
|
||||
|
@ -62,6 +63,10 @@ module GrapeSwagger
|
|||
@parsed_param[:format] = settings[:format] if settings[:format].present?
|
||||
end
|
||||
|
||||
def document_add_extensions(settings)
|
||||
GrapeSwagger::DocMethods::Extensions.add_extensions_to_root(settings, @parsed_param)
|
||||
end
|
||||
|
||||
def document_array_param(value_type, definitions)
|
||||
if value_type[:documentation].present?
|
||||
param_type = value_type[:documentation][:param_type]
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe '#532 allow custom format' do
|
||||
let(:app) do
|
||||
Class.new(Grape::API) do
|
||||
namespace :issue_784 do
|
||||
params do
|
||||
requires :logs, type: String, documentation: { format: 'log', x: { name: 'Log' } }
|
||||
optional :phone_number, type: Integer, documentation: { format: 'phone_number', x: { name: 'PhoneNumber' } }
|
||||
end
|
||||
|
||||
post do
|
||||
present params
|
||||
end
|
||||
end
|
||||
|
||||
add_swagger_documentation format: :json
|
||||
end
|
||||
end
|
||||
|
||||
subject do
|
||||
get '/swagger_doc'
|
||||
JSON.parse(last_response.body)
|
||||
end
|
||||
|
||||
let(:parameters) { subject['paths']['/issue_784']['post']['parameters'] }
|
||||
|
||||
specify do
|
||||
expect(parameters).to eql(
|
||||
[
|
||||
{ 'in' => 'formData', 'name' => 'logs', 'type' => 'string', 'format' => 'log', 'required' => true, 'x-name' => 'Log' },
|
||||
{ 'in' => 'formData', 'name' => 'phone_number', 'type' => 'integer', 'format' => 'phone_number', 'required' => false, 'x-name' => 'PhoneNumber' }
|
||||
]
|
||||
)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue