rspec-openapi 0.7.0 → 0.7.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: 0ce13b09ac314ce43bb224b5c8ff1260f283f2a415032418c3908ac51a4a6b8b
4
- data.tar.gz: dc9aaa1fe4d3f1228bed06e37cf1b26e87e045b3666b244514587204b31a8b78
3
+ metadata.gz: ef97d7a9ebc7c50fb3cc6d6ef7d148c375a190680fa1f2a6d6adb4b4971a4106
4
+ data.tar.gz: 0ca35f6a022fa7a257818b29b5e5dd35d786f2e9374e0833966756bbf1cd51e1
5
5
  SHA512:
6
- metadata.gz: 37d15147e73665c3dd236e971623a4a7a2feafeb08042191d42952e2b46a0526617bdbce87b2294d62856fc96730a92cee538bd408ea8218190ec8d90c7a151f
7
- data.tar.gz: 209e5b659ccaa36c63673314172f1d05e67d1a3d879afb2cb5907d12500dc2fa18c52c42bfc9cb0193d0e4c13a85649f9930b91e52339a5ffa900183aa400be3
6
+ metadata.gz: 32ccb146dafc799631c7dc37c557d278fbe771f3f017263ff38eaf644ec69967369757f6e7aa48ff0074bff38641dd72354203a36a2f399fe80035c62c9bf85d
7
+ data.tar.gz: 5932e0c01b98c0b6d662c43b8a3d26f4fa6709699f9eae0de92dc40cabdfb2b3fd8c2c65bfc65bd2a6ff75ab0edac14490f443bd182a4ca1164d039da2f9b5b2
@@ -0,0 +1,39 @@
1
+ name: "CodeQL"
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ # The branches below must be a subset of the branches above
8
+ branches: [ "master" ]
9
+ schedule:
10
+ - cron: '20 22 * * 2'
11
+
12
+ jobs:
13
+ analyze:
14
+ name: Analyze
15
+ runs-on: ubuntu-latest
16
+ permissions:
17
+ actions: read
18
+ contents: read
19
+ security-events: write
20
+
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ language: [ 'ruby' ]
25
+
26
+ steps:
27
+ - name: Checkout repository
28
+ uses: actions/checkout@v3
29
+
30
+ - name: Initialize CodeQL
31
+ uses: github/codeql-action/init@v2
32
+ with:
33
+ languages: ${{ matrix.language }}
34
+
35
+ - name: Autobuild
36
+ uses: github/codeql-action/autobuild@v2
37
+
38
+ - name: Perform CodeQL Analysis
39
+ uses: github/codeql-action/analyze@v2
@@ -0,0 +1,37 @@
1
+ name: "Rubocop"
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ branches: [ "master" ]
8
+
9
+ jobs:
10
+ rubocop:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+
15
+ steps:
16
+ - name: Checkout repository
17
+ uses: actions/checkout@v3
18
+
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: 2.6
23
+
24
+ - name: Install dependencies
25
+ run: bundle install
26
+
27
+ - name: Rubocop run
28
+ run: |
29
+ bash -c "
30
+ bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
31
+ [[ $? -ne 2 ]]
32
+ "
33
+
34
+ - name: Upload Sarif output
35
+ uses: github/codeql-action/upload-sarif@v2
36
+ with:
37
+ sarif_file: rubocop.sarif
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## v0.7.2
2
+ - $ref enhancements: Support $ref in arbitrary depth
3
+ [#82](https://github.com/k0kubun/rspec-openapi/pull/82)
4
+
5
+ ## v0.7.1
6
+ - $ref enhancements: Auto-generate components referenced in "items"
7
+ [#80](https://github.com/k0kubun/rspec-openapi/pull/80)
8
+ - Administration
9
+ - Setup RuboCop
10
+ [#73](https://github.com/k0kubun/rspec-openapi/pull/73)
11
+ - Setup CodeQL
12
+ [#73](https://github.com/k0kubun/rspec-openapi/pull/73)
13
+ - Bump Rails v6.0.3.x to fix bundle failure
14
+ [#72](https://github.com/k0kubun/rspec-openapi/pull/72)
15
+
16
+ ## v0.7.0
17
+ - Generate Response Headers
18
+ [#69](https://github.com/k0kubun/rspec-openapi/pull/69)
19
+ - Initial support for $ref
20
+ [#67](https://github.com/k0kubun/rspec-openapi/pull/67)
21
+ - Fixed an empty array is turned into nullable object wrongly
22
+ [#70](https://github.com/k0kubun/rspec-openapi/pull/70)
23
+
1
24
  ## v0.6.1
2
25
 
3
26
  * Stabilize the order parameter objects and preserve newer examples
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in rspec-openapi.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rails', ENV['RAILS_VERSION'] || '6.0.3.2'
6
+ gem 'rails', ENV['RAILS_VERSION'] || '6.0.3.7'
7
7
  gem 'roda'
8
8
  gem 'rspec-rails'
9
9
 
@@ -13,4 +13,5 @@ end
13
13
 
14
14
  group :development do
15
15
  gem 'pry'
16
+ gem "code-scanning-rubocop"
16
17
  end
@@ -13,9 +13,15 @@ class << RSpec::OpenAPI::ComponentsUpdater = Object.new
13
13
  generated_schema_names = fresh_schemas.keys
14
14
  nested_refs = find_non_top_level_nested_refs(base, generated_schema_names)
15
15
  nested_refs.each do |paths|
16
- parent_name = paths[-4]
17
- property_name = paths[-2]
18
- nested_schema = fresh_schemas.dig(parent_name, 'properties', property_name)
16
+ # Slice between the parent name and the element before "$ref"
17
+ # ["components", "schema", "Table", "properties", "database", "$ref"]
18
+ # 0 1 2 ^....................^
19
+ # ["components", "schema", "Table", "properties", "columns", "items", "$ref"]
20
+ # 0 1 2 ^...............................^
21
+ # ["components", "schema", "Table", "properties", "owner", "properties", "company", "$ref"]
22
+ # 0 1 2 ^...........................................^
23
+ needle = paths.slice(2, paths.size - 3)
24
+ nested_schema = fresh_schemas.dig(*needle)
19
25
 
20
26
  # Skip if the property using $ref is not found in the parent schema. The property may be removed.
21
27
  next if nested_schema.nil?
@@ -53,8 +59,10 @@ class << RSpec::OpenAPI::ComponentsUpdater = Object.new
53
59
  end
54
60
 
55
61
  def find_non_top_level_nested_refs(base, generated_names)
56
- nested_refs = RSpec::OpenAPI::HashHelper::matched_paths(base, 'components.schemas.*.properties.*.$ref')
57
-
62
+ nested_refs = [
63
+ *RSpec::OpenAPI::HashHelper.matched_paths_deeply_nested(base, 'components.schemas', 'properties.*.$ref'),
64
+ *RSpec::OpenAPI::HashHelper.matched_paths_deeply_nested(base, 'components.schemas', 'properties.*.items.$ref')
65
+ ]
58
66
  # Reject already-generated schemas to reduce unnecessary loop
59
67
  nested_refs.reject do |paths|
60
68
  ref_link = base.dig(*paths)
@@ -20,4 +20,17 @@ class << RSpec::OpenAPI::HashHelper = Object.new
20
20
  end
21
21
  selectors
22
22
  end
23
+
24
+ def matched_paths_deeply_nested(obj, begin_selector, end_selector)
25
+ path_depth_sizes = paths_to_all_fields(obj).map(&:size).uniq
26
+ path_depth_sizes.map do |depth|
27
+ diff = depth - begin_selector.count('.') - end_selector.count('.')
28
+ if diff >= 0
29
+ selector = "#{begin_selector}.#{'*.' * diff}#{end_selector}"
30
+ matched_paths(obj, selector)
31
+ else
32
+ []
33
+ end
34
+ end.flatten(1)
35
+ end
23
36
  end
@@ -12,7 +12,7 @@ error_records = {}
12
12
 
13
13
  RSpec.configuration.after(:each) do |example|
14
14
  if RSpec::OpenAPI.example_types.include?(example.metadata[:type]) && example.metadata[:openapi] != false
15
- path = RSpec::OpenAPI.path.yield_self { |path| path.is_a?(Proc) ? path.call(example) : path }
15
+ path = RSpec::OpenAPI.path.yield_self { |p| p.is_a?(Proc) ? p.call(example) : p }
16
16
  record = RSpec::OpenAPI::RecordBuilder.build(self, example: example)
17
17
  path_records[path] << record if record
18
18
  end
@@ -1,5 +1,5 @@
1
1
  RSpec::OpenAPI::Record = Struct.new(
2
- :method, # @param [String] - "GET"
2
+ :http_method, # @param [String] - "GET"
3
3
  :path, # @param [String] - "/v1/status/:id"
4
4
  :path_params, # @param [Hash] - {:controller=>"v1/statuses", :action=>"create", :id=>"1"}
5
5
  :query_params, # @param [Hash] - {:query=>"string"}
@@ -49,7 +49,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
49
49
  end
50
50
 
51
51
  RSpec::OpenAPI::Record.new(
52
- method: request.request_method,
52
+ http_method: request.method,
53
53
  path: path,
54
54
  path_params: raw_path_params(request),
55
55
  query_params: request.query_parameters,
@@ -22,7 +22,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
22
22
  {
23
23
  paths: {
24
24
  normalize_path(record.path) => {
25
- record.method.downcase => {
25
+ record.http_method.downcase => {
26
26
  summary: record.summary,
27
27
  tags: record.tags,
28
28
  parameters: build_parameters(record),
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.7.0'
3
+ VERSION = '0.7.2'.freeze
4
4
  end
5
5
  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.7.0
4
+ version: 0.7.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: 2022-08-24 00:00:00.000000000 Z
11
+ date: 2022-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -46,6 +46,8 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".github/FUNDING.yml"
49
+ - ".github/workflows/codeql-analysis.yml"
50
+ - ".github/workflows/rubocop.yml"
49
51
  - ".github/workflows/test.yml"
50
52
  - ".gitignore"
51
53
  - ".rspec"
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  - !ruby/object:Gem::Version
93
95
  version: '0'
94
96
  requirements: []
95
- rubygems_version: 3.1.6
97
+ rubygems_version: 3.3.24
96
98
  signing_key:
97
99
  specification_version: 4
98
100
  summary: Generate OpenAPI schema from RSpec request specs