1{-# LANGUAGE RecordWildCards #-}
3-- Module: Data.OpenApi.SchemaOptions
4-- Maintainer: Nickolay Kudasov <nickolay@getshoptv.com>
5-- Stability: experimental
7-- Generic deriving options for @'ToParamSchema'@ and @'ToSchema'@.
8module Data.OpenApi.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
25 -- | Specifies how to encode constructors of a sum datatype.
26 , sumEncoding :: Aeson.SumEncoding
29-- | Default encoding @'SchemaOptions'@.
33-- { 'fieldLabelModifier' = id
34-- , 'constructorTagModifier' = id
35-- , 'datatypeNameModifier' = id
36-- , 'allNullaryToStringTag' = True
37-- , 'unwrapUnaryRecords' = False
38-- , 'sumEncoding' = 'Aeson.defaultTaggedObject'
41defaultSchemaOptions :: SchemaOptions
42defaultSchemaOptions = SchemaOptions
43 { fieldLabelModifier = id
44 , constructorTagModifier = id
45 , datatypeNameModifier = id
46 , allNullaryToStringTag = True
47 , unwrapUnaryRecords = False
48 , sumEncoding = Aeson.defaultTaggedObject
51-- | Convert 'Aeson.Options' to 'SchemaOptions'.
53-- Specifically the following fields get copied:
55-- * 'fieldLabelModifier'
56-- * 'constructorTagModifier'
57-- * 'allNullaryToStringTag'
58-- * 'unwrapUnaryRecords'
60-- Note that these fields have no effect on `SchemaOptions`:
62-- * 'Aeson.omitNothingFields'
63-- * 'Aeson.tagSingleConstructors'
65-- The rest is defined as in 'defaultSchemaOptions'.
69fromAesonOptions :: Aeson.Options -> SchemaOptions
70fromAesonOptions opts = defaultSchemaOptions
71 { fieldLabelModifier = Aeson.fieldLabelModifier opts
72 , constructorTagModifier = Aeson.constructorTagModifier opts
73 , allNullaryToStringTag = Aeson.allNullaryToStringTag opts
74 , unwrapUnaryRecords = Aeson.unwrapUnaryRecords opts
75 , sumEncoding = Aeson.sumEncoding 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