git.iko.soy/deriving-openapi3
on c602f2b help sign in
.github/workflows/build.yaml+2−2
since splitsnapshots
unifiedsplit
@@ -17,7 +17,7 @@ jobs:
17 - name: Check library version
17 - name: Check library version
18 if: github.event_name == 'release'
18 if: github.event_name == 'release'
19 run: |
19 run: |
20− if [ "$(awk -F":" '{if ($1 == "version") {gsub(/ /, "", $2); print $2}}' *.cabal)" != "${{ github.event.release.tag_name }}" ]; then
20+ if [ "$(yq eval ".version" package.yaml)" != "${{ github.event.release.tag_name }}" ]; then
21 echo "::error file=action.yaml::Library version does not match release version."
21 echo "::error file=action.yaml::Library version does not match release version."
22 exit 1
22 exit 1
23 fi
23 fi
@@ -33,7 +33,7 @@ jobs:
33 path: |
33 path: |
34 ~/.stack
34 ~/.stack
35 .stack-work
35 .stack-work
36− key: ${{ runner.os }}-stack-${{ hashFiles('stack.yaml') }}-${{ hashFiles('**.cabal') }}
36+ key: ${{ runner.os }}-stack-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
37 restore-keys: |
37 restore-keys: |
38 ${{ runner.os }}-stack-${{ hashFiles('stack.yaml') }}
38 ${{ runner.os }}-stack-${{ hashFiles('stack.yaml') }}
39 ${{ runner.os }}-stack
39 ${{ runner.os }}-stack
deriving-openapi3.cabal+11−3
@@ -22,6 +22,11 @@ source-repository head
22 type: git
22 type: git
23 location: https://github.com/ilyakooo0/deriving-openapi3
23 location: https://github.com/ilyakooo0/deriving-openapi3
24
24
25+flag servant-description
26+ description: Create instances for the 'Description' type from 'servant'
27+ manual: False
28+ default: True
29+
25library
30library
26 exposed-modules:
31 exposed-modules:
27 Deriving.OpenApi
32 Deriving.OpenApi
@@ -43,13 +48,16 @@ library
43 OverloadedStrings
48 OverloadedStrings
44 DerivingStrategies
49 DerivingStrategies
45 DerivingVia
50 DerivingVia
46− FlexibleContexts
47 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
51 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
48 build-depends:
52 build-depends:
49 aeson
53 aeson
50− , base >=4.12
54+ , base
51− , deriving-aeson >=0.2.2
55+ , deriving-aeson
52 , lens
56 , lens
53 , openapi3
57 , openapi3
54 , text
58 , text
59+ if flag(servant-description)
60+ cpp-options: -DSERVANT_DESCRIPTION
61+ build-depends:
62+ servant
55 default-language: Haskell2010
63 default-language: Haskell2010
src/Deriving/OpenApi.hs+7−3
@@ -42,14 +42,16 @@ import Data.OpenApi
42import Data.OpenApi.Internal.ParamSchema
42import Data.OpenApi.Internal.ParamSchema
43import Data.OpenApi.Internal.Schema
43import Data.OpenApi.Internal.Schema
44import Data.Proxy
44import Data.Proxy
45−import Data.Text (Text)
46−import qualified Data.Text as T
47import Data.Typeable
45import Data.Typeable
48import Deriving.Aeson
46import Deriving.Aeson
49import GHC.Generics
47import GHC.Generics
50import GHC.TypeLits
48import GHC.TypeLits
51
49
52−data Description (desc :: Symbol) = Description
50+#ifdef SERVANT_DESCRIPTION
51+
52+import Servant.API
53+import Data.Text (Text)
54+import qualified Data.Text as T
53
55
54instance (AesonOptions xs) => AesonOptions (Description f ': xs) where
56instance (AesonOptions xs) => AesonOptions (Description f ': xs) where
55 aesonOptions = aesonOptions @xs
57 aesonOptions = aesonOptions @xs
@@ -60,6 +62,8 @@ instance KnownSymbol t => OpenApiOptionModifier (Description t) where
60toTextLine :: forall s. KnownSymbol s => Text
62toTextLine :: forall s. KnownSymbol s => Text
61toTextLine = "\n\n" <> T.pack (symbolVal (Proxy @s))
63toTextLine = "\n\n" <> T.pack (symbolVal (Proxy @s))
62
64
65+#endif
66+
63-- $setup
67-- $setup
64-- >>> import qualified Data.Yaml
68-- >>> import qualified Data.Yaml
65-- >>> import qualified Data.ByteString.Char8
69-- >>> import qualified Data.ByteString.Char8