rspec-openapi 0.3.19 → 0.3.20

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: bc42fc95d88e3523412bf9efbee6066b2789637a5b0213550f9d16711c1c9a94
4
- data.tar.gz: fcaa99b78c4cc3404b9ee5b8cb9906fb3872b8c06ceb8ceb5d38f775015ae6ed
3
+ metadata.gz: d0ff0f4854e68684d59b37788218a797c61cdff744808237ca08818493a393eb
4
+ data.tar.gz: 0730c2487ccb75a2fd3bec8052136cb75b9410d42daea1e3a6c9826d6854df8d
5
5
  SHA512:
6
- metadata.gz: aa9865db15800d17549ee640ed88b2d5f32289e4ac61a30db43cf0adf7021889123cedb96558032c0c8b25c03d5390897fa716352edb98c7a5c091b64210b924
7
- data.tar.gz: 5da282aa5811e4a61f24f4c853200c3e8e786704d737eff325651eca75cef49c06fb96d1d7c9547afa821e98e807fa8cf1509c672b934a296e57927f584c3e14
6
+ metadata.gz: dadb96bc250a1c615176c5ada6e5dd6a41f1dec2a96099ef5181ac83e77d9c008168c0219c0a92d59bfc7a5ca0388138bcdd2641d8c5eb767d42a38a2cbd4096
7
+ data.tar.gz: 276bf5d35e634db31d6cdcaac519dac4972cbf0c93014c9c45d59a97bb0d2c20ee969c843f54e879eca8bab29cea0192cf36aab9c3ba5b0c2ee803692b0a5816
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.3.20
2
+
3
+ * Add `RSpec::OpenAPI.output` config to output JSON
4
+ [#31](https://github.com/k0kubun/rspec-openapi/pull/31)
5
+
1
6
  ## v0.3.19
2
7
 
3
8
  * Add `server_urls` and `request_headers` configs
data/README.md CHANGED
@@ -108,6 +108,9 @@ The following configurations are optional.
108
108
  # Change the path to generate schema from `doc/openapi.yaml`
109
109
  RSpec::OpenAPI.path = 'doc/schema.yaml'
110
110
 
111
+ # Change the output type yaml or json
112
+ RSpec::OpenAPI.output = :json
113
+
111
114
  # Disable generating `example`
112
115
  RSpec::OpenAPI.enable_example = false
113
116
 
@@ -163,10 +166,6 @@ Beta
163
166
 
164
167
  Basic features are there, and some people are already using this.
165
168
 
166
- ### Current limitation
167
-
168
- * Generating a JSON file is not supported yet
169
-
170
169
  ### Other missing features with notes
171
170
 
172
171
  * Delete obsoleted endpoints
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'yaml'
3
+ require 'json'
3
4
 
4
5
  # TODO: Support JSON
5
6
  class RSpec::OpenAPI::SchemaFile
@@ -20,13 +21,25 @@ class RSpec::OpenAPI::SchemaFile
20
21
  # @return [Hash]
21
22
  def read
22
23
  return {} unless File.exist?(@path)
23
- YAML.load(File.read(@path))
24
+
25
+ content = File.read(@path)
26
+
27
+ return JSON.load(content) if json?
28
+
29
+ YAML.load(content)
24
30
  end
25
31
 
26
32
  # @param [Hash] spec
27
33
  def write(spec)
28
34
  FileUtils.mkdir_p(File.dirname(@path))
29
- File.write(@path, prepend_comment(YAML.dump(spec)))
35
+
36
+ output = if json?
37
+ JSON.pretty_generate(spec)
38
+ else
39
+ prepend_comment(YAML.dump(spec))
40
+ end
41
+
42
+ File.write(@path, output)
30
43
  end
31
44
 
32
45
  def prepend_comment(content)
@@ -38,4 +51,8 @@ class RSpec::OpenAPI::SchemaFile
38
51
  end
39
52
  "#{comment.gsub(/^/, '# ').gsub(/^# \n/, "#\n")}#{content}"
40
53
  end
54
+
55
+ def json?
56
+ RSpec::OpenAPI.output.to_s == 'json'
57
+ end
41
58
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.3.19'
3
+ VERSION = '0.3.20'
4
4
  end
5
5
  end
data/lib/rspec/openapi.rb CHANGED
@@ -7,10 +7,11 @@ module RSpec::OpenAPI
7
7
  @enable_example = true
8
8
  @description_builder = -> (example) { example.description }
9
9
  @application_version = '1.0.0'
10
+ @output = :yaml
10
11
  @request_headers = []
11
12
  @server_urls = []
12
13
 
13
14
  class << self
14
- attr_accessor :path, :comment, :enable_example, :description_builder, :application_version, :request_headers, :server_urls
15
+ attr_accessor :path, :comment, :enable_example, :description_builder, :application_version, :request_headers, :server_urls, :output
15
16
  end
16
17
  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.19
4
+ version: 0.3.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-26 00:00:00.000000000 Z
11
+ date: 2021-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 3.1.2
93
+ rubygems_version: 3.2.22
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Generate OpenAPI schema from RSpec request specs