File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11module JSONAPI
22 MEDIA_TYPE = 'application/vnd.api+json'
3- end
43
5- Mime ::Type . register JSONAPI ::MEDIA_TYPE , :api_json
4+ module MimeTypes
5+ def self . install
6+ Mime ::Type . register JSONAPI ::MEDIA_TYPE , :api_json
7+
8+ if Rails ::VERSION ::MAJOR >= 5
9+ parsers = ActionDispatch ::Request . parameter_parsers . merge (
10+ Mime ::Type . lookup ( JSONAPI ::MEDIA_TYPE ) . symbol => parser
11+ )
12+ ActionDispatch ::Request . parameter_parsers = parsers
13+ else
14+ ActionDispatch ::ParamsParser ::DEFAULT_PARSERS [ Mime ::Type . lookup ( JSONAPI ::MEDIA_TYPE ) ] = parser
15+ end
16+ end
617
7- parsers = Rails ::VERSION ::MAJOR >= 5 ?
8- ActionDispatch ::Http ::Parameters :
9- ActionDispatch ::ParamsParser
18+ def self . parser
19+ lambda do |body |
20+ data = JSON . parse ( body )
21+ data = { :_json => data } unless data . is_a? ( Hash )
22+ data . with_indifferent_access
23+ end
24+ end
25+ end
1026
11- parsers ::DEFAULT_PARSERS [ Mime ::Type . lookup ( JSONAPI ::MEDIA_TYPE ) ] = lambda do |body |
12- data = JSON . parse ( body )
13- data = { :_json => data } unless data . is_a? ( Hash )
14- data . with_indifferent_access
27+ MimeTypes . install
1528end
You can’t perform that action at this time.
0 commit comments