Revert "Don't use JSON::Type, use JSON::Any instead"

This reverts commit 34475b986a486730d696ddf52250c38d7e0cfe4a.
This commit is contained in:
Serdar Dogruyol 2018-03-10 11:11:42 +03:00
parent db00ecba1d
commit 11295f0584
3 changed files with 4 additions and 3 deletions

View File

@ -174,7 +174,7 @@ describe "ParamParser" do
body_params.to_s.should eq("") body_params.to_s.should eq("")
json_params = Kemal::ParamParser.new(request).json json_params = Kemal::ParamParser.new(request).json
json_params.should eq({} of String => Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Any) | Array(JSON::Any)) json_params.should eq({} of String => Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type))
end end
end end

View File

@ -85,6 +85,7 @@ describe "Kemal::RouteHandler" do
post "/" do |env| post "/" do |env|
skills = env.params.json["skills"].as(Array) skills = env.params.json["skills"].as(Array)
skills_from_languages = skills.map do |skill| skills_from_languages = skills.map do |skill|
skill = skill.as(Hash)
skill["language"] skill["language"]
end end
"Skills #{skills_from_languages.each.join(',')}" "Skills #{skills_from_languages.each.join(',')}"

View File

@ -8,7 +8,7 @@ module Kemal
MULTIPART_FORM = "multipart/form-data" MULTIPART_FORM = "multipart/form-data"
PARTS = %w(url query body json) PARTS = %w(url query body json)
# :nodoc: # :nodoc:
alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Any) | Array(JSON::Any) alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type)
getter files getter files
def initialize(@request : HTTP::Request) def initialize(@request : HTTP::Request)
@ -89,7 +89,7 @@ module Kemal
case json = JSON.parse(body).raw case json = JSON.parse(body).raw
when Hash when Hash
json.each do |key, value| json.each do |key, value|
@json[key] = value.raw @json[key] = value.as(AllParamTypes)
end end
when Array when Array
@json["_json"] = json @json["_json"] = json