Class: OpenapiFirst::BodyParser
- Inherits:
-
Object
- Object
- OpenapiFirst::BodyParser
- Defined in:
- lib/openapi_first/body_parser.rb
Defined Under Namespace
Classes: ParsingError
Instance Method Summary collapse
Instance Method Details
#parse(request, content_type) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/openapi_first/body_parser.rb', line 9 def parse(request, content_type) body = read_body(request) return if body.empty? return MultiJson.load(body) if content_type =~ (/json/i) && (content_type =~ /json/i) return request.POST if request.form_data? body rescue MultiJson::ParseError raise ParsingError, 'Failed to parse body as JSON' end |