git.iko.soy/deriving-openapi3
on a7837a1 help sign in
5 files changed+68−73
since splitsnapshots
unifiedsplit
.github/workflows/build.yaml+6−2 .gitignore+1 deriving-openapi3.cabal−55 package.yaml+51 src/Deriving/OpenApi.hs+10−16
.github/workflows/build.yaml+6−2
@@ -17,7 +17,7 @@ jobs:
1717 - name: Check library version
1818 if: github.event_name == 'release'
1919 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
2121 echo "::error file=action.yaml::Library version does not match release version."
2222 exit 1
2323 fi
@@ -33,11 +33,15 @@ jobs:
3333 path: |
3434 ~/.stack
3535 .stack-work
36− key: ${{ runner.os }}-stack-${{ hashFiles('stack.yaml') }}-${{ hashFiles('**.cabal') }}
36+ key: ${{ runner.os }}-stack-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
3737 restore-keys: |
3838 ${{ runner.os }}-stack-${{ hashFiles('stack.yaml') }}
3939 ${{ runner.os }}-stack
4040
41+ - name: Upgrade stack
42+ shell: bash
43+ run: stack upgrade --git
44+
4145 - name: Build
4246 shell: bash
4347 run: |
.gitignore+1
@@ -0,0 +1 @@
1+deriving-openapi3.cabal
deriving-openapi3.cabaldeleted−55
@@ -1,55 +0,0 @@
1−cabal-version: 1.12
2−
3−-- This file has been generated from package.yaml by hpack version 0.34.5.
4−--
5−-- see: https://github.com/sol/hpack
6−
7−name: deriving-openapi3
8−version: 0.1.0.0
9−synopsis: DerivingVia for OpenAPI 3
10−description: DerivingVia for OpenAPI 3
11−category: JSON, Generics, OpenAPI
12−homepage: https://github.com/ilyakooo0/deriving-openapi3#readme
13−bug-reports: https://github.com/ilyakooo0/deriving-openapi3/issues
14−maintainer: Ilya Kostyuchenko <ilyakooo0@gmail.com>
15−license: MIT
16−license-file: LICENSE
17−build-type: Simple
18−extra-source-files:
19− Changelog.md
20−
21−source-repository head
22− type: git
23− location: https://github.com/ilyakooo0/deriving-openapi3
24−
25−library
26− exposed-modules:
27− Deriving.OpenApi
28− other-modules:
29− Paths_deriving_openapi3
30− hs-source-dirs:
31− src
32− default-extensions:
33− AllowAmbiguousTypes
34− ScopedTypeVariables
35− KindSignatures
36− DataKinds
37− TypeOperators
38− FlexibleInstances
39− TypeApplications
40− UndecidableInstances
41− TypeFamilies
42− PolyKinds
43− OverloadedStrings
44− DerivingStrategies
45− 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
48− build-depends:
49− aeson
50− , base >=4.12
51− , deriving-aeson >=0.2.2
52− , lens
53− , openapi3
54− , text
55− default-language: Haskell2010
package.yamlnew file+51
@@ -0,0 +1,51 @@
1+name: deriving-openapi3
2+version: 0.1.0.0
3+synopsis: DerivingVia for OpenAPI 3
4+description: DerivingVia for OpenAPI 3
5+maintainer: Ilya Kostyuchenko <ilyakooo0@gmail.com>
6+category: JSON, Generics, OpenAPI
7+license: MIT
8+license-file: LICENSE
9+extra-source-files: Changelog.md
10+github: ilyakooo0/deriving-openapi3
11+ghc-options: -Weverything
12+ -Wno-star-is-type
13+ -Wno-unsafe
14+ -Wno-prepositive-qualified-module
15+ -Wno-safe
16+ -Wno-missing-safe-haskell-mode
17+ -Wno-missing-import-lists
18+ -Wno-implicit-prelude
19+dependencies:
20+ - base
21+ - openapi3
22+ - deriving-aeson
23+ - aeson
24+ - lens
25+ - text
26+when:
27+ - condition: flag(servant-description)
28+ dependencies:
29+ - servant
30+ cpp-options: -DSERVANT_DESCRIPTION
31+library:
32+ source-dirs: src
33+default-extensions:
34+ - AllowAmbiguousTypes
35+ - ScopedTypeVariables
36+ - KindSignatures
37+ - DataKinds
38+ - TypeOperators
39+ - FlexibleInstances
40+ - TypeApplications
41+ - UndecidableInstances
42+ - TypeFamilies
43+ - PolyKinds
44+ - OverloadedStrings
45+ - DerivingStrategies
46+ - DerivingVia
47+flags:
48+ servant-description:
49+ description: Create instances for the 'Description' type from 'servant'
50+ default: true
51+ manual: false
src/Deriving/OpenApi.hs+10−16
@@ -39,17 +39,22 @@ where
3939import Control.Lens
4040import qualified Data.Aeson.Types as A
4141import Data.OpenApi
42−import Data.OpenApi.Internal.ParamSchema
4342import Data.OpenApi.Internal.Schema
4443import Data.Proxy
45−import Data.Text (Text)
46−import qualified Data.Text as T
4744import Data.Typeable
4845import Deriving.Aeson
4946import GHC.Generics
5047import GHC.TypeLits
5148
52−data Description (desc :: Symbol) = Description
49+-- $setup
50+-- >>> import qualified Data.Yaml
51+-- >>> import qualified Data.ByteString.Char8
52+
53+#ifdef SERVANT_DESCRIPTION
54+
55+import Servant.API
56+import Data.Text (Text)
57+import qualified Data.Text as T
5358
5459instance (AesonOptions xs) => AesonOptions (Description f ': xs) where
5560 aesonOptions = aesonOptions @xs
@@ -60,9 +65,7 @@ instance KnownSymbol t => OpenApiOptionModifier (Description t) where
6065toTextLine :: forall s. KnownSymbol s => Text
6166toTextLine = "\n\n" <> T.pack (symbolVal (Proxy @s))
6267
63−-- $setup
64−-- >>> import qualified Data.Yaml
65−-- >>> import qualified Data.ByteString.Char8
68+#endif
6669
6770type CustomOpenApi = CustomJSON
6871
@@ -74,13 +77,6 @@ instance
7477 openApiSchemaModifier @xs
7578 <$> genericDeclareNamedSchema (openApiOptionsModifier @xs defaultSchemaOptions) (Proxy @x)
7679
77−instance
78− (OpenApiOptionModifier xs, GToParamSchema (Rep x), Generic x) =>
79− ToParamSchema (CustomJSON (xs :: k) x)
80− where
81− toParamSchema Proxy =
82− genericToParamSchema (openApiOptionsModifier @xs defaultSchemaOptions) (Proxy @x)
83−
8480class OpenApiOptionModifier x where
8581 openApiOptionsModifier :: SchemaOptions -> SchemaOptions
8682 openApiOptionsModifier = id
@@ -102,10 +98,8 @@ instance OpenApiOptionModifier UnwrapUnaryRecords where
10298
10399instance OpenApiOptionModifier OmitNothingFields
104100
105−#if MIN_VERSION_deriving_aeson(0,2,4)
106101instance OpenApiOptionModifier RejectUnknownFields where
107102 openApiSchemaModifier = schema . additionalProperties .~ Just (AdditionalPropertiesAllowed False)
108−#endif
109103
110104instance StringModifier f => OpenApiOptionModifier (FieldLabelModifier f) where
111105 openApiOptionsModifier o = o {fieldLabelModifier = getStringModifier @f}