From 70428799b8ec91d89589900c08eff4a00df457b4 Mon Sep 17 00:00:00 2001 From: Ji Zhou Date: Mon, 10 Aug 2015 11:41:30 +0800 Subject: [PATCH] make api doc `name` param recognizable by `declared` --- lib/grape-swagger/doc_methods.rb | 13 +++++-------- spec/api_description_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/grape-swagger/doc_methods.rb b/lib/grape-swagger/doc_methods.rb index 47430c06..d5ee3a3c 100644 --- a/lib/grape-swagger/doc_methods.rb +++ b/lib/grape-swagger/doc_methods.rb @@ -400,14 +400,11 @@ def setup(options) output end - desc specific_api_doc.delete(:desc), { params: { - 'name' => { - desc: 'Resource name of mounted API', - type: 'string', - required: true - } - }.merge(specific_api_doc.delete(:params) || {}) }.merge(specific_api_doc) - + desc specific_api_doc.delete(:desc), { params: + specific_api_doc.delete(:params) || {} }.merge(specific_api_doc) + params do + requires :name, type: String, desc: 'Resource name of mounted API' + end get "#{@@mount_path}/:name" do header['Access-Control-Allow-Origin'] = '*' header['Access-Control-Request-Method'] = '*' diff --git a/spec/api_description_spec.rb b/spec/api_description_spec.rb index dd3d541c..b9a1f572 100644 --- a/spec/api_description_spec.rb +++ b/spec/api_description_spec.rb @@ -14,7 +14,7 @@ expect(routes.first.route_description).to eq 'Swagger compatible API description' expect(routes.first.route_params).to eq({}) expect(routes.last.route_description).to eq 'Swagger compatible API description for specific API' - expect(routes.last.route_params).to eq('name' => { desc: 'Resource name of mounted API', type: 'string', required: true }) + expect(routes.last.route_params).to eq('name' => { desc: 'Resource name of mounted API', type: 'String', required: true }) end end @@ -34,7 +34,7 @@ expect(routes.first.route_params).to eq(x: 1) expect(routes.first.route_xx).to eq(11) expect(routes.last.route_description).to eq 'Second' - expect(routes.last.route_params).to eq('name' => { desc: 'Resource name of mounted API', type: 'string', required: true }, y: 42) + expect(routes.last.route_params).to eq('name' => { desc: 'Resource name of mounted API', type: 'String', required: true }, y: 42) expect(routes.last.route_yy).to eq(4242) end end