@@ -1,3 +1,4 @@
1{-# OPTIONS_GHC -Wno-orphans #-}
2{-# OPTIONS_GHC -Wno-orphans #-}
3module Deriving.OpenApi
4module Deriving.OpenApi
@@ -15,13 +16,28 @@ import Data.Kind
15import Data.OpenApi
16import Data.OpenApi
16import Data.OpenApi.Internal.Schema
17import Data.OpenApi.Internal.Schema
17import Data.Proxy
18import Data.Proxy
18−import Data.Text (Text)
19−import qualified Data.Text as T
20import Data.Typeable
19import Data.Typeable
21import Deriving.Aeson
20import Deriving.Aeson
22import GHC.Generics
21import GHC.Generics
23import GHC.TypeLits
22import GHC.TypeLits
24+#ifdef SERVANT_DESCRIPTION
24import Servant.API
26import Servant.API
27+import Data.Text (Text)
28+import qualified Data.Text as T
30+instance (AesonOptions xs) => AesonOptions (Description f ': xs) where
31+ aesonOptions = aesonOptions @xs
33+instance (OpenApiOptions xs, KnownSymbol t) => OpenApiOptions (Description t ': xs) where
34+ openApiOptions = openApiOptions @xs
35+ openApiSchemaModifier = schema . description <>~ Just (toTextLine @t)
37+toTextLine :: forall s. KnownSymbol s => Text
38+toTextLine = "\n\n" <> T.pack (symbolVal (Proxy @s))
26type CustomOpenApi = CustomJSON
42type CustomOpenApi = CustomJSON
@@ -37,16 +53,6 @@ instance (StringModifier f, OpenApiOptions xs) => OpenApiOptions (DatatypeNameMo
37instance (AesonOptions xs) => AesonOptions (DatatypeNameModifier f ': xs) where
53instance (AesonOptions xs) => AesonOptions (DatatypeNameModifier f ': xs) where
38 aesonOptions = aesonOptions @xs
54 aesonOptions = aesonOptions @xs
40−instance (AesonOptions xs) => AesonOptions (Description f ': xs) where
41− aesonOptions = aesonOptions @xs
43−instance (OpenApiOptions xs, KnownSymbol t) => OpenApiOptions (Description t ': xs) where
44− openApiOptions = openApiOptions @xs
45− openApiSchemaModifier = schema . description <>~ Just (toTextLine @t)
47−toTextLine :: forall s. KnownSymbol s => Text
48−toTextLine = "\n\n" <> T.pack (symbolVal (Proxy @s))
50type family (++) (x :: [k]) (y :: [k]) :: [k] where
56type family (++) (x :: [k]) (y :: [k]) :: [k] where
51 (++) '[] ys = ys
57 (++) '[] ys = ys
52 (++) (x ': xs) ys = xs ++ (x ': ys)
58 (++) (x ': xs) ys = xs ++ (x ': ys)