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

Remove unused codes #162

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/openapi_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,11 @@ def parse_file(content, ext)
end

def parse_yaml(content)
# FIXME: when drop ruby 2.5, we should use permitted_classes
(Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.6.0")) ?
Psych.safe_load(content, [Date, Time]) :
Psych.safe_load(content, permitted_classes: [Date, Time])
Psych.safe_load(content, permitted_classes: [Date, Time])
end

def parse_json(content)
raise "json content is nil" unless content
raise "json content is nil" unless content
JSON.parse(content)
end

Expand Down
5 changes: 1 addition & 4 deletions lib/openapi_parser/schema_validator/string_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ def validate_max_min_length(value, schema)
def validate_email_format(value, schema)
return [value, nil] unless schema.format == 'email'

# match? method is good performance.
# So when we drop ruby 2.3 support we use match? method because this method add ruby 2.4
#return [value, nil] if value.match?(URI::MailTo::EMAIL_REGEXP)
return [value, nil] if value.match(URI::MailTo::EMAIL_REGEXP)
return [value, nil] if value.match?(URI::MailTo::EMAIL_REGEXP)

return [nil, OpenAPIParser::InvalidEmailFormat.new(value, schema.object_reference)]
end
Expand Down
6 changes: 1 addition & 5 deletions spec/openapi_parser/request_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@
it do
expect { subject }.to raise_error do |e|
expect(e).to be_kind_of(OpenAPIParser::ValidateError)
if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
expect(e.message).to end_with("expected string, but received Fixnum: 1")
else
expect(e.message).to end_with("expected string, but received Integer: 1")
end
expect(e.message).to end_with("expected string, but received Integer: 1")
end
end
end
Expand Down
25 changes: 4 additions & 21 deletions spec/openapi_parser/schema_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,7 @@
nested_array = params['nested_array']
first_data = nested_array[0]
expect(first_data['update_time'].class).to eq DateTime

if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
expect(first_data['per_page'].class).to eq Fixnum # rubocop:disable Lint/UnifiedInteger
else
expect(first_data['per_page'].class).to eq Integer
end
expect(first_data['per_page'].class).to eq Integer
end
end

Expand Down Expand Up @@ -774,27 +769,15 @@
nested_array = params['nested_array']
first_data = nested_array[0]
expect(first_data['update_time'].class).to eq String
if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
expect(first_data['per_page'].class).to eq Fixnum # rubocop:disable Lint/UnifiedInteger
else
expect(first_data['per_page'].class).to eq Integer
end
expect(first_data['per_page'].class).to eq Integer

second_data = nested_array[1]
expect(second_data['update_time'].class).to eq String
if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
expect(first_data['per_page'].class).to eq Fixnum # rubocop:disable Lint/UnifiedInteger
else
expect(first_data['per_page'].class).to eq Integer
end
expect(first_data['per_page'].class).to eq Integer
expect(second_data['threshold'].class).to eq Float

third_data = nested_array[2]
if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.4.0')
expect(first_data['per_page'].class).to eq Fixnum # rubocop:disable Lint/UnifiedInteger
else
expect(first_data['per_page'].class).to eq Integer
end
expect(first_data['per_page'].class).to eq Integer
expect(third_data['threshold'].class).to eq Float

expect(first_data['nested_coercer_object']['update_time'].class).to eq String
Expand Down