Simplify ToJSON Responses
commitb982c7dd1fe8fb007d25a5b56114fe62d48b745a
authorOleg Grenrus <oleg.grenrus@iki.fi>
dateTue 8 Mar 2016, 09:04 (11 years ago)
parent2a46257
src/Data/Swagger/Internal.hs+1−2
@@ -978,8 +978,7 @@ instance ToJSON ParamOtherSchema where
978978 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "paramOtherSchema")
979979
980980instance ToJSON Responses where
981− toJSON (Responses def rs) = omitEmpties $
982− toJSON (InsOrdHashMap.mapKeys show rs) <+> object [ "default" .= def ]
981+ toJSON = omitEmpties . genericToJSONWithSub "responses" (jsonPrefix "responses")
983982
984983instance ToJSON Response where
985984 toJSON = omitEmpties . genericToJSON (jsonPrefix "response")
src/Data/Swagger/Internal/Utils.hs+1−1
@@ -111,7 +111,7 @@ genericParseJSONWithSub sub opts js@(Object o)
111111 <|> genericParseJSON opts js' -- try with subjson
112112 where
113113 js' = Object (HashMap.insert sub (Object o) o)
114−genericParseJSONWithSub _ _ _ = error "genericParseJSONWithSub: given json is not an object"
114+genericParseJSONWithSub _ _ _ = fail "genericParseJSONWithSub: given json is not an object"
115115
116116(<+>) :: Value -> Value -> Value
117117Object x <+> Object y = Object (x <> y)