Skip to content

Commit

Permalink
Support aeson-1.0.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fizruk committed Aug 8, 2016
1 parent 9cfef58 commit 7b962c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/Data/Swagger/Internal/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand Down
4 changes: 3 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion swagger2.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7b962c8

Please sign in to comment.