Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ AllCops:

inherit_from: .rubocop_todo.yml

require:
- rubocop-rake
- rubocop-rspec

Naming/FileName:
Enabled: false

Expand Down
126 changes: 88 additions & 38 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 5000`
# on 2023-07-06 20:16:40 UTC using RuboCop version 1.42.0.
# `rubocop --auto-gen-config`
# on 2024-09-09 22:35:29 UTC using RuboCop version 1.66.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -28,7 +28,7 @@ Lint/EmptyBlock:
Exclude:
- 'spec/grape-swagger/entity/attribute_parser_spec.rb'

# Offense count: 1
# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedMethods.
# AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal?
Expand All @@ -37,59 +37,109 @@ Lint/RedundantSafeNavigation:
- 'lib/grape-swagger/entity/attribute_parser.rb'

# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes, Max.
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'

# Offense count: 13
# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
# AllowedMethods: refine
Metrics/BlockLength:
Exclude:
- '**/*.gemspec'
- 'spec/grape-swagger/entities/response_model_spec.rb'
- 'spec/grape-swagger/entity/attribute_parser_spec.rb'
- 'spec/grape-swagger/entity/parser_spec.rb'
- 'spec/support/shared_contexts/this_api.rb'
Max: 34

# Offense count: 1
# Configuration parameters: CountComments, Max, CountAsOne.
# Offense count: 2
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'
Max: 112

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, Max.
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'
Max: 11

# Offense count: 5
# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
# Offense count: 7
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'
Max: 28

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, Max.
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'
Max: 13

# Offense count: 2
# Offense count: 5
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'spec/grape-swagger/entities/response_model_spec.rb'

# Offense count: 1
RSpec/BeforeAfterAll:
Exclude:
- '**/spec/spec_helper.rb'
- '**/spec/rails_helper.rb'
- '**/spec/support/**/*.rb'
- 'spec/grape-swagger/entities/response_model_spec.rb'

# Offense count: 4
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/grape-swagger/entity/parser_spec.rb'
- 'spec/support/shared_contexts/inheritance_api.rb'
- 'spec/support/shared_contexts/this_api.rb'

# Offense count: 2
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- '**/spec/features/**/*'
- '**/spec/requests/**/*'
- '**/spec/routing/**/*'
- '**/spec/system/**/*'
- '**/spec/views/**/*'
- 'spec/grape-swagger/entities/response_model_spec.rb'

# Offense count: 4
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 172

# Offense count: 24
RSpec/LeakyConstantDeclaration:
Exclude:
- 'spec/grape-swagger/entities/response_model_spec.rb'
- 'spec/support/shared_contexts/inheritance_api.rb'
- 'spec/support/shared_contexts/this_api.rb'

# Offense count: 1
RSpec/MultipleDescribes:
Exclude:
- 'spec/grape-swagger/entities/response_model_spec.rb'

# Offense count: 5
RSpec/MultipleExpectations:
Max: 11

# Offense count: 20
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/grape-swagger/entities/response_model_spec.rb'

# Offense count: 39
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 5

# Offense count: 3
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
# Include: **/*_spec.rb
RSpec/SpecFilePathFormat:
Exclude:
- '**/spec/routing/**/*'
- 'spec/grape-swagger/entity/attribute_parser_spec.rb'
- 'spec/grape-swagger/entity/parser_spec.rb'
- 'spec/grape-swagger/entity_spec.rb'

# Offense count: 4
# Configuration parameters: AllowedConstants.
Style/Documentation:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ group :development, :test do
gem 'rdoc'
gem 'rspec'
gem 'rubocop'
gem 'rubocop-rake'
gem 'rubocop-rspec'
end

gem 'grape-swagger', git: 'https://github.com/ruby-grape/grape-swagger.git'
Expand Down
4 changes: 2 additions & 2 deletions grape-swagger-entity.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']

s.required_ruby_version = '>= 3.0'
s.add_runtime_dependency 'grape-entity', '~> 1'
s.add_runtime_dependency 'grape-swagger', '~> 2'
s.add_dependency 'grape-entity', '~> 1'
s.add_dependency 'grape-swagger', '~> 2'
s.metadata['rubygems_mfa_required'] = 'true'
end
22 changes: 11 additions & 11 deletions spec/grape-swagger/entities/response_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
require 'spec_helper'

describe 'responseModel' do
subject do
get '/swagger_doc/something'
JSON.parse(last_response.body)
end

include_context 'this api'

def app
ThisApi::ResponseModelApi
end

subject do
get '/swagger_doc/something'
JSON.parse(last_response.body)
end

it 'documents index action' do
expect(subject['paths']['/something']['get']['responses']).to eq(
'200' => {
Expand All @@ -26,7 +26,7 @@ def app
)
end

it 'should document specified models as show action' do
it 'documents specified models as show action' do
expect(subject['paths']['/something/{id}']['get']['responses']).to eq(
'200' => {
'description' => 'OK',
Expand Down Expand Up @@ -88,6 +88,11 @@ def app
end

describe 'building definitions from given entities' do
subject do
get '/swagger_doc'
JSON.parse(last_response.body)['definitions']
end

before :all do
module TheseApi
module Entities
Expand Down Expand Up @@ -209,11 +214,6 @@ def app
TheseApi::ResponseEntityApi
end

subject do
get '/swagger_doc'
JSON.parse(last_response.body)['definitions']
end

it 'prefers entity over other `using` values' do
expect(subject['TheseApi_Entities_Values']).to eql(
'type' => 'object',
Expand Down
28 changes: 14 additions & 14 deletions spec/grape-swagger/entity/attribute_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
include_context 'this api'

describe '#call' do
let(:endpoint) {}

subject { described_class.new(endpoint).call(entity_options) }

let(:endpoint) {}

context 'when the entity is a model' do
context 'when it is exposed as an array' do
let(:entity_options) { { using: ThisApi::Entities::Tag, documentation: { is_array: true } } }
Expand Down Expand Up @@ -62,7 +62,7 @@
documentation: { type: 'ThisApi::Kind', desc: 'The kind of this something.' } }
end

it { is_expected.to_not include('type') }
it { is_expected.not_to include('type') }
it { is_expected.to include('$ref' => '#/definitions/Kind') }
end
end
Expand All @@ -88,15 +88,15 @@
context 'when it contains values array' do
let(:entity_options) { { documentation: { type: 'string', desc: 'Colors', values: %w[red blue] } } }

it { is_expected.to_not include('minimum') }
it { is_expected.to_not include('maximum') }
it { is_expected.not_to include('minimum') }
it { is_expected.not_to include('maximum') }
end

context 'when it contains values range' do
let(:entity_options) { { documentation: { type: 'string', desc: 'Colors', values: 'a'...'c' } } }

it { is_expected.to_not include('minimum') }
it { is_expected.to_not include('maximum') }
it { is_expected.not_to include('minimum') }
it { is_expected.not_to include('maximum') }
end

context 'when it contains extensions' do
Expand Down Expand Up @@ -126,8 +126,8 @@
context 'when it contains values array' do
let(:entity_options) { { documentation: { type: 'number', desc: 'Solution pH', values: [6.0, 7.0, 8.0] } } }

it { is_expected.to_not include('minimum') }
it { is_expected.to_not include('maximum') }
it { is_expected.not_to include('minimum') }
it { is_expected.not_to include('maximum') }
end

context 'when it contains values range' do
Expand All @@ -139,14 +139,14 @@
context 'when it contains values range with no minimum' do
let(:entity_options) { { documentation: { type: 'number', desc: 'Solution pH', values: ..14.0 } } }

it { is_expected.to_not include('minimum') }
it { is_expected.not_to include('minimum') }
it { is_expected.to include(maximum: 14.0) }
end

context 'when it contains values range with no maximum' do
let(:entity_options) { { documentation: { type: 'number', desc: 'Solution pH', values: 0.0.. } } }

it { is_expected.to_not include('maximum') }
it { is_expected.not_to include('maximum') }
it { is_expected.to include(minimum: 0.0) }
end

Expand Down Expand Up @@ -177,8 +177,8 @@
context 'when it contains values array' do
let(:entity_options) { { documentation: { type: 'integer', desc: 'Count', values: 1..10 } } }

it { is_expected.to_not include('minimum') }
it { is_expected.to_not include('maximum') }
it { is_expected.not_to include('minimum') }
it { is_expected.not_to include('maximum') }
end

context 'when it contains values range' do
Expand Down Expand Up @@ -241,7 +241,7 @@
let(:entity_options) { { documentation: { type: 'string', desc: 'Content of something.' } } }

it { is_expected.to include(type: 'string') }
it { is_expected.to_not include('$ref') }
it { is_expected.not_to include('$ref') }
end

context 'when it is exposed as a boolean' do
Expand Down
3 changes: 2 additions & 1 deletion spec/grape-swagger/entity/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
end

it 'hides hidden attributes' do
expect(properties).to_not include(:hidden_attr)
expect(properties).not_to include(:hidden_attr)
end
end
end
end

context 'inheritance api' do
include_context 'inheritance api'

Expand Down
2 changes: 1 addition & 1 deletion spec/grape-swagger/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe GrapeSwagger::Entity do
it 'has a version number' do
expect(GrapeSwagger::Entity::VERSION).not_to be nil
expect(GrapeSwagger::Entity::VERSION).not_to be_nil
end

it 'parser should be registred' do
Expand Down