@@ -54,6 +54,7 @@ import qualified Data.Vector.Storable as VS
54import qualified Data.Vector.Unboxed as VU
54import qualified Data.Vector.Unboxed as VU
55import Data.Word
55import Data.Word
56import GHC.Generics
56import GHC.Generics
57+import qualified Data.UUID.Types as UUID
58import Data.Swagger.Declare
59import Data.Swagger.Declare
59import Data.Swagger.Internal
60import Data.Swagger.Internal
@@ -441,6 +442,11 @@ instance (ToSchema a, ToSchema b) => ToSchema (Either a b)
441instance ToSchema () where
442instance ToSchema () where
442 declareNamedSchema _ = pure (NamedSchema Nothing nullarySchema)
443 declareNamedSchema _ = pure (NamedSchema Nothing nullarySchema)
445+-- | For 'ToJSON' instance, see <http://hackage.haskell.org/package/uuid-aeson uuid-aeson> package.
446+instance ToSchema UUID.UUID where
447+ declareNamedSchema p = pure $ named "UUID" $ paramSchemaToSchema p
448+ & example ?~ toJSON (UUID.toText UUID.nil)
444instance (ToSchema a, ToSchema b) => ToSchema (a, b)
450instance (ToSchema a, ToSchema b) => ToSchema (a, b)
445instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c)
451instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c)
446instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d)
452instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d)
@@ -502,6 +508,21 @@ instance ToSchema a => ToSchema (IntMap a) where
502 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
508 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
504#if MIN_VERSION_aeson(1,0,0)
510#if MIN_VERSION_aeson(1,0,0)
511+instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
512+ declareNamedSchema _ = case toJSONKey :: ToJSONKeyFunction k of
513+ ToJSONKeyText _ _ -> declareObjectMapSchema
514+ ToJSONKeyValue _ _ -> declareNamedSchema (Proxy :: Proxy [(k, v)])
516+ declareObjectMapSchema = do
517+ schema <- declareSchemaRef (Proxy :: Proxy v)
518+ return $ unnamed $ mempty
519+ & type_ .~ SwaggerObject
520+ & additionalProperties ?~ schema
522+instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
523+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
506instance ToSchema a => ToSchema (Map String a) where
527instance ToSchema a => ToSchema (Map String a) where
507 declareNamedSchema _ = do
528 declareNamedSchema _ = do
@@ -517,22 +538,6 @@ instance ToSchema a => ToSchema (HashMap String a) where declareNamedSchema _ =
517instance ToSchema a => ToSchema (HashMap T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
538instance ToSchema a => ToSchema (HashMap T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
518instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
539instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
522−instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
523− declareNamedSchema _ = case toJSONKey :: ToJSONKeyFunction v of
524− ToJSONKeyText _ _ -> declareObjectMapSchema
525− ToJSONKeyValue _ _ -> declareNamedSchema (Proxy :: Proxy [(k, v)])
527− declareObjectMapSchema = do
528− schema <- declareSchemaRef (Proxy :: Proxy v)
529− return $ unnamed $ mempty
530− & type_ .~ SwaggerObject
531− & additionalProperties ?~ schema
533−instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
534− declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
538instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
543instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])