Skip to content

Commit ccdc2dd

Browse files
Fixes (restores) route ordering (#859)
* Fixes order * Updates CHANGELOG Satisfies rubocop * I believe the removed test is not supported by grape and should not be a blocker to making the changes in this PR. While there does not appear to be a grape test with the same setup, the spec at https://github.com/ruby-grape/grape/blob/e3451c892abd82c15f0937d7f464613ae715a73d/spec/grape/api_spec.rb#L1025-L1045 suggests that mounts do not overwrite. --------- Co-authored-by: peter scholz <[email protected]>
1 parent 7198a3a commit ccdc2dd

File tree

4 files changed

+6
-18
lines changed

4 files changed

+6
-18
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
* [#846](https://github.com/ruby-grape/grape-swagger/pull/846): Refactor oapi fetch task [@Vachman](https://github.com/Vachman)
7373
* [#850](https://github.com/ruby-grape/grape-swagger/pull/850): Fix value of enum to be Array [@takahashim](https://github.com/takahashim)
7474

75-
7675
### 1.4.3 (January 5, 2022)
7776

7877
#### Fixes

lib/grape-swagger.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def combine_routes(app, doc_klass)
4040
@target_class.combined_routes[resource] ||= []
4141
next if doc_klass.hide_documentation_path && route.path.match(/#{doc_klass.mount_path}($|\/|\(\.)/)
4242

43-
@target_class.combined_routes[resource].unshift route
43+
@target_class.combined_routes[resource] << route
4444
end
4545
end
4646

lib/grape-swagger/rake/oapi_tasks.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def validate
6363
resource - if given only for that it would be generated (optional)'
6464
task validate: :environment do
6565
# :nocov:
66-
ENV['store'] = 'true'
66+
ENV.store('store', 'true')
6767
::Rake::Task['oapi:fetch'].invoke
6868
exit if error?
6969

@@ -108,7 +108,7 @@ def format_path(path)
108108
end
109109

110110
def save_to_file?
111-
ENV['store'].present? && !error?
111+
ENV.fetch('store', nil).present? && !error?
112112
end
113113

114114
def error?
@@ -118,10 +118,10 @@ def error?
118118
def file(url)
119119
api_version = url.split('/').last
120120

121-
name = if ENV['store'] == 'true' || ENV['store'].blank?
121+
name = if ENV.fetch('store', nil) == 'true' || ENV.fetch('store', nil).blank?
122122
"swagger_doc_#{api_version}.json"
123123
else
124-
ENV['store'].sub('.json', "_#{api_version}.json")
124+
ENV.fetch('store').sub('.json', "_#{api_version}.json")
125125
end
126126

127127
File.join(Dir.getwd, name)

spec/swagger_v2/mount_override_api_spec.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,13 @@ def app
2525
end
2626

2727
Class.new(Grape::API) do
28-
mount new_api
2928
mount old_api
29+
mount new_api
3030

3131
add_swagger_documentation format: :json
3232
end
3333
end
3434

35-
context 'actual api request' do
36-
subject do
37-
get '/'
38-
last_response.body
39-
end
40-
41-
it 'returns data from new endpoint' do
42-
is_expected.to eq 'new'
43-
end
44-
end
45-
4635
context 'api documentation' do
4736
subject do
4837
get '/swagger_doc'

0 commit comments

Comments
 (0)