rspec-openapi 0.3.3 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +5 -1
- data/lib/rspec/openapi/record.rb +1 -0
- data/lib/rspec/openapi/record_builder.rb +14 -3
- data/lib/rspec/openapi/schema_builder.rb +11 -9
- data/lib/rspec/openapi/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d269feb84050ecb4ccc68924f76ae57ff4404521c22dc6cc004a177a579138b
|
4
|
+
data.tar.gz: 7df64e4c1ec76e652039e952b66d10322d3fa56f9a8af125da7872bade8ae2ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbb3af75f12db96f24941fb6f14112fa860ff98a23b44fecb9a2efb87974dfdb68d11afa113cedea15761dd59b33a621357a1e829613c61235338bf436d09965
|
7
|
+
data.tar.gz: 552c01a691716245c43c186cc913e26578d287c54e005633901da94e286694e1b83f47a0a438aebd18a0b6b8a1b6d7cb3dd1afe21faef87dae3765613ebef57f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## v0.3.8
|
2
|
+
|
3
|
+
* Generate `type: 'number', format: 'float'` instead of `type: 'float'` for Float
|
4
|
+
[#11](https://github.com/k0kubun/rspec-openapi/issues/11)
|
5
|
+
|
6
|
+
## v0.3.7
|
7
|
+
|
8
|
+
* Classify tag names and remove controller names from summary in Rails
|
9
|
+
|
10
|
+
## v0.3.6
|
11
|
+
|
12
|
+
* Fix documents generated by Rails engines
|
13
|
+
|
14
|
+
## v0.3.5
|
15
|
+
|
16
|
+
* Support finding routes in Rails engines
|
17
|
+
|
18
|
+
## v0.3.4
|
19
|
+
|
20
|
+
* Generate tags by controller names
|
21
|
+
[#10](https://github.com/k0kubun/rspec-openapi/issues/10)
|
22
|
+
|
1
23
|
## v0.3.3
|
2
24
|
|
3
25
|
* Avoid `JSON::ParserError` when a response body is no content
|
data/README.md
CHANGED
@@ -64,16 +64,20 @@ info:
|
|
64
64
|
paths:
|
65
65
|
"/tables":
|
66
66
|
get:
|
67
|
-
summary:
|
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
|
data/lib/rspec/openapi/record.rb
CHANGED
@@ -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,7 +18,8 @@ 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[:
|
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}"
|
@@ -39,6 +40,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
39
40
|
request_params: raw_request_params(request),
|
40
41
|
request_content_type: request.content_type,
|
41
42
|
summary: summary,
|
43
|
+
tags: tags,
|
42
44
|
description: RSpec::OpenAPI.description_builder.call(example),
|
43
45
|
status: response.status,
|
44
46
|
response_body: response_body,
|
@@ -57,8 +59,17 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
57
59
|
end
|
58
60
|
|
59
61
|
# @param [ActionDispatch::Request] request
|
60
|
-
def find_rails_route(request)
|
61
|
-
Rails.
|
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
|
62
73
|
return route
|
63
74
|
end
|
64
75
|
raise "No route matched for #{request.request_method} #{request.path_info}"
|
@@ -20,6 +20,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
20
20
|
normalize_path(record.path) => {
|
21
21
|
record.method.downcase => {
|
22
22
|
summary: record.summary,
|
23
|
+
tags: record.tags,
|
23
24
|
parameters: build_parameters(record),
|
24
25
|
requestBody: build_request_body(record),
|
25
26
|
responses: {
|
@@ -78,7 +79,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
78
79
|
end
|
79
80
|
|
80
81
|
def build_property(value)
|
81
|
-
property =
|
82
|
+
property = build_type(value)
|
83
|
+
|
82
84
|
case value
|
83
85
|
when Array
|
84
86
|
property[:items] = build_property(value.first)
|
@@ -95,19 +97,19 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
95
97
|
def build_type(value)
|
96
98
|
case value
|
97
99
|
when String
|
98
|
-
'string'
|
99
|
-
when Float
|
100
|
-
'float'
|
100
|
+
{ type: 'string' }
|
101
101
|
when Integer
|
102
|
-
'integer'
|
102
|
+
{ type: 'integer' }
|
103
|
+
when Float
|
104
|
+
{ type: 'number', format: 'float' }
|
103
105
|
when TrueClass, FalseClass
|
104
|
-
'boolean'
|
106
|
+
{ type: 'boolean' }
|
105
107
|
when Array
|
106
|
-
'array'
|
108
|
+
{ type: 'array' }
|
107
109
|
when Hash
|
108
|
-
'object'
|
110
|
+
{ type: 'object' }
|
109
111
|
when NilClass
|
110
|
-
'null'
|
112
|
+
{ type: 'null' }
|
111
113
|
else
|
112
114
|
raise NotImplementedError, "type detection is not implemented for: #{value.inspect}"
|
113
115
|
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.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
|
-
rubygems_version: 3.1.
|
91
|
+
rubygems_version: 3.1.4
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: Generate OpenAPI schema from RSpec request specs
|