Module: Sinatra::Swagger::ParamValidator::Helpers

Defined in:
lib/sinatra/swagger/param_validator.rb

Instance Method Summary collapse

Instance Method Details

#error_response(code, dev_message, details: {}, status: 400) ⇒ Object


47
48
49
50
51
52
53
54
# File 'lib/sinatra/swagger/param_validator.rb', line 47

def error_response(code, dev_message, details: {}, status: 400)
  content_type :json
  halt(status,{
    error: code,
    developerMessage: dev_message,
    details: details
  }.to_json)
end

#invalid_content_type(acceptable) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sinatra/swagger/param_validator.rb', line 33

def invalid_content_type(acceptable)
  error_response(
    'invalid_content',
    'The ',
    details: {
      content_types: {
        acceptable: acceptable,
        given: request.content_type
      }
    },
    status: 400
  )
end

#invalid_params(invalidities) ⇒ Object


24
25
26
27
28
29
30
31
# File 'lib/sinatra/swagger/param_validator.rb', line 24

def invalid_params(invalidities)
  error_response(
    'invalid_params',
    'Some of the given parameters were invalid according to the Swagger spec.',
    details: { invalidities: invalidities },
    status: 400
  )
end