diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0721ff9..ee3432e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -42,3 +42,9 @@ jobs: shell: bash run: | stack build + + - name: Check Formatting + shell: bash + run: | + stack install ormolu + ormolu -o -XTypeApplications -o -XCPP -m check $(find . -type f -name "*.hs") diff --git a/package.yaml b/package.yaml index a3308cc..6c86176 100644 --- a/package.yaml +++ b/package.yaml @@ -1,18 +1,31 @@ name: deriving-openapi3 version: 0.1.0.0 synopsis: DerivingVia for OpenAPI 3 -# description: +description: See for more details. maintainer: Ilya Kostyuchenko +category: JSON, Generics +license: MIT github: ilyakooo0/deriving-openapi3 -ghc-options: -Wall +ghc-options: -Weverything + -Wno-star-is-type + -Wno-unsafe + -Wno-prepositive-qualified-module + -Wno-safe + -Wno-missing-safe-haskell-mode + -Wno-missing-import-lists + -Wno-implicit-prelude dependencies: - base - openapi3 - deriving-aeson - aeson - - servant - lens - text +when: + - condition: flag(servant-description) + dependencies: + - servant + cpp-options: -DSERVANT_DESCRIPTION library: source-dirs: src default-extensions: @@ -27,3 +40,8 @@ default-extensions: - TypeFamilies - PolyKinds - OverloadedStrings +flags: + servant-description: + description: Create instances for the 'Description' type from 'servant' + default: true + manual: false diff --git a/src/Deriving/OpenApi.hs b/src/Deriving/OpenApi.hs index 8e61f36..61c165f 100644 --- a/src/Deriving/OpenApi.hs +++ b/src/Deriving/OpenApi.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -Wno-orphans #-} module Deriving.OpenApi @@ -15,13 +16,28 @@ import Data.Kind import Data.OpenApi import Data.OpenApi.Internal.Schema import Data.Proxy -import Data.Text (Text) -import qualified Data.Text as T import Data.Typeable import Deriving.Aeson import GHC.Generics import GHC.TypeLits + +#ifdef SERVANT_DESCRIPTION + import Servant.API +import Data.Text (Text) +import qualified Data.Text as T + +instance (AesonOptions xs) => AesonOptions (Description f ': xs) where + aesonOptions = aesonOptions @xs + +instance (OpenApiOptions xs, KnownSymbol t) => OpenApiOptions (Description t ': xs) where + openApiOptions = openApiOptions @xs + openApiSchemaModifier = schema . description <>~ Just (toTextLine @t) + +toTextLine :: forall s. KnownSymbol s => Text +toTextLine = "\n\n" <> T.pack (symbolVal (Proxy @s)) + +#endif type CustomOpenApi = CustomJSON @@ -37,16 +53,6 @@ instance (StringModifier f, OpenApiOptions xs) => OpenApiOptions (DatatypeNameMo instance (AesonOptions xs) => AesonOptions (DatatypeNameModifier f ': xs) where aesonOptions = aesonOptions @xs -instance (AesonOptions xs) => AesonOptions (Description f ': xs) where - aesonOptions = aesonOptions @xs - -instance (OpenApiOptions xs, KnownSymbol t) => OpenApiOptions (Description t ': xs) where - openApiOptions = openApiOptions @xs - openApiSchemaModifier = schema . description <>~ Just (toTextLine @t) - -toTextLine :: forall s. KnownSymbol s => Text -toTextLine = "\n\n" <> T.pack (symbolVal (Proxy @s)) - type family (++) (x :: [k]) (y :: [k]) :: [k] where (++) '[] ys = ys (++) (x ': xs) ys = xs ++ (x ': ys)