From 7b962c8a1f9bfc939a579ebcea65f8d13d6f2fad Mon Sep 17 00:00:00 2001 From: Nickolay Kudasov Date: Tue, 9 Aug 2016 02:51:11 +0500 Subject: [PATCH] Support aeson-1.0.0.0 --- src/Data/Swagger/Internal/Schema.hs | 20 ++++++++++++++++++++ stack.yaml | 4 +++- swagger2.cabal | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Data/Swagger/Internal/Schema.hs b/src/Data/Swagger/Internal/Schema.hs index 103a8a5..54ddd56 100644 --- a/src/Data/Swagger/Internal/Schema.hs +++ b/src/Data/Swagger/Internal/Schema.hs @@ -481,6 +481,8 @@ instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy instance ToSchema a => ToSchema (IntMap a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)]) +#if MIN_VERSION_aeson(1,0,0) + instance ToSchema a => ToSchema (Map String a) where declareNamedSchema _ = do schema <- declareSchemaRef (Proxy :: Proxy a) @@ -495,6 +497,24 @@ instance ToSchema a => ToSchema (HashMap String a) where declareNamedSchema _ = instance ToSchema a => ToSchema (HashMap T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a)) instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a)) +#else + +instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where + declareNamedSchema _ = case toJSONKey :: ToJSONKeyFunction v of + ToJSONKeyText _ _ -> declareObjectMapSchema + ToJSONKeyValue _ _ -> declareNamedSchema (Proxy :: Proxy [(k, v)]) + where + declareObjectMapSchema = do + schema <- declareSchemaRef (Proxy :: Proxy v) + return $ unnamed $ mempty + & type_ .~ SwaggerObject + & additionalProperties ?~ schema + +instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where + declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v)) + +#endif + instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a]) instance ToSchema a => ToSchema (VU.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a]) instance ToSchema a => ToSchema (VS.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a]) diff --git a/stack.yaml b/stack.yaml index e52a05e..60cd976 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,5 +1,7 @@ flags: {} packages: - '.' -extra-deps: [] +extra-deps: +- aeson-1.0.0.0 +- insert-ordered-containers-0.2.0.0 resolver: nightly-2016-07-15 diff --git a/swagger2.cabal b/swagger2.cabal index 5ad2adf..228ec33 100644 --- a/swagger2.cabal +++ b/swagger2.cabal @@ -46,7 +46,7 @@ library , hashable , generics-sop >=0.2 && <0.3 , http-media - , insert-ordered-containers >=0.1.0.0 && <0.2 + , insert-ordered-containers >=0.1.0.0 && <0.3 , lens , mtl , network