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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f16d83f7a23388930df36ade00c6a17dfc53de509eac6c3a5d99c41235bd281b
4
- data.tar.gz: 9b65d3f8942388bfe9b62435ceef108ff55bc7e9f15af2c63bfee67bb10197ec
3
+ metadata.gz: 934be20ed834fa8fa6c975eccf5c63f218b06a80136e6a50920914d4bfd867d0
4
+ data.tar.gz: 4921448fe86bf5ad591cf73ab965c38667df4d37daa319d696e8c42e614dcb7a
5
5
  SHA512:
6
- metadata.gz: 447d354f4c0ef64cf78fd9eb2b0f47b42d943d12f9c73cc6eb51ef3ba20a931b7a4cc6c0fd214ece15214a029fc0ab28d6b028b774f652a10940806d3df5e014
7
- data.tar.gz: 44566e265fbca4419f15cc8d59948804f72b133092fe5a920bcd80bc889959ccee201395c3cf8c76849daa552d9ecbc094d271ff5885a0e972a2ad8b1752dfb1
6
+ metadata.gz: d45c922230748ab26637a1865aa4cd82a201f84a314b0c18a2a9ed820c9819b17f8506bcc8dbc6e67f0b6b84ed6eb88de061d53981ef99dacdcfdf54c09dbb27
7
+ data.tar.gz: 3ffb70c7167f312511febf9969e69ef8e3bc6b6757115ae3f400a46d9628475e5681e976e389011459e5a7891940fbbb62089d059b962e055e4c0306ce1a6a44
@@ -1,6 +1,10 @@
1
+ ## v0.1.3
2
+
3
+ * Add `RSpec::OpenAPI.comment` configuration
4
+
1
5
  ## v0.1.2
2
6
 
3
- * Generate `required: true` for path params
7
+ * Generate `required: true` for path params [#1](https://github.com/k0kubun/rspec-openapi/issues/1)
4
8
 
5
9
  ## v0.1.1
6
10
 
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 be rspec spec/requests/tables_spec.rb
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?
@@ -5,6 +5,6 @@ module RSpec::OpenAPI
5
5
  @path = 'doc/openapi.yaml'
6
6
 
7
7
  class << self
8
- attr_accessor :path
8
+ attr_accessor :path, :comment
9
9
  end
10
10
  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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-openapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun