mirror of
https://github.com/ilyakooo0/deriving-openapi3.git
synced 2024-09-11 10:25:55 +03:00
Made servant conditional
This commit is contained in:
parent
4c35d5a662
commit
f4bfff11a2
6
.github/workflows/build.yaml
vendored
6
.github/workflows/build.yaml
vendored
@ -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")
|
||||
|
24
package.yaml
24
package.yaml
@ -1,18 +1,31 @@
|
||||
name: deriving-openapi3
|
||||
version: 0.1.0.0
|
||||
synopsis: DerivingVia for OpenAPI 3
|
||||
# description:
|
||||
description: See <https://github.com/ilyakooo0/deriving-openapi3 GitHub> for more details.
|
||||
maintainer: Ilya Kostyuchenko <ilyakooo0@gmail.com>
|
||||
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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user