rspec-openapi 0.3.5 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +5 -2
- data/lib/rspec/openapi.rb +2 -1
- data/lib/rspec/openapi/default_schema.rb +1 -0
- data/lib/rspec/openapi/record_builder.rb +9 -6
- data/lib/rspec/openapi/schema_builder.rb +12 -9
- data/lib/rspec/openapi/version.rb +1 -1
- data/test.png +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62ae9fb333bba34df56a7675823e22ae9029852028d529ffae48ee9070eadeb0
|
4
|
+
data.tar.gz: 249959214fbce6ae72294f07e1a7de945c1052071d67942ec7f19c68cbe90a9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f66917401fc326b7a290892000ef82af637d959fd337ab158152176605fa5e41a8ce2e904b7c1d73cef203d1b3851912bcff0d58f5e879d27fc728f456d1569
|
7
|
+
data.tar.gz: abf3aee3cd216b58d53079c53372a3839c3cc89470d5a0500274fde35a3103643d8c6a3555b977989bc598f4f71e0518300cec76372dce1a8ff4bb41615a0113
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
## v0.3.10
|
2
|
+
|
3
|
+
* Add `info.version`
|
4
|
+
[#16](https://github.com/k0kubun/rspec-openapi/pull/16)
|
5
|
+
|
6
|
+
## v0.3.9
|
7
|
+
|
8
|
+
* Initial support for multipart/form-data
|
9
|
+
[#12](https://github.com/k0kubun/rspec-openapi/pull/12)
|
10
|
+
|
11
|
+
## v0.3.8
|
12
|
+
|
13
|
+
* Generate `type: 'number', format: 'float'` instead of `type: 'float'` for Float
|
14
|
+
[#11](https://github.com/k0kubun/rspec-openapi/issues/11)
|
15
|
+
|
16
|
+
## v0.3.7
|
17
|
+
|
18
|
+
* Classify tag names and remove controller names from summary in Rails
|
19
|
+
|
20
|
+
## v0.3.6
|
21
|
+
|
22
|
+
* Fix documents generated by Rails engines
|
23
|
+
|
1
24
|
## v0.3.5
|
2
25
|
|
3
26
|
* Support finding routes in Rails engines
|
data/README.md
CHANGED
@@ -64,9 +64,9 @@ info:
|
|
64
64
|
paths:
|
65
65
|
"/tables":
|
66
66
|
get:
|
67
|
-
summary:
|
67
|
+
summary: index
|
68
68
|
tags:
|
69
|
-
-
|
69
|
+
- Table
|
70
70
|
parameters:
|
71
71
|
- name: page
|
72
72
|
in: query
|
@@ -111,6 +111,9 @@ RSpec::OpenAPI.path = 'doc/schema.yaml'
|
|
111
111
|
# Disable generating `example`
|
112
112
|
RSpec::OpenAPI.enable_example = false
|
113
113
|
|
114
|
+
# Change `info.version`
|
115
|
+
RSpec::OpenAPI.application_version = '1.0.0'
|
116
|
+
|
114
117
|
# Generate a comment on top of a schema file
|
115
118
|
RSpec::OpenAPI.comment = <<~EOS
|
116
119
|
This file is auto-generated by rspec-openapi https://github.com/k0kubun/rspec-openapi
|
data/lib/rspec/openapi.rb
CHANGED
@@ -6,8 +6,9 @@ module RSpec::OpenAPI
|
|
6
6
|
@comment = nil
|
7
7
|
@enable_example = true
|
8
8
|
@description_builder = -> (example) { example.description }
|
9
|
+
@application_version = '1.0.0'
|
9
10
|
|
10
11
|
class << self
|
11
|
-
attr_accessor :path, :comment, :enable_example, :description_builder
|
12
|
+
attr_accessor :path, :comment, :enable_example, :description_builder, :application_version
|
12
13
|
end
|
13
14
|
end
|
@@ -18,8 +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[:
|
22
|
-
tags = [route.requirements[:controller]]
|
21
|
+
summary = "#{route.requirements[:action]}"
|
22
|
+
tags = [route.requirements[:controller].classify]
|
23
23
|
else
|
24
24
|
path = request.path
|
25
25
|
summary = "#{request.method} #{request.path}"
|
@@ -59,14 +59,17 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# @param [ActionDispatch::Request] request
|
62
|
-
def find_rails_route(request)
|
63
|
-
# Reverse the destructive modification by Rails https://github.com/rails/rails/blob/
|
64
|
-
|
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
65
|
request = request.dup
|
66
66
|
request.path_info = File.join(request.script_name, request.path_info)
|
67
67
|
end
|
68
68
|
|
69
|
-
|
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
|
70
73
|
return route
|
71
74
|
end
|
72
75
|
raise "No route matched for #{request.request_method} #{request.path_info}"
|
@@ -79,7 +79,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def build_property(value)
|
82
|
-
property =
|
82
|
+
property = build_type(value)
|
83
|
+
|
83
84
|
case value
|
84
85
|
when Array
|
85
86
|
property[:items] = build_property(value.first)
|
@@ -96,19 +97,21 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
96
97
|
def build_type(value)
|
97
98
|
case value
|
98
99
|
when String
|
99
|
-
'string'
|
100
|
-
when Float
|
101
|
-
'float'
|
100
|
+
{ type: 'string' }
|
102
101
|
when Integer
|
103
|
-
'integer'
|
102
|
+
{ type: 'integer' }
|
103
|
+
when Float
|
104
|
+
{ type: 'number', format: 'float' }
|
104
105
|
when TrueClass, FalseClass
|
105
|
-
'boolean'
|
106
|
+
{ type: 'boolean' }
|
106
107
|
when Array
|
107
|
-
'array'
|
108
|
+
{ type: 'array' }
|
108
109
|
when Hash
|
109
|
-
'object'
|
110
|
+
{ type: 'object' }
|
111
|
+
when ActionDispatch::Http::UploadedFile
|
112
|
+
{ type: 'string', format: 'binary' }
|
110
113
|
when NilClass
|
111
|
-
'null'
|
114
|
+
{ type: 'null' }
|
112
115
|
else
|
113
116
|
raise NotImplementedError, "type detection is not implemented for: #{value.inspect}"
|
114
117
|
end
|
data/test.png
ADDED
Binary file
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/rspec/openapi/schema_merger.rb
|
67
67
|
- lib/rspec/openapi/version.rb
|
68
68
|
- rspec-openapi.gemspec
|
69
|
+
- test.png
|
69
70
|
homepage: https://github.com/k0kubun/rspec-openapi
|
70
71
|
licenses:
|
71
72
|
- MIT
|