Skip to content

Commit c449900

Browse files
authored
gAuto-correct cops (#6)
* Auto-correct cops * Check rubocop version running in ci * Lock rubocop to version 0.76 There is a breaking change in 0.81 that changes the cop names and namespacing * Remove some unnecessary config
1 parent 77720ef commit c449900

File tree

8 files changed

+200
-188
lines changed

8 files changed

+200
-188
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
- name: Test with rspec
2424
run: |
2525
bundle exec rspec spec/
26-
# TODO: finish fixing cops
27-
# - name: Lint with rubocop
28-
# run: |
29-
# bundle exec rubocop
26+
- name: Lint with rubocop
27+
run: |
28+
bundle exec rubocop --verbose && bundle exec rubocop

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2020-04-09 14:12:08 -0700 using RuboCop version 0.76.0.
3+
# on 2020-04-15 15:50:47 -0700 using RuboCop version 0.76.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new

lib/open_api_parser/document.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module OpenApiParser
24
class Document
35
def self.resolve(path, file_cache = OpenApiParser::FileCache.new)
@@ -34,15 +36,15 @@ def deeply_expand_refs(fragment, current_pointer)
3436
end
3537

3638
def expand_refs(fragment, current_pointer)
37-
if fragment.is_a?(Hash) && fragment.key?("$ref")
38-
raw_uri = fragment["$ref"]
39+
if fragment.is_a?(Hash) && fragment.key?('$ref')
40+
raw_uri = fragment['$ref']
3941
ref = OpenApiParser::Reference.new(raw_uri)
4042
fully_resolved, referrent_document, referrent_pointer =
4143
ref.resolve(@path, current_pointer, @content, @file_cache)
42-
unless fully_resolved
43-
expand_refs(referrent_document, referrent_pointer)
44-
else
44+
if fully_resolved
4545
[referrent_document, referrent_pointer]
46+
else
47+
expand_refs(referrent_document, referrent_pointer)
4648
end
4749
else
4850
[fragment, current_pointer]

lib/open_api_parser/specification.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
module OpenApiParser
24
module Specification
3-
META_SCHEMA_PATH = File.expand_path("../../../resources/swagger_meta_schema.json", __FILE__)
5+
META_SCHEMA_PATH = File.expand_path('../../resources/swagger_meta_schema.json', __dir__)
46

57
def self.resolve(path, validate_meta_schema: true)
68
raw_specification = Document.resolve(path)

open_api_parser.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
3030
spec.add_development_dependency 'pry', '~> 0.12'
3131
spec.add_development_dependency 'rake', '~> 10.0'
3232
spec.add_development_dependency 'rspec', '~> 3.0'
33-
spec.add_development_dependency 'rubocop', '~> 0.76'
33+
spec.add_development_dependency 'rubocop', '<= 0.76' # rubocop 0.86 has breaking change in cop names
3434
end

spec/open_api_parser/document_spec.rb

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
1-
require "spec_helper"
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
24

35
RSpec.describe OpenApiParser::Document do
4-
describe "self.resolve" do
5-
context "yaml" do
6-
it "resolves JSON pointers" do
7-
path = File.expand_path("../../resources/pointer_example.yaml", __FILE__)
6+
describe 'self.resolve' do
7+
context 'yaml' do
8+
it 'resolves JSON pointers' do
9+
path = File.expand_path('../resources/pointer_example.yaml', __dir__)
810
json = OpenApiParser::Document.resolve(path)
911

10-
expect(json["person"]).to eq({
11-
"name" => "Drew"
12-
})
12+
expect(json['person']).to eq(
13+
'name' => 'Drew'
14+
)
1315
end
1416

15-
it "resolves JSON file references" do
16-
path = File.expand_path("../../resources/file_reference_example.yaml", __FILE__)
17+
it 'resolves JSON file references' do
18+
path = File.expand_path('../resources/file_reference_example.yaml', __dir__)
1719
json = OpenApiParser::Document.resolve(path)
1820

19-
expect(json["person"]).to eq({
20-
"name" => "Drew"
21-
})
21+
expect(json['person']).to eq(
22+
'name' => 'Drew'
23+
)
2224

23-
expect(json["person_without_scheme"]).to eq({
24-
"name" => "Drew"
25-
})
25+
expect(json['person_without_scheme']).to eq(
26+
'name' => 'Drew'
27+
)
2628
end
2729

28-
it "resolves a mix of pointers and file references" do
29-
path = File.expand_path("../../resources/mixed_reference_example.yaml", __FILE__)
30+
it 'resolves a mix of pointers and file references' do
31+
path = File.expand_path('../resources/mixed_reference_example.yaml', __dir__)
3032
json = OpenApiParser::Document.resolve(path)
3133

32-
expect(json["person"]["greeting"]).to eq({
33-
"hi" => "Drew"
34-
})
34+
expect(json['person']['greeting']).to eq(
35+
'hi' => 'Drew'
36+
)
3537

36-
expect(json["person"]["stats"]).to eq({
37-
"age" => 34
38-
})
38+
expect(json['person']['stats']).to eq(
39+
'age' => 34
40+
)
3941

40-
expect(json["person_greeting"]).to eq("Drew")
42+
expect(json['person_greeting']).to eq('Drew')
4143
end
4244
end
4345

44-
context "json" do
45-
it "resolves JSON pointers" do
46-
path = File.expand_path("../../resources/pointer_example.json", __FILE__)
46+
context 'json' do
47+
it 'resolves JSON pointers' do
48+
path = File.expand_path('../resources/pointer_example.json', __dir__)
4749
json = OpenApiParser::Document.resolve(path)
4850

49-
expect(json["person"]).to eq({
50-
"name" => "Drew"
51-
})
51+
expect(json['person']).to eq(
52+
'name' => 'Drew'
53+
)
5254
end
5355
end
5456
end

0 commit comments

Comments
 (0)