rspec-openapi 0.7.1 → 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: c1b6910e5f6511e985a899e1c3b7dacec413924a6f19d79fddc5b9e4c5059c4a
4
- data.tar.gz: 8bccc7c850b4d1f1cea4125abba829fc8a128bc2bfe448ae4fa1523a11f0a414
3
+ metadata.gz: ef97d7a9ebc7c50fb3cc6d6ef7d148c375a190680fa1f2a6d6adb4b4971a4106
4
+ data.tar.gz: 0ca35f6a022fa7a257818b29b5e5dd35d786f2e9374e0833966756bbf1cd51e1
5
5
  SHA512:
6
- metadata.gz: 60661ba7a0f3828bcbe20437c280a791e90fcd0b00e64f4d27a7052b000c3c70640b45ba1976749df47693d956b97cf4aa491db7957ceb3383dba16e3901da38
7
- data.tar.gz: 3a4431f735c5b2bc6684d8f79ed5ced925edb1c8941f449ccbc02e80bec4401ef4fe65bd5af45c1096fee4b6ca766b46b7bc15d49e4aad0405feb70f44f5b3cd
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,5 +1,9 @@
1
+ ## v0.7.2
2
+ - $ref enhancements: Support $ref in arbitrary depth
3
+ [#82](https://github.com/k0kubun/rspec-openapi/pull/82)
4
+
1
5
  ## v0.7.1
2
- - $ref enhancements: Generate Response Headers
6
+ - $ref enhancements: Auto-generate components referenced in "items"
3
7
  [#80](https://github.com/k0kubun/rspec-openapi/pull/80)
4
8
  - Administration
5
9
  - Setup RuboCop
data/Gemfile CHANGED
@@ -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.1'.freeze
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.1
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-11-08 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"