rspec-openapi 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +13 -4
- data/lib/rspec/openapi.rb +1 -1
- data/lib/rspec/openapi/schema_builder.rb +10 -3
- data/lib/rspec/openapi/schema_file.rb +11 -1
- data/lib/rspec/openapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adaf5569dc17aa32bf1f570f77023097aed29ce2b76ee9c9c62ab5b48208dc31
|
4
|
+
data.tar.gz: ddf2e7c33c5a02a86f610dc68d6e3a46f1be0a44b2df838ab1681c9e09cca5dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07011c0a01fce891827ee62898a814ce653f17b68a13dca3dd11c4b166e3ef0c864675a43a86c8f94175ea50936d0cfb3a3a386c2c1eeaf68c13f3c180731be2
|
7
|
+
data.tar.gz: cb24d803cc198dd7df3578147a54c4160dbd160bb642e5ecfad149c5c119a3d6cd35a2fba02618b7c58a2511b5907129ced6d408fbe2e341cd616d0224f01a4d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
## v0.1.5
|
2
|
+
|
3
|
+
* Support detecting `float` type [#2](https://github.com/k0kubun/rspec-openapi/issues/2)
|
4
|
+
|
5
|
+
## v0.1.4
|
6
|
+
|
7
|
+
* Avoid NoMethodError on nil Content-Type
|
8
|
+
* Include a space between controller and action in summary
|
9
|
+
|
10
|
+
## v0.1.3
|
11
|
+
|
12
|
+
* Add `RSpec::OpenAPI.comment` configuration
|
13
|
+
|
14
|
+
## v0.1.2
|
15
|
+
|
16
|
+
* Generate `required: true` for path params [#1](https://github.com/k0kubun/rspec-openapi/issues/1)
|
17
|
+
|
18
|
+
## v0.1.1
|
19
|
+
|
20
|
+
* Generate a path like `/{id}` instead of `/:id`
|
21
|
+
|
1
22
|
## v0.1.0
|
2
23
|
|
3
24
|
* Initial release
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ $ OPENAPI=1 rspec
|
|
29
29
|
|
30
30
|
### Example
|
31
31
|
|
32
|
-
Let's say you have [a request spec](./spec/requests/
|
32
|
+
Let's say you have [a request spec](./spec/requests/tables_spec.rb) like this:
|
33
33
|
|
34
34
|
```rb
|
35
35
|
RSpec.describe 'Tables', type: :request do
|
@@ -52,7 +52,7 @@ end
|
|
52
52
|
If you run the spec with `OPENAPI=1`,
|
53
53
|
|
54
54
|
```
|
55
|
-
OPENAPI=1
|
55
|
+
OPENAPI=1 rspec spec/requests/tables_spec.rb
|
56
56
|
```
|
57
57
|
|
58
58
|
It will generate [`doc/openapi.yaml` file](./spec/railsapp/doc/openapi.yaml) like:
|
@@ -64,7 +64,7 @@ info:
|
|
64
64
|
paths:
|
65
65
|
"/tables":
|
66
66
|
get:
|
67
|
-
summary: tables#index
|
67
|
+
summary: 'tables #index'
|
68
68
|
parameters:
|
69
69
|
- name: page
|
70
70
|
in: query
|
@@ -98,10 +98,19 @@ and the schema file can be used as an input of [Swagger UI](https://github.com/s
|
|
98
98
|
|
99
99
|
### Configuration
|
100
100
|
|
101
|
-
|
101
|
+
The following configurations are optional.
|
102
102
|
|
103
103
|
```rb
|
104
|
+
# Change the path to generate schema from `doc/openapi.yaml`
|
104
105
|
RSpec::OpenAPI.path = 'doc/schema.yaml'
|
106
|
+
|
107
|
+
# Generate a comment on top of a schema file
|
108
|
+
RSpec::OpenAPI.comment = <<~EOS
|
109
|
+
This file is auto-generated by rspec-openapi https://github.com/k0kubun/rspec-openapi
|
110
|
+
|
111
|
+
When you write a spec in spec/requests, running the spec with `OPENAPI=1 rspec` will
|
112
|
+
update this file automatically. You can also manually edit this file.
|
113
|
+
EOS
|
105
114
|
```
|
106
115
|
|
107
116
|
### How can I add information which can't be generated from RSpec?
|
data/lib/rspec/openapi.rb
CHANGED
@@ -4,9 +4,9 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
4
4
|
def build(record)
|
5
5
|
{
|
6
6
|
paths: {
|
7
|
-
record.path => {
|
7
|
+
normalize_path(record.path) => {
|
8
8
|
record.method.downcase => {
|
9
|
-
summary: "#{record.controller}##{record.action}",
|
9
|
+
summary: "#{record.controller} ##{record.action}",
|
10
10
|
parameters: build_parameters(record),
|
11
11
|
requestBody: build_request_body(record),
|
12
12
|
responses: {
|
@@ -35,6 +35,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
35
35
|
parameters << {
|
36
36
|
name: key.to_s,
|
37
37
|
in: 'path',
|
38
|
+
required: true,
|
38
39
|
schema: build_property(try_cast(value)),
|
39
40
|
}
|
40
41
|
end
|
@@ -83,6 +84,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
83
84
|
case value
|
84
85
|
when String
|
85
86
|
'string'
|
87
|
+
when Float
|
88
|
+
'float'
|
86
89
|
when Integer
|
87
90
|
'integer'
|
88
91
|
when TrueClass, FalseClass
|
@@ -107,7 +110,11 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
107
110
|
end
|
108
111
|
end
|
109
112
|
|
113
|
+
def normalize_path(path)
|
114
|
+
path.gsub(%r|/:([^:/]+)|, '/{\1}')
|
115
|
+
end
|
116
|
+
|
110
117
|
def normalize_content_type(content_type)
|
111
|
-
content_type
|
118
|
+
content_type&.sub(/;.+\z/, '')
|
112
119
|
end
|
113
120
|
end
|
@@ -26,6 +26,16 @@ class RSpec::OpenAPI::SchemaFile
|
|
26
26
|
# @param [Hash] spec
|
27
27
|
def write(spec)
|
28
28
|
FileUtils.mkdir_p(File.dirname(@path))
|
29
|
-
File.write(@path, YAML.dump(spec))
|
29
|
+
File.write(@path, prepend_comment(YAML.dump(spec)))
|
30
|
+
end
|
31
|
+
|
32
|
+
def prepend_comment(content)
|
33
|
+
return content if RSpec::OpenAPI.comment.nil?
|
34
|
+
|
35
|
+
comment = RSpec::OpenAPI.comment.dup
|
36
|
+
unless comment.end_with?("\n")
|
37
|
+
comment << "\n"
|
38
|
+
end
|
39
|
+
"#{comment.gsub(/^/, '# ').gsub(/^# \n/, "#\n")}#{content}"
|
30
40
|
end
|
31
41
|
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.1.
|
4
|
+
version: 0.1.5
|
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-06-
|
11
|
+
date: 2020-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|