git.iko.soy/typeable/swagger2
on master help sign in
Add fromAesonOptions helper
85b8f32Nickolay Kudasov
src/Data/Swagger/Schema.hs+1
@@ -54,6 +54,7 @@ module Data.Swagger.Schema (
54 -- * Generic encoding configuration
54 -- * Generic encoding configuration
55 SchemaOptions(..),
55 SchemaOptions(..),
56 defaultSchemaOptions,
56 defaultSchemaOptions,
57+ fromAesonOptions,
57) where
58) where
58
59
59import Data.Swagger.Internal.Schema
60import Data.Swagger.Internal.Schema
src/Data/Swagger/SchemaOptions.hs+26
@@ -1,3 +1,4 @@
1+{-# LANGUAGE RecordWildCards #-}
1-- |
2-- |
2-- Module: Data.Swagger.SchemaOptions
3-- Module: Data.Swagger.SchemaOptions
3-- Maintainer: Nickolay Kudasov <nickolay@getshoptv.com>
4-- Maintainer: Nickolay Kudasov <nickolay@getshoptv.com>
@@ -6,6 +7,8 @@
6-- Generic deriving options for @'ToParamSchema'@ and @'ToSchema'@.
7-- Generic deriving options for @'ToParamSchema'@ and @'ToSchema'@.
7module Data.Swagger.SchemaOptions where
8module Data.Swagger.SchemaOptions where
8
9
10+import qualified Data.Aeson.Types as Aeson
11+
9-- | Options that specify how to encode your type to Swagger schema.
12-- | Options that specify how to encode your type to Swagger schema.
10data SchemaOptions = SchemaOptions
13data SchemaOptions = SchemaOptions
11 { -- | Function applied to field labels. Handy for removing common record prefixes for example.
14 { -- | Function applied to field labels. Handy for removing common record prefixes for example.
@@ -41,3 +44,26 @@ defaultSchemaOptions = SchemaOptions
41 , unwrapUnaryRecords = False
44 , unwrapUnaryRecords = False
42 }
45 }
43
46
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+ }