rspec-openapi 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +10 -1
- data/lib/rspec/openapi.rb +1 -1
- data/lib/rspec/openapi/schema_file.rb +11 -1
- data/lib/rspec/openapi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 934be20ed834fa8fa6c975eccf5c63f218b06a80136e6a50920914d4bfd867d0
|
4
|
+
data.tar.gz: 4921448fe86bf5ad591cf73ab965c38667df4d37daa319d696e8c42e614dcb7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d45c922230748ab26637a1865aa4cd82a201f84a314b0c18a2a9ed820c9819b17f8506bcc8dbc6e67f0b6b84ed6eb88de061d53981ef99dacdcfdf54c09dbb27
|
7
|
+
data.tar.gz: 3ffb70c7167f312511febf9969e69ef8e3bc6b6757115ae3f400a46d9628475e5681e976e389011459e5a7891940fbbb62089d059b962e055e4c0306ce1a6a44
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -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:
|
@@ -101,7 +101,16 @@ and the schema file can be used as an input of [Swagger UI](https://github.com/s
|
|
101
101
|
If you want to change the path to generate a spec from `doc/openapi.yaml`, use:
|
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
@@ -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
|