accepts string as entity (#527)

- adds changelog entry
- requires min version of rubocop
This commit is contained in:
peter scholz 2016-10-31 12:14:08 +01:00 committed by GitHub
parent 7d405ff714
commit 57947d308e
16 changed files with 117 additions and 71 deletions

View File

@ -4,3 +4,7 @@ AllCops:
- example/**/*
inherit_from: .rubocop_todo.yml
Metrics/LineLength:
Exclude:
- spec/**/*

View File

@ -1,30 +1,20 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-05-11 23:53:37 +0300 using RuboCop version 0.40.0.
# on 2016-10-31 11:51:42 +0100 using RuboCop version 0.45.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: 1
Lint/AmbiguousOperator:
Exclude:
- 'spec/lib/move_params_spec.rb'
# Offense count: 1
Lint/UnreachableCode:
Exclude:
- 'example/config.ru'
# Offense count: 1
Lint/UselessAssignment:
Exclude:
- 'spec/lib/move_params_spec.rb'
# Offense count: 27
Metrics/AbcSize:
Max: 56
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/BlockLength:
Max: 30
# Offense count: 3
# Configuration parameters: CountComments.
Metrics/ClassLength:
@ -32,38 +22,32 @@ Metrics/ClassLength:
# Offense count: 10
Metrics/CyclomaticComplexity:
Max: 16
Max: 15
# Offense count: 719
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# Offense count: 803
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
# URISchemes: http, https
Metrics/LineLength:
Max: 454
Max: 160
# Offense count: 31
# Offense count: 34
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 101
# Offense count: 6
# Offense count: 5
Metrics/PerceivedComplexity:
Max: 17
Max: 16
# Offense count: 4
# Offense count: 3
Style/ClassVars:
Exclude:
- 'example/api/endpoints.rb'
- 'lib/grape-swagger/doc_methods.rb'
# Offense count: 27
# Offense count: 23
Style/Documentation:
Enabled: false
# Offense count: 1
Style/DoubleNegation:
Exclude:
- 'example/api/endpoints.rb'
# Offense count: 5
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
Style/FileName:
@ -74,7 +58,20 @@ Style/FileName:
- 'spec/swagger_v2/api_swagger_v2_type-format_spec.rb'
- 'spec/swagger_v2/grape-swagger_spec.rb'
# Offense count: 3
# Offense count: 94
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: when_needed, always
Style/FrozenStringLiteralComment:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
Style/MultilineIfModifier:
Exclude:
- 'lib/grape-swagger/grape/route.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed

View File

@ -19,6 +19,8 @@ matrix:
env: GRAPE_VERSION=0.16.2
- rvm: 2.3.1
env: GRAPE_VERSION=0.17.0
- rvm: 2.3.1
env: GRAPE_VERSION=0.18.0
- rvm: 2.3.1
env: GRAPE_VERSION=HEAD
- rvm: 2.3.0

View File

@ -10,6 +10,7 @@
#### Fixes
* [#527](https://github.com/ruby-grape/grape-swagger/pull/527): Accepts string as entity - [@LeFnord](https://github.com/LeFnord).
* [#515](https://github.com/ruby-grape/grape-swagger/pull/515): Removes limit on model names - [@LeFnord](https://github.com/LeFnord).
* [#511](https://github.com/ruby-grape/grape-swagger/pull/511): Fix incorrect data type linking for request params of entity types - [@serggl](https://github.com/serggl).
* Your contribution here.

View File

@ -2,7 +2,7 @@ source 'http://rubygems.org'
gemspec
case version = ENV['GRAPE_VERSION'] || '~> 0.17.0'
case version = ENV['GRAPE_VERSION'] || '~> 0.18'
when 'HEAD'
gem 'grape', github: 'ruby-grape/grape'
else

View File

@ -8,7 +8,7 @@ Gem::Specification.new do |s|
s.authors = ['Tim Vandecasteele']
s.email = ['tim.vandecasteele@gmail.com']
s.homepage = 'https://github.com/ruby-grape/grape-swagger'
s.summary = 'A simple way to add auto generated documentation to your Grape API that can be displayed with Swagger.'
s.summary = 'Add auto generated documentation to your Grape API that can be displayed with Swagger.'
s.license = 'MIT'
s.add_runtime_dependency 'grape', '>= 0.12.0'
@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'bundler'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'rack-cors'
s.add_development_dependency 'rubocop', '0.40.0'
s.add_development_dependency 'rubocop', '~> 0.40'
s.add_development_dependency 'kramdown'
s.add_development_dependency 'redcarpet' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
s.add_development_dependency 'rouge' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')

View File

@ -52,7 +52,9 @@ module Grape
combine_namespace_routes(@target_class.combined_namespaces)
exclusive_route_keys = @target_class.combined_routes.keys - @target_class.combined_namespaces.keys
exclusive_route_keys.each { |key| @target_class.combined_namespace_routes[key] = @target_class.combined_routes[key] }
exclusive_route_keys.each do |key|
@target_class.combined_namespace_routes[key] = @target_class.combined_routes[key]
end
documentation_class
end
@ -128,10 +130,12 @@ module Grape
end
parent_standalone_namespaces = standalone_namespaces.reject { |ns_name, _| !name.start_with?(ns_name) }
# add only to the main route if the namespace is not within any other namespace appearing as standalone resource
# add only to the main route
# if the namespace is not within any other namespace appearing as standalone resource
if parent_standalone_namespaces.empty?
# default option, append namespace methods to parent route
@target_class.combined_namespace_routes[parent_route_name] = [] unless @target_class.combined_namespace_routes.key?(parent_route_name)
parent_route = @target_class.combined_namespace_routes.key?(parent_route_name)
@target_class.combined_namespace_routes[parent_route_name] = [] unless parent_route
@target_class.combined_namespace_routes[parent_route_name].push(*namespace_routes)
end
end
@ -175,7 +179,9 @@ module Grape
# skip if sub_ns is standalone, too
next unless sub_ns.options.key?(:swagger) && sub_ns.options[:swagger][:nested] == false
# remove all namespaces that are nested below this standalone sub_ns
sub_namespaces.each { |sub_sub_name, _| sub_namespaces.delete(sub_sub_name) if sub_sub_name.start_with?(sub_name) }
sub_namespaces.each do |sub_sub_name, _|
sub_namespaces.delete(sub_sub_name) if sub_sub_name.start_with?(sub_name)
end
end
sub_namespaces
end

View File

@ -37,9 +37,11 @@ module GrapeSwagger
class_variables_from(options)
if formatter
[:format, :default_format, :default_error_formatter].each do |method|
send(method, formatter)
end if formatter
end
end
send(guard.split.first.to_sym, *guard.split(/[\s,]+/).drop(1)) unless guard.nil?

View File

@ -12,7 +12,7 @@ module GrapeSwagger
end
def evaluate(key, options, request)
options[key].arity == 0 ? options[key].call : options[key].call(request)
options[key].arity.zero? ? options[key].call : options[key].call(request)
end
def default_values

View File

@ -21,7 +21,7 @@ module GrapeSwagger
# optional properties
document_description(settings)
document_type_and_format(data_type)
document_array_param(value_type, definitions)
document_array_param(value_type, definitions) if value_type[:is_array]
document_default_value(settings)
document_range_values(settings)
document_required(settings)
@ -61,7 +61,6 @@ module GrapeSwagger
end
def document_array_param(value_type, definitions)
if value_type[:is_array]
if value_type[:documentation].present?
param_type = value_type[:documentation][:param_type]
doc_type = value_type[:documentation][:type]
@ -82,7 +81,6 @@ module GrapeSwagger
@parsed_param[:type] = 'array'
@parsed_param[:collectionFormat] = collection_format if %w(csv ssv tsv pipes multi).include?(collection_format)
end
end
def param_type(value_type)
param_type = value_type[:param_type] || value_type[:in]

View File

@ -1,5 +1,3 @@
# frozen_string_literal: true
require 'active_support'
require 'active_support/core_ext/string/inflections.rb'
@ -279,6 +277,7 @@ module Grape
end
def expose_params_from_model(model)
model = model.is_a?(String) ? model.constantize : model
model_name = model_name(model)
return model_name if @definitions.key?(model_name)

View File

@ -0,0 +1,39 @@
require 'spec_helper'
require 'grape-entity'
require 'grape-swagger-entity'
describe '#427 nested entity given as string' do
let(:app) do
Class.new(Grape::API) do
namespace :issue_427 do
module Permission
class WithoutRole < Grape::Entity
expose :id
expose :description
end
end
class RoleEntity < Grape::Entity
expose :id
expose :description
expose :role
expose :permissions, using: 'Permission::WithoutRole'
end
desc 'Get a list of roles',
success: RoleEntity
get '/' do
present [], with: RoleEntity
end
end
add_swagger_documentation format: :json
end
end
subject do
get '/swagger_doc'
JSON.parse(last_response.body)['definitions']
end
specify { expect(subject.keys).to include 'RoleEntity', 'WithoutRole' }
end

View File

@ -336,5 +336,5 @@ RSpec.shared_context 'entity swagger example' do
end
def mounted_paths
%w( /thing /other_thing /dummy )
%w(/thing /other_thing /dummy)
end

View File

@ -332,5 +332,5 @@ RSpec.shared_context 'mock swagger example' do
end
def mounted_paths
%w( /thing /other_thing /dummy )
%w(/thing /other_thing /dummy)
end

View File

@ -408,5 +408,5 @@ RSpec.shared_context 'representable swagger example' do
end
def mounted_paths
%w( /thing /other_thing /dummy )
%w(/thing /other_thing /dummy)
end

View File

@ -1,5 +1,3 @@
# encoding: UTF-8
require 'spec_helper'
def details