Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: schema cleaner parent['required'] may be nil #119

Closed
wants to merge 1 commit into from

Conversation

bf4
Copy link
Contributor

@bf4 bf4 commented Jun 26, 2023

We had to patch the schema cleaner in our app since it was raising a NoMethodError

require "rspec/openapi"
require "rspec/openapi/schema_cleaner"
RSpec::OpenAPI::SchemaCleaner # ensure this is loaded # rubocop:todo Lint/Void
class << RSpec::OpenAPI::SchemaCleaner
  def cleanup_empty_required_array!(base)
    paths_to_objects = [
      *RSpec::OpenAPI::HashHelper.matched_paths_deeply_nested(base, "components.schemas", "properties"),
      *RSpec::OpenAPI::HashHelper.matched_paths_deeply_nested(base, "paths", "properties"),
    ]
    paths_to_objects.each do |path|
      parent = base.dig(*path.take(path.length - 1))
      # "required" array  must not be present if empty
      # parent.delete('required') if parent['required'].empty?
      # NOTE(BF): hack around schema error
      # NoMethodError:
      #   undefined method `empty?' for nil:NilClass
      #
      #   parent.delete('required') if parent['required'].empty?
      #                                                  ^^^^^^^
      parent.delete("required") if parent["required"] && parent["required"].empty?
    end
  end
end

@@ -47,7 +47,7 @@
paths_to_objects.each do |path|
parent = base.dig(*path.take(path.length - 1))
# "required" array must not be present if empty
parent.delete('required') if parent['required'].empty?
parent.delete('required') if parent['required']&.empty?

Check warning

Code scanning / Rubocop

Avoid `foo&.empty?` in conditionals. Warning

Lint/SafeNavigationWithEmpty: Avoid calling empty? with the safe navigation operator in conditionals.
@codecov
Copy link

codecov bot commented Jun 26, 2023

Codecov Report

Merging #119 (31575b8) into master (bf8ac1e) will not change coverage.
The diff coverage is 0.00%.

@@           Coverage Diff           @@
##           master     #119   +/-   ##
=======================================
  Coverage   65.88%   65.88%           
=======================================
  Files          31       31           
  Lines         686      686           
=======================================
  Hits          452      452           
  Misses        234      234           
Impacted Files Coverage Δ
lib/rspec/openapi/schema_cleaner.rb 20.83% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@exoego
Copy link
Owner

exoego commented Jun 27, 2023

Sorry for the inconvenience, and thanks for the PR!
I think this was fixed in #118
Closing as duplication.

@exoego exoego closed this Jun 27, 2023
@bf4 bf4 deleted the patch-3 branch June 27, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants