Skip to content

Commit

Permalink
Fixes (restores) route ordering (#859)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
dchandekstark and LeFnord authored Mar 3, 2024
1 parent 7198a3a commit ccdc2dd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
* [#846](https://github.com/ruby-grape/grape-swagger/pull/846): Refactor oapi fetch task [@Vachman](https://github.com/Vachman)
* [#850](https://github.com/ruby-grape/grape-swagger/pull/850): Fix value of enum to be Array [@takahashim](https://github.com/takahashim)


### 1.4.3 (January 5, 2022)

#### Fixes
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def combine_routes(app, doc_klass)
@target_class.combined_routes[resource] ||= []
next if doc_klass.hide_documentation_path && route.path.match(/#{doc_klass.mount_path}($|\/|\(\.)/)

@target_class.combined_routes[resource].unshift route
@target_class.combined_routes[resource] << route
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/grape-swagger/rake/oapi_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def validate
resource - if given only for that it would be generated (optional)'
task validate: :environment do
# :nocov:
ENV['store'] = 'true'
ENV.store('store', 'true')
::Rake::Task['oapi:fetch'].invoke
exit if error?

Expand Down Expand Up @@ -108,7 +108,7 @@ def format_path(path)
end

def save_to_file?
ENV['store'].present? && !error?
ENV.fetch('store', nil).present? && !error?
end

def error?
Expand All @@ -118,10 +118,10 @@ def error?
def file(url)
api_version = url.split('/').last

name = if ENV['store'] == 'true' || ENV['store'].blank?
name = if ENV.fetch('store', nil) == 'true' || ENV.fetch('store', nil).blank?
"swagger_doc_#{api_version}.json"
else
ENV['store'].sub('.json', "_#{api_version}.json")
ENV.fetch('store').sub('.json', "_#{api_version}.json")
end

File.join(Dir.getwd, name)
Expand Down
13 changes: 1 addition & 12 deletions spec/swagger_v2/mount_override_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,13 @@ def app
end

Class.new(Grape::API) do
mount new_api
mount old_api
mount new_api

add_swagger_documentation format: :json
end
end

context 'actual api request' do
subject do
get '/'
last_response.body
end

it 'returns data from new endpoint' do
is_expected.to eq 'new'
end
end

context 'api documentation' do
subject do
get '/swagger_doc'
Expand Down

0 comments on commit ccdc2dd

Please sign in to comment.