rspec-openapi 0.1.2 → 0.2.1

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: cb2aae5a8366967c1ce6a904bb990372af7f5d3b09d4c81fad3866e590c168c3
4
+ data.tar.gz: 0665f9348a14cb0eb77c37368f69d3952d6eb71e919d8864931cdfbbbc3055dc
5
5
  SHA512:
6
- metadata.gz: 447d354f4c0ef64cf78fd9eb2b0f47b42d943d12f9c73cc6eb51ef3ba20a931b7a4cc6c0fd214ece15214a029fc0ab28d6b028b774f652a10940806d3df5e014
7
- data.tar.gz: 44566e265fbca4419f15cc8d59948804f72b133092fe5a920bcd80bc889959ccee201395c3cf8c76849daa552d9ecbc094d271ff5885a0e972a2ad8b1752dfb1
6
+ metadata.gz: 69ec6408d396d9e4c75bc4ba3ef1c71f82ea2a7bbd67def082262b275c20b9769db851fdb2c1bea971a4ede35c10b6f325fbc35a73be8591f12a986e94a01637
7
+ data.tar.gz: b71662890f9710012a329db3f380f831e10a8d37671fd9db2a9e3b84d237c699c0c40892020e4f20c781b36ab68563205208bc51607f73f5b2f002c80b5c48de
@@ -0,0 +1,27 @@
1
+ name: test
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ pull_request:
7
+ types:
8
+ - opened
9
+ - synchronize
10
+ - reopened
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ container: ${{ matrix.ruby }}
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ ruby:
19
+ - ruby:2.5
20
+ - ruby:2.6
21
+ - ruby:2.7
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - name: bundle install
25
+ run: bundle install -j$(nproc) --retry 3
26
+ - run: bundle exec rspec
27
+ timeout-minutes: 1
@@ -1,6 +1,30 @@
1
+ ## v0.2.1
2
+
3
+ * Generate `example` of request body and path / query params
4
+ [#4](https://github.com/k0kubun/rspec-openapi/issues/4)
5
+ * Remove a wrapper param created by Rails in request body
6
+ [#4](https://github.com/k0kubun/rspec-openapi/issues/4)
7
+
8
+ ## v0.2.0
9
+
10
+ * Generate `example` of response body [#3](https://github.com/k0kubun/rspec-openapi/issues/3)
11
+
12
+ ## v0.1.5
13
+
14
+ * Support detecting `float` type [#2](https://github.com/k0kubun/rspec-openapi/issues/2)
15
+
16
+ ## v0.1.4
17
+
18
+ * Avoid NoMethodError on nil Content-Type
19
+ * Include a space between controller and action in summary
20
+
21
+ ## v0.1.3
22
+
23
+ * Add `RSpec::OpenAPI.comment` configuration
24
+
1
25
  ## v0.1.2
2
26
 
3
- * Generate `required: true` for path params
27
+ * Generate `required: true` for path params [#1](https://github.com/k0kubun/rspec-openapi/issues/1)
4
28
 
5
29
  ## v0.1.1
6
30
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # rspec-openapi
1
+ # rspec-openapi ![test](https://github.com/k0kubun/rspec-openapi/workflows/test/badge.svg)
2
2
 
3
- Generate OpenAPI specs from RSpec request specs.
3
+ Generate OpenAPI schema from RSpec request specs.
4
4
 
5
5
  ## What's this?
6
6
 
@@ -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:
@@ -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
- If you want to change the path to generate a spec from `doc/openapi.yaml`, use:
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?
@@ -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
@@ -15,7 +15,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
15
15
  path: route.path.spec.to_s.delete_suffix('(.:format)'),
16
16
  path_params: request.path_parameters,
17
17
  query_params: request.query_parameters,
18
- request_params: request.request_parameters,
18
+ request_params: raw_request_params(request),
19
19
  request_content_type: request.content_type,
20
20
  controller: route.requirements[:controller],
21
21
  action: route.requirements[:action],
@@ -35,4 +35,13 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
35
35
  end
36
36
  raise "No route matched for #{request.request_method} #{request.path_info}"
37
37
  end
38
+
39
+ # workaround to get real request parameters
40
+ # because ActionController::ParamsWrapper overwrites request_parameters
41
+ def raw_request_params(request)
42
+ original = request.delete_header('action_dispatch.request.request_parameters')
43
+ request.request_parameters
44
+ ensure
45
+ request.set_header('action_dispatch.request.request_parameters', original)
46
+ end
38
47
  end
@@ -6,7 +6,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
6
6
  paths: {
7
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: {
@@ -15,6 +15,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
15
15
  content: {
16
16
  normalize_content_type(record.response_content_type) => {
17
17
  schema: build_property(record.response_body),
18
+ example: record.response_body,
18
19
  },
19
20
  },
20
21
  },
@@ -37,6 +38,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
37
38
  in: 'path',
38
39
  required: true,
39
40
  schema: build_property(try_cast(value)),
41
+ example: try_cast(value),
40
42
  }
41
43
  end
42
44
 
@@ -45,6 +47,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
45
47
  name: key.to_s,
46
48
  in: 'query',
47
49
  schema: build_property(try_cast(value)),
50
+ example: try_cast(value),
48
51
  }
49
52
  end
50
53
 
@@ -60,6 +63,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
60
63
  content: {
61
64
  normalize_content_type(record.request_content_type) => {
62
65
  schema: build_property(record.request_params),
66
+ example: record.request_params,
63
67
  }
64
68
  }
65
69
  }
@@ -84,6 +88,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
84
88
  case value
85
89
  when String
86
90
  'string'
91
+ when Float
92
+ 'float'
87
93
  when Integer
88
94
  'integer'
89
95
  when TrueClass, FalseClass
@@ -113,6 +119,6 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
113
119
  end
114
120
 
115
121
  def normalize_content_type(content_type)
116
- content_type.sub(/;.+\z/, '')
122
+ content_type&.sub(/;.+\z/, '')
117
123
  end
118
124
  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.2.1'
4
4
  end
5
5
  end
@@ -6,15 +6,15 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ['Takashi Kokubun']
7
7
  spec.email = ['takashikkbn@gmail.com']
8
8
 
9
- spec.summary = %q{Generate OpenAPI specs from RSpec request specs}
10
- spec.description = %q{Generate OpenAPI specs from RSpec request specs}
9
+ spec.summary = %q{Generate OpenAPI schema from RSpec request specs}
10
+ spec.description = %q{Generate OpenAPI from RSpec request specs}
11
11
  spec.homepage = 'https://github.com/k0kubun/rspec-openapi'
12
12
  spec.license = 'MIT'
13
13
  spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
14
14
 
15
15
  spec.metadata['homepage_uri'] = spec.homepage
16
16
  spec.metadata['source_code_uri'] = spec.homepage
17
- # spec.metadata['changelog_uri'] = 'TODO'
17
+ spec.metadata['changelog_uri'] = File.join(spec.homepage, 'blob/master/CHANGELOG.md')
18
18
 
19
19
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
20
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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.2
4
+ version: 0.2.1
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-19 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,13 +24,14 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: Generate OpenAPI specs from RSpec request specs
27
+ description: Generate OpenAPI from RSpec request specs
28
28
  email:
29
29
  - takashikkbn@gmail.com
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".github/workflows/test.yml"
34
35
  - ".gitignore"
35
36
  - ".rspec"
36
37
  - ".travis.yml"
@@ -57,6 +58,7 @@ licenses:
57
58
  metadata:
58
59
  homepage_uri: https://github.com/k0kubun/rspec-openapi
59
60
  source_code_uri: https://github.com/k0kubun/rspec-openapi
61
+ changelog_uri: https://github.com/k0kubun/rspec-openapi/blob/master/CHANGELOG.md
60
62
  post_install_message:
61
63
  rdoc_options: []
62
64
  require_paths:
@@ -72,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  - !ruby/object:Gem::Version
73
75
  version: '0'
74
76
  requirements: []
75
- rubygems_version: 3.1.2
77
+ rubygems_version: 3.2.0.pre1
76
78
  signing_key:
77
79
  specification_version: 4
78
- summary: Generate OpenAPI specs from RSpec request specs
80
+ summary: Generate OpenAPI schema from RSpec request specs
79
81
  test_files: []