git.iko.soy/typeable/openapi3
on master help sign in
Do not omit items property from schema when it is []
commit8ef43e666fa0d027b7e3a32e682a30a3b77fefe8 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSat 16 Jan 2016, 12:21 (11 years ago) parent4139a57
2 files changed+15−6
src/Data/Swagger/Internal.hs+8−2 src/Data/Swagger/Internal/Utils.hs+7−4
src/Data/Swagger/Internal.hs+8−2
@@ -906,7 +906,10 @@ instance ToJSON SecurityScheme where
906906 toJSON = genericToJSONWithSub "type" (jsonPrefix "securityScheme")
907907
908908instance ToJSON Schema where
909− toJSON = omitEmpties . genericToJSONWithSub "paramSchema" (jsonPrefix "schema")
909+ toJSON = omitEmptiesExcept f . genericToJSONWithSub "paramSchema" (jsonPrefix "schema")
910+ where
911+ f "items" (Array _) = True
912+ f _ _ = False
910913
911914instance ToJSON Header where
912915 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "header")
@@ -985,7 +988,10 @@ instance ToJSON (CollectionFormat t) where
985988 toJSON CollectionMulti = "multi"
986989
987990instance ToJSON (ParamSchema t) where
988− toJSON = omitEmpties . genericToJSONWithSub "items" (jsonPrefix "paramSchema")
991+ toJSON = omitEmptiesExcept f . genericToJSONWithSub "items" (jsonPrefix "paramSchema")
992+ where
993+ f "items" (Array _) = True
994+ f _ _ = False
989995
990996-- =======================================================================
991997-- Manual FromJSON instances
src/Data/Swagger/Internal/Utils.hs+7−4
@@ -58,11 +58,14 @@ parseOneOf xs js =
5858 where
5959 ys = zip (map toJSON xs) xs
6060
61−omitEmpties :: Value -> Value
62−omitEmpties (Object o) = Object (HashMap.filter nonEmpty o)
61+omitEmptiesExcept :: (Text -> Value -> Bool) -> Value -> Value
62+omitEmptiesExcept f (Object o) = Object (HashMap.filterWithKey nonEmpty o)
6363 where
64− nonEmpty js = (js /= Object mempty) && (js /= Array mempty) && (js /= Null)
65−omitEmpties js = js
64+ nonEmpty k js = f k js || (js /= Object mempty) && (js /= Array mempty) && (js /= Null)
65+omitEmptiesExcept _ js = js
66+
67+omitEmpties :: Value -> Value
68+omitEmpties = omitEmptiesExcept (\_ _ -> False)
6669
6770genericToJSONWithSub :: (Generic a, GToJSON (Rep a)) => Text -> Options -> a -> Value
6871genericToJSONWithSub sub opts x =