rspec-openapi 0.1.3 → 0.2.2

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: 934be20ed834fa8fa6c975eccf5c63f218b06a80136e6a50920914d4bfd867d0
4
- data.tar.gz: 4921448fe86bf5ad591cf73ab965c38667df4d37daa319d696e8c42e614dcb7a
3
+ metadata.gz: 11f6fd4a506ac6f481fa67c33e2bacecba3ee4e568339338acf4237f4f599bac
4
+ data.tar.gz: 45ea7bbf466a413d3eb5d32ae19a38591c542431eee4dcb21905b8070b2280ac
5
5
  SHA512:
6
- metadata.gz: d45c922230748ab26637a1865aa4cd82a201f84a314b0c18a2a9ed820c9819b17f8506bcc8dbc6e67f0b6b84ed6eb88de061d53981ef99dacdcfdf54c09dbb27
7
- data.tar.gz: 3ffb70c7167f312511febf9969e69ef8e3bc6b6757115ae3f400a46d9628475e5681e976e389011459e5a7891940fbbb62089d059b962e055e4c0306ce1a6a44
6
+ metadata.gz: 3b98372303bb006dba766c0b48218c4be8a45a84f470d6cdfc40b3e7f9d780edb484ca58373239a6aeeba83c7f4c8c3daf8c241cdcb903cc1158c80c92269203
7
+ data.tar.gz: 8a198194bdc3e4bf0d09f6fe66b1893da1eaa4b0333c1168b9bd309ba26634ab16d53342c140f8d7b4c0f31e02cfc1ba9629b5dc12905dfc5e6eb35990f23c30
@@ -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,3 +1,27 @@
1
+ ## v0.2.2
2
+
3
+ * Allow disabling `example` by `RSpec::OpenAPI.enable_example = false`
4
+
5
+ ## v0.2.1
6
+
7
+ * Generate `example` of request body and path / query params
8
+ [#4](https://github.com/k0kubun/rspec-openapi/issues/4)
9
+ * Remove a wrapper param created by Rails in request body
10
+ [#4](https://github.com/k0kubun/rspec-openapi/issues/4)
11
+
12
+ ## v0.2.0
13
+
14
+ * Generate `example` of response body [#3](https://github.com/k0kubun/rspec-openapi/issues/3)
15
+
16
+ ## v0.1.5
17
+
18
+ * Support detecting `float` type [#2](https://github.com/k0kubun/rspec-openapi/issues/2)
19
+
20
+ ## v0.1.4
21
+
22
+ * Avoid NoMethodError on nil Content-Type
23
+ * Include a space between controller and action in summary
24
+
1
25
  ## v0.1.3
2
26
 
3
27
  * Add `RSpec::OpenAPI.comment` configuration
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
 
@@ -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,12 +98,15 @@ 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
104
  # Change the path to generate schema from `doc/openapi.yaml`
105
105
  RSpec::OpenAPI.path = 'doc/schema.yaml'
106
106
 
107
+ # Disable generating `example`
108
+ RSpec::OpenAPI.enable_example = false
109
+
107
110
  # Generate a comment on top of a schema file
108
111
  RSpec::OpenAPI.comment = <<~EOS
109
112
  This file is auto-generated by rspec-openapi https://github.com/k0kubun/rspec-openapi
@@ -138,9 +141,9 @@ end
138
141
 
139
142
  ## Project status
140
143
 
141
- PoC / Experimental
144
+ Beta
142
145
 
143
- This worked for some of my Rails apps, but this may raise a basic error for your app.
146
+ Basic features are there, and some people are already using this.
144
147
 
145
148
  ### Current limitations
146
149
 
@@ -3,8 +3,10 @@ require 'rspec/openapi/hooks' if ENV['OPENAPI']
3
3
 
4
4
  module RSpec::OpenAPI
5
5
  @path = 'doc/openapi.yaml'
6
+ @comment = nil
7
+ @enable_example = true
6
8
 
7
9
  class << self
8
- attr_accessor :path, :comment
10
+ attr_accessor :path, :comment, :enable_example
9
11
  end
10
12
  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,7 +15,8 @@ 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
- },
18
+ example: (record.response_body if example_enabled?),
19
+ }.compact,
19
20
  },
20
21
  },
21
22
  },
@@ -27,6 +28,10 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
27
28
 
28
29
  private
29
30
 
31
+ def example_enabled?
32
+ RSpec::OpenAPI.enable_example
33
+ end
34
+
30
35
  def build_parameters(record)
31
36
  parameters = []
32
37
 
@@ -37,7 +42,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
37
42
  in: 'path',
38
43
  required: true,
39
44
  schema: build_property(try_cast(value)),
40
- }
45
+ example: (try_cast(value) if example_enabled?),
46
+ }.compact
41
47
  end
42
48
 
43
49
  record.query_params.each do |key, value|
@@ -45,7 +51,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
45
51
  name: key.to_s,
46
52
  in: 'query',
47
53
  schema: build_property(try_cast(value)),
48
- }
54
+ example: (try_cast(value) if example_enabled?),
55
+ }.compact
49
56
  end
50
57
 
51
58
  return nil if parameters.empty?
@@ -60,7 +67,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
60
67
  content: {
61
68
  normalize_content_type(record.request_content_type) => {
62
69
  schema: build_property(record.request_params),
63
- }
70
+ example: (record.request_params if example_enabled?),
71
+ }.compact
64
72
  }
65
73
  }
66
74
  end
@@ -84,6 +92,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
84
92
  case value
85
93
  when String
86
94
  'string'
95
+ when Float
96
+ 'float'
87
97
  when Integer
88
98
  'integer'
89
99
  when TrueClass, FalseClass
@@ -113,6 +123,6 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
113
123
  end
114
124
 
115
125
  def normalize_content_type(content_type)
116
- content_type.sub(/;.+\z/, '')
126
+ content_type&.sub(/;.+\z/, '')
117
127
  end
118
128
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.1.3'
3
+ VERSION = '0.2.2'
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.3
4
+ version: 0.2.2
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-07-02 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:
@@ -75,5 +77,5 @@ requirements: []
75
77
  rubygems_version: 3.1.2
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: []