apipie-rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 822d52cddc54c458cc7449d9f881a68ee6766811d740cbc0a6d717f4760b8896
4
- data.tar.gz: 37a6bd59c3e1fac91dbcb8ef34078caa28c19b9e27bcad872d70796096dfc67f
3
+ metadata.gz: 5beee9e3a891140602d1c9a962c9229cbeb60d7e289a95d62a48bfea39b396a9
4
+ data.tar.gz: 6f096bb6648692ceaa7a05fa095051a26c4bd176e062bf2ad794a9f3b5438261
5
5
  SHA512:
6
- metadata.gz: a16332ce330bd90cc3a12bc57b5904bc7e66cd0f21dd66fd497903a139fb826c7e4e796fbdf440bb17c48427755d3cd66e548660e3e8a4a549dd8b97f5205db4
7
- data.tar.gz: 1ac7735265214806b2beb8d7414c18915a8de995bf55339c93124f5247833284a30d566517ce71266718da3a237769d48c1a02bc1f6d5b11a893908bcc33f4d8
6
+ metadata.gz: 27f57c84d3b692d40b84ee01740b960d10c9951bdf0e45d936079cd7dc0fac899a0ac90ccd229db6a164549c7238de6bb515f8102b7624342c406a775ee7cbfa
7
+ data.tar.gz: 4ee73961d9417cfa623d9d84b5dbf7a8afdfcd19afa86f43b72b807dce374a79b456c3c041d953cb5a31d3b5bb5ba4926ccfd6b2d751ee61e36e21fd0ec83776
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@
4
4
  Also deleted the `Gemfile` that was now a broken symlink.
5
5
  please use `export BUNDLE_GEMFILE='gemfiles/Gemfile.rails61'; bundle exec rspec` to run the test suite
6
6
 
7
+ ## [v1.1.0](https://github.com/Apipie/apipie-rails/tree/v1.1.0) (2023-05-16)
8
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v1.0.0...v1.1.0)
9
+ * Improve performance of route detection [#870](https://github.com/Apipie/apipie-rails/pull/870) (Eric Hankins)
10
+ * Fix startup crash due to typo [#869](https://github.com/Apipie/apipie-rails/pull/869) (Eric Hankins)
11
+ * Skip parse body for pdf responses [#871](https://github.com/Apipie/apipie-rails/pull/871) (Juan Gomez)
12
+ * add missing 'returns' translation [#868](https://github.com/Apipie/apipie-rails/pull/868) (Anthony Robertson)
13
+
7
14
  ## [v1.0.0](https://github.com/Apipie/apipie-rails/tree/v1.0.0) (2023-04-26)
8
15
  [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.9.4...v1.0.0)
9
16
  * Refactor Swagger generator [#816](https://github.com/Apipie/apipie-rails/pull/816) (Panos Dalitsouris)
@@ -30,6 +30,7 @@ en:
30
30
  headers: Headers
31
31
  header_name: Header name
32
32
  code: Code
33
+ returns: Returns
33
34
  deprecated: Deprecated
34
35
  deprecation_details: Deprecation details
35
36
  deprecation:
@@ -26,14 +26,13 @@ module Apipie
26
26
  end
27
27
 
28
28
  def rails_routes(route_set = nil, base_url = "")
29
- if route_set.nil? && @rails_routes
30
- return @rails_routes
31
- end
29
+ return @_rails_routes if route_set.nil? && @_rails_routes
30
+
32
31
  route_set ||= Rails.application.routes
33
32
  # ensure routes are loaded
34
33
  Rails.application.reload_routes! unless Rails.application.routes.routes.any?
35
34
 
36
- flatten_routes = []
35
+ flattened_routes = []
37
36
 
38
37
  route_set.routes.each do |route|
39
38
  # route is_a ActionDispatch::Journey::Route
@@ -42,30 +41,30 @@ module Apipie
42
41
  route_app = route.app.app
43
42
  if route_app.respond_to?(:routes) && route_app.routes.is_a?(ActionDispatch::Routing::RouteSet)
44
43
  # recursively go though the mounted engines
45
- flatten_routes.concat(rails_routes(route_app.routes, File.join(base_url, route.path.spec.to_s)))
44
+ flattened_routes.concat(rails_routes(route_app.routes, File.join(base_url, route.path.spec.to_s)))
46
45
  else
47
46
  route.base_url = base_url
48
- flatten_routes << route
47
+ flattened_routes << route
49
48
  end
50
49
  end
51
50
 
52
- @rails_routes = flatten_routes
51
+ @_rails_routes = flattened_routes
53
52
  end
54
53
 
55
- # the app might be nested when using contraints, namespaces etc.
56
- # this method does in depth search for the route controller
57
- def route_app_controller(app, route, visited_apps = [])
58
- if route.defaults[:controller]
59
- controller_name = "#{route.defaults[:controller]}_controller".camelize
60
- controller_name.safe_constantize
54
+ def rails_routes_by_controller_and_action
55
+ @_rails_routes_by_controller_and_action = rails_routes.group_by do |route|
56
+ requirements = route.requirements
57
+ [requirements[:controller], requirements[:action]]
61
58
  end
62
59
  end
63
60
 
61
+ def clear_cached_routes!
62
+ @_rails_routes = nil
63
+ @_rails_routes_by_controller_and_action = nil
64
+ end
65
+
64
66
  def routes_for_action(controller, method, args)
65
- routes = rails_routes.select do |route|
66
- controller == route_app_controller(route.app, route) &&
67
- method.to_s == route.defaults[:action]
68
- end
67
+ routes = rails_routes_by_controller_and_action[[controller.name.underscore.chomp('_controller'), method.to_s]] || []
69
68
 
70
69
  Apipie.configuration.routes_formatter.format_routes(routes, args)
71
70
  end
@@ -227,7 +226,7 @@ module Apipie
227
226
 
228
227
  def remove_method_description(resource, versions, method_name)
229
228
  versions.each do |version|
230
- resource = resource_id(resource)
229
+ resource = get_resource_id(resource)
231
230
  if resource_description = get_resource_description("#{version}##{resource}")
232
231
  resource_description.remove_method_description(method_name)
233
232
  end
@@ -482,6 +481,7 @@ module Apipie
482
481
  # as this would break loading of the controllers.
483
482
  def rails_mark_classes_for_reload
484
483
  unless Rails.application.config.cache_classes
484
+ clear_cached_routes!
485
485
  Rails.application.reloader.reload!
486
486
  init_env
487
487
  reload_examples
@@ -48,7 +48,9 @@ module Apipie
48
48
  else
49
49
  @query = request.query_string
50
50
  end
51
- @response_data = parse_data(response.body)
51
+ if response.content_type != 'application/pdf'
52
+ @response_data = parse_data(response.body)
53
+ end
52
54
  @code = response.code
53
55
  end
54
56
 
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -22,7 +22,8 @@ module Api
22
22
  def update
23
23
  end
24
24
 
25
- api :DELETE, "/architecturess/:id/", "Delete an architecture."
25
+ api! "Delete an architecture."
26
+ api_version "2.0" # forces removal of the method description
26
27
  def destroy
27
28
  end
28
29
  end
@@ -45,6 +45,12 @@ Dummy::Application.routes.draw do
45
45
  get "/pets/returns_response_with_valid_array" => "pets#returns_response_with_valid_array"
46
46
  get "/pets/returns_response_with_invalid_array" => "pets#returns_response_with_invalid_array"
47
47
  get "/pets/undocumented_method" => "pets#undocumented_method"
48
+
49
+ # generate 1000 routes for testing performance of route matching used by api! method
50
+ # it's okay that these don't go anywhere real
51
+ 1000.times do |i|
52
+ get "/api/v1/pets/#{i}" => "pets#{i}#show"
53
+ end
48
54
  end
49
55
 
50
56
  apipie
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apipie-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Pokorny
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-26 00:00:00.000000000 Z
12
+ date: 2023-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack