Skip to content

Commit

Permalink
Fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeRVY committed Jan 6, 2021
1 parent a64af7f commit 946cec1
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 27 deletions.
2 changes: 2 additions & 0 deletions lib/grape-swagger/errors.rb
Expand Up @@ -3,7 +3,9 @@
module GrapeSwagger
module Errors
class UnregisteredParser < StandardError; end

class SwaggerSpec < StandardError; end

class SwaggerSpecDeprecated < SwaggerSpec
class << self
def tell!(what)
Expand Down
2 changes: 1 addition & 1 deletion spec/issues/587_range_parameter_delimited_by_dash_spec.rb
Expand Up @@ -8,7 +8,7 @@
namespace :range_parameter do
desc 'Get a array with range'
get '/range/:range_start-:range_end' do
present []
present[]
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/support/empty_model_parser.rb
@@ -1,7 +1,9 @@
# frozen_string_literal: true

# rubocop:disable Lint/EmptyClass
class EmptyClass
end
# rubocop:enable Lint/EmptyClass

module GrapeSwagger
class EmptyModelParser
Expand Down
16 changes: 16 additions & 0 deletions spec/support/model_parsers/mock_parser.rb
Expand Up @@ -40,21 +40,37 @@ def documentation
end

class UseNestedWithAddress < OpenStruct; end

class TypedDefinition < OpenStruct; end

class UseItemResponseAsType < OpenStruct; end

class OtherItem < OpenStruct; end

class EnumValues < OpenStruct; end

class AliasedThing < OpenStruct; end

class FourthLevel < OpenStruct; end

class ThirdLevel < OpenStruct; end

class SecondLevel < OpenStruct; end

class FirstLevel < OpenStruct; end

class QueryInputElement < OpenStruct; end

class QueryInput < OpenStruct; end

class ApiError < OpenStruct; end

class SecondApiError < OpenStruct; end

class RecursiveModel < OpenStruct; end

class DocumentedHashAndArrayModel < OpenStruct; end

module NestedModule
class ApiResponse < OpenStruct; end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/support/namespace_tags.rb
Expand Up @@ -3,7 +3,9 @@
RSpec.shared_context 'namespace example' do
before :all do
module TheApi
# rubocop:disable Lint/EmptyClass
class CustomType; end
# rubocop:enable Lint/EmptyClass

class NamespaceApi < Grape::API
namespace :hudson do
Expand Down
2 changes: 1 addition & 1 deletion spec/swagger_v2/api_swagger_v2_detail_spec.rb
Expand Up @@ -42,7 +42,7 @@ class DetailApi < Grape::API
desc 'This returns something' do
detail 'detailed description of the route inside the `desc` block'
entity Entities::UseResponse
failure [{ code: 400, model: Entities::ApiError }]
failure[{ code: 400, model: Entities::ApiError }]
end
get '/use_detail_block' do
{ 'declared_params' => declared(params) }
Expand Down
6 changes: 3 additions & 3 deletions spec/swagger_v2/api_swagger_v2_mounted_spec.rb
Expand Up @@ -13,15 +13,15 @@ def app
# Thing stuff
desc 'This gets Things.' do
params Entities::Something.documentation
http_codes [{ code: 401, message: 'Unauthorized', model: Entities::ApiError }]
http_codes[{ code: 401, message: 'Unauthorized', model: Entities::ApiError }]
end
get '/thing' do
something = OpenStruct.new text: 'something'
present something, with: Entities::Something
end

desc 'This gets Things.' do
http_codes [
http_codes[
{ code: 200, message: 'get Horses', model: Entities::Something },
{ code: 401, message: 'HorsesOutError', model: Entities::ApiError }
]
Expand All @@ -32,7 +32,7 @@ def app
end

desc 'This gets Thing.' do
http_codes [{ code: 200, message: 'getting a single thing' }, { code: 401, message: 'Unauthorized' }]
http_codes[{ code: 200, message: 'getting a single thing' }, { code: 401, message: 'Unauthorized' }]
end
params do
requires :id, type: Integer
Expand Down
6 changes: 3 additions & 3 deletions spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
Expand Up @@ -12,15 +12,15 @@ class ResponseApiExamples < Grape::API

desc 'This returns examples' do
success model: Entities::UseResponse, examples: { 'application/json' => { description: 'Names list', items: [{ id: '123', name: 'John' }] } }
failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }]]
failure[[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }]]
end
get '/response_examples' do
{ 'declared_params' => declared(params) }
end

desc 'This syntax also returns examples' do
success model: Entities::UseResponse, examples: { 'application/json' => { description: 'Names list', items: [{ id: '123', name: 'John' }] } }
failure [
failure[
{
code: 404,
message: 'NotFound',
Expand All @@ -41,7 +41,7 @@ class ResponseApiExamples < Grape::API

desc 'This does not return examples' do
success model: Entities::UseResponse
failure [[404, 'NotFound', Entities::ApiError]]
failure[[404, 'NotFound', Entities::ApiError]]
end
get '/response_no_examples' do
{ 'declared_params' => declared(params) }
Expand Down
10 changes: 5 additions & 5 deletions spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
Expand Up @@ -12,31 +12,31 @@ class ResponseApiHeaders < Grape::API

desc 'This returns headers' do
success model: Entities::UseResponse, headers: { 'Location' => { description: 'Location of resource', type: 'string' } }
failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
failure[[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
end
get '/response_headers' do
{ 'declared_params' => declared(params) }
end

desc 'A 204 can have headers too' do
success Hash[status: 204, message: 'No content', headers: { 'Location' => { description: 'Location of resource', type: 'string' } }]
failure [[400, 'Bad Request', Entities::ApiError, { 'application/json' => { code: 400, message: 'Bad request' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
failure[[400, 'Bad Request', Entities::ApiError, { 'application/json' => { code: 400, message: 'Bad request' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
end
delete '/no_content_response_headers' do
{ 'declared_params' => declared(params) }
end

desc 'A file can have headers too' do
success Hash[status: 200, model: 'File', headers: { 'Cache-Control' => { description: 'Directive for caching', type: 'string' } }]
failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
failure[[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
end
get '/file_response_headers' do
{ 'declared_params' => declared(params) }
end

desc 'This syntax also returns headers' do
success model: Entities::UseResponse, headers: { 'Location' => { description: 'Location of resource', type: 'string' } }
failure [
failure[
{
code: 404,
message: 'NotFound',
Expand All @@ -57,7 +57,7 @@ class ResponseApiHeaders < Grape::API

desc 'This does not return headers' do
success model: Entities::UseResponse
failure [[404, 'NotFound', Entities::ApiError]]
failure[[404, 'NotFound', Entities::ApiError]]
end
get '/response_no_headers' do
{ 'declared_params' => declared(params) }
Expand Down
6 changes: 3 additions & 3 deletions spec/swagger_v2/api_swagger_v2_spec.rb
Expand Up @@ -12,15 +12,15 @@ def app
# Thing stuff
desc 'This gets Things.' do
params Entities::Something.documentation
http_codes [{ code: 401, message: 'Unauthorized', model: Entities::ApiError }]
http_codes[{ code: 401, message: 'Unauthorized', model: Entities::ApiError }]
end
get '/thing' do
something = OpenStruct.new text: 'something'
present something, with: Entities::Something
end

desc 'This gets Things.' do
http_codes [
http_codes[
{ code: 200, message: 'get Horses', model: Entities::Something },
{ code: 401, message: 'HorsesOutError', model: Entities::ApiError }
]
Expand All @@ -31,7 +31,7 @@ def app
end

desc 'This gets Thing.' do
http_codes [{ code: 200, message: 'getting a single thing' }, { code: 401, message: 'Unauthorized' }]
http_codes[{ code: 200, message: 'getting a single thing' }, { code: 401, message: 'Unauthorized' }]
end
params do
requires :id, type: Integer
Expand Down
16 changes: 8 additions & 8 deletions spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
Expand Up @@ -14,9 +14,9 @@
let(:app) do
Class.new(Grape::API) do
desc 'Has explicit success http_codes defined' do
http_codes [{ code: 202, message: 'We got it!' },
{ code: 204, message: 'Or returned no content' },
{ code: 400, message: 'Bad request' }]
http_codes[{ code: 202, message: 'We got it!' },
{ code: 204, message: 'Or returned no content' },
{ code: 400, message: 'Bad request' }]
end

post '/accepting_endpoint' do
Expand All @@ -36,7 +36,7 @@
Class.new(Grape::API) do
desc 'Has explicit success http_codes defined' do
success code: 202, model: Entities::UseResponse, message: 'a changed status code'
failure [[400, 'Bad Request']]
failure[[400, 'Bad Request']]
end

post '/accepting_endpoint' do
Expand All @@ -55,8 +55,8 @@
let(:app) do
Class.new(Grape::API) do
desc 'Has explicit error http_codes defined' do
http_codes [{ code: 400, message: 'Error!' },
{ code: 404, message: 'Not found' }]
http_codes[{ code: 400, message: 'Error!' },
{ code: 404, message: 'Not found' }]
end

post '/error_endpoint' do
Expand All @@ -75,8 +75,8 @@
let(:app) do
Class.new(Grape::API) do
desc 'Has success and error codes defined' do
http_codes [{ code: 200, message: 'Found' },
{ code: 404, message: 'Not found' }]
http_codes[{ code: 200, message: 'Found' },
{ code: 404, message: 'Not found' }]
end

get '/endpoint' do
Expand Down
4 changes: 2 additions & 2 deletions spec/swagger_v2/errors_spec.rb
Expand Up @@ -9,7 +9,7 @@
format :json

desc 'Empty model get.' do
http_codes [
http_codes[
{ code: 200, message: 'get Empty model', model: EmptyClass }
]
end
Expand Down Expand Up @@ -45,7 +45,7 @@
format :json

desc 'Wrong model get.' do
http_codes [
http_codes[
{ code: 200, message: 'get Wrong model', model: Hash }
]
end
Expand Down
1 change: 1 addition & 0 deletions spec/swagger_v2/inheritance_and_discriminator_spec.rb
Expand Up @@ -33,6 +33,7 @@ class Cat < Pet
}
end
end

class NameApi < Grape::API
add_swagger_documentation models: [Entities::Pet, Entities::Cat]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/swagger_v2/namespace_tags_prefix_spec.rb
Expand Up @@ -8,7 +8,7 @@
before :all do
module TheApi
class NamespaceApi < Grape::API
version %i[v1 v2]
version % i[v1 v2]
end

class CascadingVersionApi < Grape::API
Expand Down
2 changes: 2 additions & 0 deletions spec/swagger_v2/simple_mounted_api_spec.rb
Expand Up @@ -4,7 +4,9 @@

describe 'a simple mounted api' do
before :all do
# rubocop:disable Lint/EmptyClass
class CustomType; end
# rubocop:enable Lint/EmptyClass

class SimpleMountedApi < Grape::API
desc 'Document root'
Expand Down

0 comments on commit 946cec1

Please sign in to comment.