1{-# LANGUAGE RecordWildCards #-}
3-- Module: Data.Swagger.SchemaOptions
4-- Maintainer: Nickolay Kudasov <nickolay@getshoptv.com>
5-- Stability: experimental
7-- Generic deriving options for @'ToParamSchema'@ and @'ToSchema'@.
8module Data.Swagger.SchemaOptions where
10import qualified Data.Aeson.Types as Aeson
12-- | Options that specify how to encode your type to Swagger schema.
13data SchemaOptions = SchemaOptions
14 { -- | Function applied to field labels. Handy for removing common record prefixes for example.
15 fieldLabelModifier :: String -> String
16 -- | Function applied to constructor tags which could be handy for lower-casing them for example.
17 , constructorTagModifier :: String -> String
18 -- | Function applied to datatype name.
19 , datatypeNameModifier :: String -> String
20 -- | If @'True'@ the constructors of a datatype, with all nullary constructors,
21 -- will be encoded to a string enumeration schema with the constructor tags as possible values.
22 , allNullaryToStringTag :: Bool
23 -- | Hide the field name when a record constructor has only one field, like a newtype.
24 , unwrapUnaryRecords :: Bool
27-- | Default encoding @'SchemaOptions'@.
31-- { 'fieldLabelModifier' = id
32-- , 'constructorTagModifier' = id
33-- , 'datatypeNameModifier' = id
34-- , 'allNullaryToStringTag' = True
35-- , 'unwrapUnaryRecords' = False
38defaultSchemaOptions :: SchemaOptions
39defaultSchemaOptions = SchemaOptions
40 { fieldLabelModifier = id
41 , constructorTagModifier = id
42 , datatypeNameModifier = id
43 , allNullaryToStringTag = True
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'.
66fromAesonOptions :: Aeson.Options -> SchemaOptions
67fromAesonOptions opts = defaultSchemaOptions
68 { fieldLabelModifier = Aeson.fieldLabelModifier opts
69 , constructorTagModifier = Aeson.constructorTagModifier opts
70 , allNullaryToStringTag = Aeson.allNullaryToStringTag opts
71 , unwrapUnaryRecords = Aeson.unwrapUnaryRecords opts
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list