rspec-openapi 0.3.2 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6a204535e3afe650434a20936c2d1ec34bc5136071cb76e48f1481b13629de8
4
- data.tar.gz: d102d224884511c60d2b15030083d382d5c8da0bbbfa12dc3c293248456fd7ed
3
+ metadata.gz: 31d1b980670f03ab900ae31ecd241ce6a2b44edfbbc79839c9dc948c22ffa6b0
4
+ data.tar.gz: 51eead9afb87f8303cdb1d5b4fcb8331bfc01f534127c038be1394e6e598d9dc
5
5
  SHA512:
6
- metadata.gz: 241b1dd789ae12fa853dc90b12cb497945dfc1bf4da0974a93d097c9f685ce6d585ddf08874a8dccfdec22467a8e47428e3a85a68ce847e8d306821b402b36fa
7
- data.tar.gz: 60f6569f6d91262742732d45eacf8ef3192e201ddf91254b49fe00bdeada72ef05db02f3fcc61a817ed9ff54dc44a12fc45ffc4a1ee95e229f93c9e14b0e5b08
6
+ metadata.gz: ddd8900e0365e487f42411e3cbfc7a8c23d33cdd0376da9d705311e8ba7e5c8d95e97859a8b10e0e1b5f83da2e6a1e4166993adc6a8dddb704cc3949a02eae7a
7
+ data.tar.gz: 3bd25b3e5d2ce70c0961d3bcd471d0c6ff6d36e5bc2a7d72fd43f594f698a56a38774bc0d298a936987db54eca6995f098817adbabf232433dc4f2f26232f4f9
@@ -1,3 +1,25 @@
1
+ ## v0.3.7
2
+
3
+ * Classify tag names and remove controller names from summary in Rails
4
+
5
+ ## v0.3.6
6
+
7
+ * Fix documents generated by Rails engines
8
+
9
+ ## v0.3.5
10
+
11
+ * Support finding routes in Rails engines
12
+
13
+ ## v0.3.4
14
+
15
+ * Generate tags by controller names
16
+ [#10](https://github.com/k0kubun/rspec-openapi/issues/10)
17
+
18
+ ## v0.3.3
19
+
20
+ * Avoid `JSON::ParserError` when a response body is no content
21
+ [#9](https://github.com/k0kubun/rspec-openapi/issues/9)
22
+
1
23
  ## v0.3.2
2
24
 
3
25
  * Stop generating format as path parameters in Rails
data/README.md CHANGED
@@ -64,16 +64,20 @@ info:
64
64
  paths:
65
65
  "/tables":
66
66
  get:
67
- summary: 'tables #index'
67
+ summary: index
68
+ tags:
69
+ - Table
68
70
  parameters:
69
71
  - name: page
70
72
  in: query
71
73
  schema:
72
74
  type: integer
75
+ example: 1
73
76
  - name: per
74
77
  in: query
75
78
  schema:
76
79
  type: integer
80
+ example: 10
77
81
  responses:
78
82
  '200':
79
83
  description: returns a list of tables
@@ -6,6 +6,7 @@ RSpec::OpenAPI::Record = Struct.new(
6
6
  :request_params, # @param [Hash] - {:request=>"body"}
7
7
  :request_content_type, # @param [String] - "application/json"
8
8
  :summary, # @param [String] - "v1/statuses #show"
9
+ :tags, # @param [Array] - ["Status"]
9
10
  :description, # @param [String] - "returns a status"
10
11
  :status, # @param [Integer] - 200
11
12
  :response_body, # @param [Object] - {"status" => "ok"}
@@ -18,12 +18,20 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
18
18
  if rails?
19
19
  route = find_rails_route(request)
20
20
  path = route.path.spec.to_s.delete_suffix('(.:format)')
21
- summary = "#{route.requirements[:controller]} ##{route.requirements[:action]}"
21
+ summary = "#{route.requirements[:action]}"
22
+ tags = [route.requirements[:controller].classify]
22
23
  else
23
24
  path = request.path
24
25
  summary = "#{request.method} #{request.path}"
25
26
  end
26
27
 
28
+ response_body =
29
+ begin
30
+ response.parsed_body
31
+ rescue JSON::ParserError
32
+ nil
33
+ end
34
+
27
35
  RSpec::OpenAPI::Record.new(
28
36
  method: request.request_method,
29
37
  path: path,
@@ -32,9 +40,10 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
32
40
  request_params: raw_request_params(request),
33
41
  request_content_type: request.content_type,
34
42
  summary: summary,
43
+ tags: tags,
35
44
  description: RSpec::OpenAPI.description_builder.call(example),
36
45
  status: response.status,
37
- response_body: response.parsed_body,
46
+ response_body: response_body,
38
47
  response_content_type: response.content_type,
39
48
  ).freeze
40
49
  end
@@ -50,8 +59,17 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
50
59
  end
51
60
 
52
61
  # @param [ActionDispatch::Request] request
53
- def find_rails_route(request)
54
- Rails.application.routes.router.recognize(request) do |route|
62
+ def find_rails_route(request, app: Rails.application, fix_path: true)
63
+ # Reverse the destructive modification by Rails https://github.com/rails/rails/blob/v6.0.3.4/actionpack/lib/action_dispatch/journey/router.rb#L33-L41
64
+ if fix_path && !request.script_name.empty?
65
+ request = request.dup
66
+ request.path_info = File.join(request.script_name, request.path_info)
67
+ end
68
+
69
+ app.routes.router.recognize(request) do |route|
70
+ unless route.path.anchored
71
+ route = find_rails_route(request, app: route.app.app, fix_path: false)
72
+ end
55
73
  return route
56
74
  end
57
75
  raise "No route matched for #{request.request_method} #{request.path_info}"
@@ -2,23 +2,29 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
2
2
  # @param [RSpec::OpenAPI::Record] record
3
3
  # @return [Hash]
4
4
  def build(record)
5
+ response = {
6
+ description: record.description,
7
+ }
8
+
9
+ if record.response_body
10
+ response[:content] = {
11
+ normalize_content_type(record.response_content_type) => {
12
+ schema: build_property(record.response_body),
13
+ example: (record.response_body if example_enabled?),
14
+ }.compact,
15
+ }
16
+ end
17
+
5
18
  {
6
19
  paths: {
7
20
  normalize_path(record.path) => {
8
21
  record.method.downcase => {
9
22
  summary: record.summary,
23
+ tags: record.tags,
10
24
  parameters: build_parameters(record),
11
25
  requestBody: build_request_body(record),
12
26
  responses: {
13
- record.status.to_s => {
14
- description: record.description,
15
- content: {
16
- normalize_content_type(record.response_content_type) => {
17
- schema: build_property(record.response_body),
18
- example: (record.response_body if example_enabled?),
19
- }.compact,
20
- },
21
- },
27
+ record.status.to_s => response,
22
28
  },
23
29
  }.compact,
24
30
  },
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.3.2'
3
+ VERSION = '0.3.7'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-openapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-01 00:00:00.000000000 Z
11
+ date: 2020-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -73,7 +73,7 @@ metadata:
73
73
  homepage_uri: https://github.com/k0kubun/rspec-openapi
74
74
  source_code_uri: https://github.com/k0kubun/rspec-openapi
75
75
  changelog_uri: https://github.com/k0kubun/rspec-openapi/blob/master/CHANGELOG.md
76
- post_install_message:
76
+ post_install_message:
77
77
  rdoc_options: []
78
78
  require_paths:
79
79
  - lib
@@ -88,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.2.0.pre1
92
- signing_key:
91
+ rubygems_version: 3.1.2
92
+ signing_key:
93
93
  specification_version: 4
94
94
  summary: Generate OpenAPI schema from RSpec request specs
95
95
  test_files: []