Skip to content

Commit

Permalink
Merge pull request #52 from LeFnord/master
Browse files Browse the repository at this point in the history
Fixes descriminator behaviour.
  • Loading branch information
kzaitsev authored Jun 30, 2020
2 parents 7f290cd + 7548c30 commit 303e0a2
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 42 deletions.
33 changes: 31 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AllCops:
Exclude:
- vendor/**/*
TargetRubyVersion:
2.2
2.7

inherit_from: .rubocop_todo.yml

Expand All @@ -21,5 +21,34 @@ Metrics/MethodLength:
Naming/FileName:
Enabled: false

Layout/IndentFirstHashElement:
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true
Layout/SpaceAroundMethodCallOperator:
Enabled: true
Lint/DeprecatedOpenSSLConstant:
Enabled: true
Lint/MixedRegexpCaptureTypes:
Enabled: true
Lint/RaiseException:
Enabled: true
Lint/StructNewOverride:
Enabled: true
Style/ExponentialNotation:
Enabled: true
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
Style/RedundantFetchBlock:
Enabled: true
Style/RedundantRegexpCharacterClass:
Enabled: true
Style/RedundantRegexpEscape:
Enabled: true
Style/SlicingWithRange:
Enabled: true
45 changes: 22 additions & 23 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-07-03 22:59:40 +0300 using RuboCop version 0.49.1.
# on 2020-06-29 22:12:50 UTC using RuboCop version 0.86.0.
# 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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
Metrics/AbcSize:
Max: 40

# Offense count: 1
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 27
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'grape-swagger-entity.gemspec'

# Offense count: 4
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 30

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 124
Max: 111

# Offense count: 1
# Offense count: 2
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 15

# Offense count: 14
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 120
Max: 11

# Offense count: 3
# Configuration parameters: CountComments.
# Offense count: 5
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 30
Max: 25

# Offense count: 2
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 16
Max: 12

# Offense count: 2
# Offense count: 4
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/grape-swagger/entity.rb'
- 'lib/grape-swagger/entity/parser.rb'
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,27 @@ after_success:
- bundle exec danger

rvm:
- 2.4.5
- 2.5.3
- 2.6.0
- 2.5.8
- 2.6.6
- 2.7.1

env:
- GRAPE_ENTITY=0.6.1
- GRAPE_ENTITY=0.7.1
- GRAPE_ENTITY=0.8.0

matrix:
fast_finish: true

include:
- rvm: 2.3.8
- rvm: 2.4.10
env:
- rvm: ruby-head
env:
- rvm: jruby-head
env:
- rvm: rbx-2
env:

allow_failures:
- rvm: 2.3.8
- rvm: 2.4.10
- rvm: ruby-head
- rvm: jruby-head
- rvm: rbx-2
2 changes: 2 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

danger.import_dangerfile(gem: 'ruby-grape-danger')
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in grape-swagger-entity.gemspec
Expand All @@ -12,8 +14,8 @@ group :development, :test do
gem 'rack-test'
gem 'rake'
gem 'rdoc'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 0.68.1'
gem 'rspec', '~> 3.9'
gem 'rubocop', '~> 0.85'
end

gem 'grape-swagger', git: 'https://github.com/ruby-grape/grape-swagger.git'
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rubygems'
require 'bundler'

Expand Down
1 change: 1 addition & 0 deletions bin/pry
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'grape-swagger/entity'
Expand Down
6 changes: 4 additions & 2 deletions grape-swagger-entity.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'grape-swagger/entity/version'
Expand All @@ -17,7 +19,7 @@ Gem::Specification.new do |s|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
s.require_paths = ['lib']

s.required_ruby_version = '>= 2.2.6'
s.add_runtime_dependency 'grape-entity', '>= 0.5.0'
s.required_ruby_version = '>= 2.4'
s.add_runtime_dependency 'grape-entity', '>= 0.6.0'
s.add_runtime_dependency 'grape-swagger', '>= 1.0.0'
end
2 changes: 2 additions & 0 deletions lib/grape-swagger-entity.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'grape-swagger/entity'
2 changes: 2 additions & 0 deletions lib/grape-swagger/entity.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'grape-swagger'
require 'grape-entity'

Expand Down
7 changes: 4 additions & 3 deletions lib/grape-swagger/entity/attribute_parser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module GrapeSwagger
module Entity
class AttributeParser
Expand Down Expand Up @@ -65,8 +67,7 @@ def direct_model_type?(type)
end

def ambiguous_model_type?(type)
type &&
type.is_a?(Class) &&
type&.is_a?(Class) &&
!GrapeSwagger::DocMethods::DataType.primitive?(type.name.downcase) &&
!type == Array
end
Expand All @@ -87,7 +88,7 @@ def document_data_type(documentation, data_type)
else
{ type: data_type }
end
type[:format] = documentation[:format] if documentation && documentation.key?(:format)
type[:format] = documentation[:format] if documentation&.key?(:format)

type
end
Expand Down
4 changes: 3 additions & 1 deletion lib/grape-swagger/entity/helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module GrapeSwagger
module Entity
# Helper methods for DRY
Expand All @@ -13,7 +15,7 @@ def model_name(entity_model, endpoint)

def discriminator(entity_model)
entity_model.superclass.root_exposures.detect do |value|
value.documentation.dig(:is_discriminator)
value.documentation&.dig(:is_discriminator)
end
end

Expand Down
3 changes: 3 additions & 0 deletions lib/grape-swagger/entity/parser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module GrapeSwagger
module Entity
class Parser
Expand All @@ -19,6 +21,7 @@ def call

class Alias
attr_reader :original, :renamed

def initialize(original, renamed)
@original = original
@renamed = renamed
Expand Down
4 changes: 3 additions & 1 deletion lib/grape-swagger/entity/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

module GrapeSwagger
module Entity
VERSION = '0.4.0'.freeze
VERSION = '0.4.0'
end
end
2 changes: 2 additions & 0 deletions spec/grape-swagger/entities/response_model_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'responseModel' do
Expand Down
2 changes: 2 additions & 0 deletions spec/grape-swagger/entity/attribute_parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require_relative '../../../spec/support/shared_contexts/this_api'

Expand Down
2 changes: 2 additions & 0 deletions spec/grape-swagger/entity/parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require_relative '../../../spec/support/shared_contexts/this_api'

Expand Down
2 changes: 2 additions & 0 deletions spec/grape-swagger/entity_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe GrapeSwagger::Entity do
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path('lib', __dir__)

require 'grape-swagger/entity'
Expand Down
2 changes: 2 additions & 0 deletions spec/support/shared_contexts/inheritance_api.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

shared_context 'inheritance api' do
before :all do
module InheritanceApi
Expand Down
2 changes: 2 additions & 0 deletions spec/support/shared_contexts/this_api.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

shared_context 'this api' do
before :all do
module ThisApi
Expand Down

0 comments on commit 303e0a2

Please sign in to comment.