@@ -1,3 +1,4 @@
1+{-# LANGUAGE RecordWildCards #-}
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
10+import qualified Data.Aeson.Types as Aeson
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
47+-- | Convert 'Aeson.Options' to 'SchemaOptions'.
49+-- Specifically the following fields get copied:
51+-- * 'fieldLabelModifier'
52+-- * 'constructorTagModifier'
53+-- * 'allNullaryToStringTag'
54+-- * 'unwrapUnaryRecords'
56+-- Note that these fields have no effect on `SchemaOptions`:
58+-- * 'Aeson.omitNothingFields'
59+-- * 'Aeson.sumEncoding'
60+-- * 'Aeson.tagSingleConstructors'
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