Class: SwaggerShield::Shield
- Inherits:
-
Object
- Object
- SwaggerShield::Shield
- Defined in:
- lib/swagger_shield/shield.rb
Instance Method Summary collapse
-
#initialize(swagger_spec) ⇒ Shield
constructor
A new instance of Shield.
- #validate(path, method, params) ⇒ Object
Constructor Details
#initialize(swagger_spec) ⇒ Shield
Returns a new instance of Shield.
3 4 5 6 |
# File 'lib/swagger_shield/shield.rb', line 3 def initialize(swagger_spec) @swagger_spec = swagger_spec.deep_dup load_route_definitions! end |
Instance Method Details
#validate(path, method, params) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/swagger_shield/shield.rb', line 8 def validate(path, method, params) canonical_path_id = identify_path(path, paths[method]) JSON::Validator.fully_validate( swagger_spec, params, fragment: "#/route_lookups/#{method}/#{canonical_path_id}/schema", errors_as_objects: true ).map { |error| { message: error[:message].match(/(?<message_part>.*) in schema/)[:message_part], fragment: error[:fragment] } } end |