Skip to content

Commit e1b5df6

Browse files
LeFnordaka-momo
authored andcommitted
Fixes ruby-grape#809: supports UTF8 route names. (ruby-grape#811)
- adds changelog entry
1 parent 42c7cd7 commit e1b5df6

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Naming:
7373
Style/AccessorGrouping:
7474
Enabled: true
7575

76+
Style/AsciiComments:
77+
Enabled: false
78+
7679
Style/ArrayCoercion:
7780
Enabled: true
7881

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Fixes
88

99
* Your contribution here.
10+
* [#811](https://github.com/ruby-grape/grape-swagger/pull/811): Fixes #809: supports utf8 route names - [@LeFnord](https://github.com/LeFnord).
1011

1112

1213
### 1.3.0 (September 3, 2020)

lib/grape-swagger.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def combine_routes(app, doc_klass)
3030
route_match = route_path.split(/^.*?#{route.prefix}/).last
3131
next unless route_match
3232

33-
route_match = route_match.match('\/([\w|-]*?)[\.\/\(]') || route_match.match('\/([\w|-]*)$')
33+
# want to match emojis … ;)
34+
# route_match = route_match
35+
# .match('\/([\p{Alnum}|\p{Emoji}|\-|\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}|\p{Emoji}|\-|\_]*)$')
36+
route_match = route_match.match('\/([\p{Alnum}|\-|\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}|\-|\_]*)$')
3437
next unless route_match
3538

3639
resource = route_match.captures.first
@@ -86,7 +89,7 @@ def extract_parent_route(name)
8689
route_name = name.match(%r{^/?([^/]*).*$})[1]
8790
return route_name unless route_name.include? ':'
8891

89-
matches = name.match(/\/[a-z]+/)
92+
matches = name.match(/\/\p{Alpha}+/)
9093
matches.nil? ? route_name : matches[0].delete('/')
9194
end
9295

spec/issues/809_utf8_routes_spec.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe '#605 root route documentation' do
6+
let(:app) do
7+
Class.new(Grape::API) do
8+
resource :grunnbeløp do
9+
desc 'returnerer grunnbeløp'
10+
get do
11+
{ message: 'hello world' }
12+
end
13+
end
14+
15+
resource :εσόδων do
16+
desc 'εσόδων'
17+
get do
18+
{ message: 'hello world' }
19+
end
20+
end
21+
22+
resource :数 do
23+
desc '数'
24+
get do
25+
{ message: 'hello world' }
26+
end
27+
end
28+
29+
resource :amount do
30+
desc 'returns amount'
31+
get do
32+
{ message: 'hello world' }
33+
end
34+
end
35+
36+
resource :👍 do
37+
desc 'returns 👍'
38+
get do
39+
{ message: 'hello world' }
40+
end
41+
end
42+
43+
add_swagger_documentation
44+
end
45+
end
46+
47+
subject do
48+
get '/swagger_doc'
49+
JSON.parse(last_response.body)['paths']
50+
end
51+
52+
specify do
53+
expect(subject.keys).to match_array ['/grunnbeløp', '/amount', '/εσόδων', '/数']
54+
end
55+
end

0 commit comments

Comments
 (0)