git.iko.soy/typeable/swagger2
on master help sign in
Fix #71
7433e9aOleg Grenrus
src/Data/Swagger/Internal/Schema.hs+15−16
@@ -482,6 +482,21 @@ instance ToSchema a => ToSchema (IntMap a) where
482 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
482 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
483
483
484#if MIN_VERSION_aeson(1,0,0)
484#if MIN_VERSION_aeson(1,0,0)
485+instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
486+ declareNamedSchema _ = case toJSONKey :: ToJSONKeyFunction k of
487+ ToJSONKeyText _ _ -> declareObjectMapSchema
488+ ToJSONKeyValue _ _ -> declareNamedSchema (Proxy :: Proxy [(k, v)])
489+ where
490+ declareObjectMapSchema = do
491+ schema <- declareSchemaRef (Proxy :: Proxy v)
492+ return $ unnamed $ mempty
493+ & type_ .~ SwaggerObject
494+ & additionalProperties ?~ schema
495+
496+instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
497+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
498+
499+#else
485
500
486instance ToSchema a => ToSchema (Map String a) where
501instance ToSchema a => ToSchema (Map String a) where
487 declareNamedSchema _ = do
502 declareNamedSchema _ = do
@@ -497,22 +512,6 @@ instance ToSchema a => ToSchema (HashMap String a) where declareNamedSchema _ =
497instance ToSchema a => ToSchema (HashMap T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
512instance ToSchema a => ToSchema (HashMap T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
498instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
513instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
499
514
500−#else
501−
502−instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
503− declareNamedSchema _ = case toJSONKey :: ToJSONKeyFunction v of
504− ToJSONKeyText _ _ -> declareObjectMapSchema
505− ToJSONKeyValue _ _ -> declareNamedSchema (Proxy :: Proxy [(k, v)])
506− where
507− declareObjectMapSchema = do
508− schema <- declareSchemaRef (Proxy :: Proxy v)
509− return $ unnamed $ mempty
510− & type_ .~ SwaggerObject
511− & additionalProperties ?~ schema
512−
513−instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
514− declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
515−
516#endif
515#endif
517
516
518instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
517instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])