File tree Expand file tree Collapse file tree 5 files changed +32
-0
lines changed Expand file tree Collapse file tree 5 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ def self.deprecator
7575
7676 configure do |config |
7777 config . param_builder = :hash_with_indifferent_access
78+ config . lint_api = false
7879 config . compile_methods!
7980 end
8081end
Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ def do_not_route_options!
8181 namespace_inheritable ( :do_not_route_options , true )
8282 end
8383
84+ def lint_api!
85+ namespace_inheritable ( :lint_api , true )
86+ end
87+
8488 def do_not_document!
8589 namespace_inheritable ( :do_not_document , true )
8690 end
Original file line number Diff line number Diff line change @@ -358,6 +358,7 @@ def build_stack(helpers)
358358 format = namespace_inheritable ( :format )
359359
360360 stack . use Rack ::Head
361+ stack . use Rack ::Lint if lint_api?
361362 stack . use Class . new ( Grape ::Middleware ::Error ) ,
362363 helpers : helpers ,
363364 format : format ,
@@ -408,5 +409,9 @@ def build_response_cookies
408409 Rack ::Utils . set_cookie_header! header , name , cookie_value
409410 end
410411 end
412+
413+ def lint_api?
414+ namespace_inheritable ( :lint_api ) || Grape . config . lint_api
415+ end
411416 end
412417end
Original file line number Diff line number Diff line change @@ -4738,4 +4738,25 @@ def uniqe_id_route
47384738 expect ( last_response . body ) . to eq ( 'unknown params_builder: unknown' )
47394739 end
47404740 end
4741+
4742+ describe '.lint_api!' do
4743+ let ( :app ) do
4744+ Class . new ( described_class ) do
4745+ lint_api!
4746+ get '/' do
4747+ status 42
4748+ end
4749+ end
4750+ end
4751+
4752+ around do |example |
4753+ Grape . config . lint_api = false
4754+ example . run
4755+ Grape . config . lint_api = true
4756+ end
4757+
4758+ it 'raises a Rack::Lint error' do
4759+ expect { get '/' } . to raise_error ( Rack ::Lint ::LintError , 'Status must be an Integer >=100' )
4760+ end
4761+ end
47414762end
Original file line number Diff line number Diff line change 1313 end
1414end
1515
16+ Grape . config . lint_api = true # lint all apis by default
1617Grape ::Util ::Registry . include ( Deregister )
1718# issue with ruby 2.7 with ^. We need to extend it again
1819Grape ::Validations . extend ( Grape ::Util ::Registry ) if Gem ::Version . new ( RUBY_VERSION ) . release < Gem ::Version . new ( '3.0' )
You can’t perform that action at this time.
0 commit comments