git.iko.soy/typeable/swagger2
on master help sign in
Merge pull request #146 from GetShopTV/from-aeson-options

Add fromAesonOptions helper

commit5275f6295877e08fb62ca8ac884b616a01a41486 authorNickolay Kudasov <fizruk@users.noreply.github.com> dateFri 9 Mar 2018, 23:28 (9 years ago) parentfff19d285b8f32
2 files changed+27
src/Data/Swagger/Schema.hs+1 src/Data/Swagger/SchemaOptions.hs+26
src/Data/Swagger/Schema.hs+1
@@ -54,6 +54,7 @@ module Data.Swagger.Schema (
5454 -- * Generic encoding configuration
5555 SchemaOptions(..),
5656 defaultSchemaOptions,
57+ fromAesonOptions,
5758) where
5859
5960import Data.Swagger.Internal.Schema
src/Data/Swagger/SchemaOptions.hs+26
@@ -1,3 +1,4 @@
1+{-# LANGUAGE RecordWildCards #-}
12-- |
23-- Module: Data.Swagger.SchemaOptions
34-- Maintainer: Nickolay Kudasov <nickolay@getshoptv.com>
@@ -6,6 +7,8 @@
67-- Generic deriving options for @'ToParamSchema'@ and @'ToSchema'@.
78module Data.Swagger.SchemaOptions where
89
10+import qualified Data.Aeson.Types as Aeson
11+
912-- | Options that specify how to encode your type to Swagger schema.
1013data SchemaOptions = SchemaOptions
1114 { -- | Function applied to field labels. Handy for removing common record prefixes for example.
@@ -41,3 +44,26 @@ defaultSchemaOptions = SchemaOptions
4144 , unwrapUnaryRecords = False
4245 }
4346
47+-- | Convert 'Aeson.Options' to 'SchemaOptions'.
48+--
49+-- Specifically the following fields get copied:
50+--
51+-- * 'fieldLabelModifier'
52+-- * 'constructorTagModifier'
53+-- * 'allNullaryToStringTag'
54+-- * 'unwrapUnaryRecords'
55+--
56+-- Note that these fields have no effect on `SchemaOptions`:
57+--
58+-- * 'Aeson.omitNothingFields'
59+-- * 'Aeson.sumEncoding'
60+-- * 'Aeson.tagSingleConstructors'
61+--
62+-- The rest is defined as in 'defaultSchemaOptions'.
63+fromAesonOptions :: Aeson.Options -> SchemaOptions
64+fromAesonOptions opts = defaultSchemaOptions
65+ { fieldLabelModifier = Aeson.fieldLabelModifier opts
66+ , constructorTagModifier = Aeson.constructorTagModifier opts
67+ , allNullaryToStringTag = Aeson.allNullaryToStringTag opts
68+ , unwrapUnaryRecords = Aeson.unwrapUnaryRecords opts
69+ }