-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support excluding optional parameters from documentation (#463)
- Loading branch information
Showing
6 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require 'spec_helper' | ||
|
||
describe 'hidden flag enables a single endpoint parameter to be excluded from the documentation' do | ||
include_context "#{MODEL_PARSER} swagger example" | ||
before :all do | ||
module TheApi | ||
class HideParamsApi < Grape::API | ||
namespace :flat_params_endpoint do | ||
desc 'This is a endpoint with a flat parameter hierarchy' | ||
params do | ||
requires :name, type: String, documentation: { desc: 'name' } | ||
optional :favourite_color, type: String, documentation: { desc: 'I should not be anywhere', hidden: true } | ||
optional :proc_param, type: String, documentation: { desc: 'I should not be anywhere', hidden: -> { true } } | ||
end | ||
|
||
post do | ||
{ 'declared_params' => declared(params) } | ||
end | ||
end | ||
|
||
namespace :nested_params_endpoint do | ||
desc 'This is a endpoint with a nested parameter hierarchy' | ||
params do | ||
optional :name, type: String, documentation: { desc: 'name' } | ||
optional :hidden_attribute, type: Hash do | ||
optional :favourite_color, type: String, documentation: { desc: 'I should not be anywhere', hidden: true } | ||
end | ||
|
||
optional :attributes, type: Hash do | ||
optional :attribute_1, type: String, documentation: { desc: 'Attribute one' } | ||
optional :hidden_attribute, type: String, documentation: { desc: 'I should not be anywhere', hidden: true } | ||
end | ||
end | ||
|
||
post do | ||
{ 'declared_params' => declared(params) } | ||
end | ||
end | ||
|
||
namespace :required_param_endpoint do | ||
desc 'This endpoint has hidden defined for a required parameter' | ||
params do | ||
requires :name, type: String, documentation: { desc: 'name', hidden: true } | ||
end | ||
|
||
post do | ||
{ 'declared_params' => declared(params) } | ||
end | ||
end | ||
|
||
add_swagger_documentation | ||
end | ||
end | ||
end | ||
|
||
let(:app) { TheApi::HideParamsApi } | ||
|
||
describe 'simple flat parameter hierarchy' do | ||
subject do | ||
get '/swagger_doc/flat_params_endpoint' | ||
JSON.parse(last_response.body) | ||
end | ||
|
||
specify do | ||
expect(subject['paths']['/flat_params_endpoint']['post']['parameters'].map { |p| p['name'] }).not_to include('favourite_color', 'proc_param') | ||
end | ||
end | ||
|
||
describe 'nested parameter hierarchy' do | ||
subject do | ||
get '/swagger_doc/nested_params_endpoint' | ||
JSON.parse(last_response.body) | ||
end | ||
|
||
specify do | ||
expect(subject['paths']['/nested_params_endpoint']['post']['parameters'].map { |p| p['name'] }).not_to include(/hidden_attribute/) | ||
end | ||
end | ||
|
||
describe 'hidden defined for required parameter' do | ||
subject do | ||
get '/swagger_doc/required_param_endpoint' | ||
JSON.parse(last_response.body) | ||
end | ||
|
||
specify do | ||
expect(subject['paths']['/required_param_endpoint']['post']['parameters'].map { |p| p['name'] }).to include('name') | ||
end | ||
end | ||
end |