From 717c62e7795b8797b0cacc41e1a0f4fa34095063 Mon Sep 17 00:00:00 2001 From: dm1try Date: Fri, 13 Feb 2015 15:07:50 +0300 Subject: [PATCH 1/3] add the the failing spec for the issue which related to API with :path versioning so when you specify api "format" and use "path" versioning then "root" endpoints disapper from swagger docs related to grape >= 0.10.0 --- spec/api_with_path_versioning_spec.rb | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 spec/api_with_path_versioning_spec.rb diff --git a/spec/api_with_path_versioning_spec.rb b/spec/api_with_path_versioning_spec.rb new file mode 100644 index 00000000..54bfa314 --- /dev/null +++ b/spec/api_with_path_versioning_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe 'Api with "path" versioning' do + let(:json_body) { JSON.parse(last_response.body) } + + before :all do + class ApiWithPathVersioning < Grape::API + format :json + version 'v1', using: :path + + namespace :resources do + get + end + + add_swagger_documentation api_version: 'v1' + end + end + + def app + ApiWithPathVersioning + end + + it 'retrieves swagger-documentation on /swagger_doc that contains :resources api path' do + get '/v1/swagger_doc' + + expect(json_body['apis']).to eq( + [ + { 'path' => '/resources.{format}', 'description' => 'Operations about resources' }, + { 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' } + ] + ) + end +end From ea58020a33de6d42e11b4a49b066c6a026a6dbed Mon Sep 17 00:00:00 2001 From: Adam Weller Date: Tue, 20 Jan 2015 16:40:52 -0500 Subject: [PATCH 2/3] Match index routes that do not contain :format, as it has been explicitly declared in the resource, e.g., `format :json`. TODO: Add spec(s). --- lib/grape-swagger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grape-swagger.rb b/lib/grape-swagger.rb index 8661c88f..3d648b11 100644 --- a/lib/grape-swagger.rb +++ b/lib/grape-swagger.rb @@ -21,7 +21,7 @@ def add_swagger_documentation(options = {}) route_path = route.route_path route_match = route_path.split(/^.*?#{route.route_prefix.to_s}/).last next unless route_match - route_match = route_match.match('\/([\w|-]*?)[\.\/\(]') || route_match.match('\/([\w|-]*)') + route_match = route_match.match('\/([\w|-]*?)[\.\/\(]') || route_match.match('\/([\w|-]*)$') next unless route_match resource = route_match.captures.first next if resource.empty? From 10c0b945ac31265921a8a14b2d445e235584cfae Mon Sep 17 00:00:00 2001 From: dm1try Date: Fri, 13 Feb 2015 16:26:13 +0300 Subject: [PATCH 3/3] update CHANGELOG for #216 [ci skip] --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a590ab7e..919cad1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ### Next Release + * [#214](https://github.com/tim-vandecasteele/grape-swagger/pull/214): Allow anything that responds to `call` to be used in `:hidden` - [@zbelzer](https://github.com/zbelzer). * [#211](https://github.com/tim-vandecasteele/grape-swagger/pull/211): Fixed the dependency, just `require 'grape'` - [@u2](https://github.com/u2). * [#210](https://github.com/tim-vandecasteele/grape-swagger/pull/210): Fixed the range `:values` option, now exposed as `enum` parameters - [@u2](https://github.com/u2). @@ -6,6 +7,11 @@ * [#196](https://github.com/tim-vandecasteele/grape-swagger/pull/196): If `:type` is omitted, see if it's available in `:using` - [@jhollinger](https://github.com/jhollinger). * [#200](https://github.com/tim-vandecasteele/grape-swagger/pull/200): Treat `type: Symbol` as string form parameter - [@ypresto](https://github.com/ypresto). * [#207](https://github.com/tim-vandecasteele/grape-swagger/pull/207): Support grape `mutually_exclusive` - [@mintuhouse](https://github.com/mintuhouse). + +#### Fixes + +* [#216](https://github.com/tim-vandecasteele/grape-swagger/pull/216): Fix API route paths matching. This prevents the disappearance of the documentation for root endpoints in case you are using `grape ~> 0.10.0`, specific `format` and `:path` versioning. Fixes [#192](https://github.com/tim-vandecasteele/grape-swagger/issues/192), [#189](https://github.com/tim-vandecasteele/grape-swagger/issues/189). - [@dm1try](https://github.com/dm1try) [@minch](https://github.com/minch) + * Your contribution here. ### 0.9.0 (December 19, 2014)