Module: Sinatra::Swagger::ParamValidator

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

Defined Under Namespace

Modules: Helpers Classes: ValidityParser

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sinatra/swagger/param_validator.rb', line 6

def self.registered(app)
  app.register Swagger::SwaggerLinked
  app.helpers Helpers

  app.before do
    next if swagger_spec.nil?
    _, captures, spec = swagger_spec.values
    invalid_content_type(spec['consumes']) if spec['consumes'] && !spec['consumes'].include?(request.content_type)

    # NB. The Validity parser will update the application params with defaults and typing as it goes
    vp = ValidityParser.new(request, params, captures, spec, settings.swagger['definitions'])

    invalid_params(vp.invalidities) if vp.invalidities?
    nil
  end
end