Class: OpenapiFirst::BodyParser
- Inherits:
-
Object
- Object
- OpenapiFirst::BodyParser
- Defined in:
- lib/openapi_first/body_parser.rb
Instance Method Summary collapse
Instance Method Details
#parse_body(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/openapi_first/body_parser.rb', line 7 def parse_body(env) request = Rack::Request.new(env) body = read_body(request) return if body.empty? return MultiJson.load(body) if request.media_type =~ (/json/i) && (request.media_type =~ /json/i) return request.POST if request.form_data? body rescue MultiJson::ParseError raise BodyParsingError, 'Failed to parse body as application/json' end |