git.iko.soy/typeable/swagger2
on master help sign in
Do not omit items property from schema when it is []
8ef43e6Nickolay Kudasov
src/Data/Swagger/Internal.hs+8−2
@@ -906,7 +906,10 @@ instance ToJSON SecurityScheme where
906 toJSON = genericToJSONWithSub "type" (jsonPrefix "securityScheme")
906 toJSON = genericToJSONWithSub "type" (jsonPrefix "securityScheme")
907
907
908instance ToJSON Schema where
908instance 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
910
913
911instance ToJSON Header where
914instance ToJSON Header where
912 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "header")
915 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "header")
@@ -985,7 +988,10 @@ instance ToJSON (CollectionFormat t) where
985 toJSON CollectionMulti = "multi"
988 toJSON CollectionMulti = "multi"
986
989
987instance ToJSON (ParamSchema t) where
990instance 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
989
995
990-- =======================================================================
996-- =======================================================================
991-- Manual FromJSON instances
997-- Manual FromJSON instances
src/Data/Swagger/Internal/Utils.hs+7−4
@@ -58,11 +58,14 @@ parseOneOf xs js =
58 where
58 where
59 ys = zip (map toJSON xs) xs
59 ys = zip (map toJSON xs) xs
60
60
61−omitEmpties :: Value -> Value
61+omitEmptiesExcept :: (Text -> Value -> Bool) -> Value -> Value
62−omitEmpties (Object o) = Object (HashMap.filter nonEmpty o)
62+omitEmptiesExcept f (Object o) = Object (HashMap.filterWithKey nonEmpty o)
63 where
63 where
64− nonEmpty js = (js /= Object mempty) && (js /= Array mempty) && (js /= Null)
64+ nonEmpty k js = f k js || (js /= Object mempty) && (js /= Array mempty) && (js /= Null)
65−omitEmpties js = js
65+omitEmptiesExcept _ js = js
66+
67+omitEmpties :: Value -> Value
68+omitEmpties = omitEmptiesExcept (\_ _ -> False)
66
69
67genericToJSONWithSub :: (Generic a, GToJSON (Rep a)) => Text -> Options -> a -> Value
70genericToJSONWithSub :: (Generic a, GToJSON (Rep a)) => Text -> Options -> a -> Value
68genericToJSONWithSub sub opts x =
71genericToJSONWithSub sub opts x =