@@ -33,6 +33,7 @@ import GHC.Generics
3333
3434import Data.Swagger.Internal
3535import Data.Swagger.Lens
36+import Data.Swagger.SchemaOptions
3637
3738-- | A @'Schema'@ with an optional name.
3839-- This name can be used in references.
@@ -239,59 +240,6 @@ instance ToSchema a => ToSchema (First a) where toNamedSchema _ = unnamed $ to
239240instance ToSchema a => ToSchema (Last a) where toNamedSchema _ = unnamed $ toSchema (Proxy :: Proxy a)
240241instance ToSchema a => ToSchema (Dual a) where toNamedSchema _ = unnamed $ toSchema (Proxy :: Proxy a)
241242
242−-- | Options that specify how to encode your type to Swagger schema.
243−data SchemaOptions = SchemaOptions
244− { -- | Function applied to field labels. Handy for removing common record prefixes for example.
245− fieldLabelModifier :: String -> String
246− -- | Function applied to constructor tags which could be handy for lower-casing them for example.
247− , constructorTagModifier :: String -> String
248− -- | Function applied to datatype name.
249− , datatypeNameModifier :: String -> String
250− -- | If @'True'@ the constructors of a datatype, with all nullary constructors,
251− -- will be encoded to a string enumeration schema with the constructor tags as possible values.
252− , allNullaryToStringTag :: Bool
253− -- | If @'True'@ direct subschemas will be referenced if possible (rather than inlined).
254− -- Note that this option does not influence nested schemas, e.g. for these types
255− --
256− -- @
257− -- data Object = Object String deriving Generic
258− -- instance ToSchema Object
259− --
260− -- newtype Objects = Objects [Object] deriving Generic
261− -- instance ToSchema Objects where
262− -- toNamedSchema = genericToNamedSchema defaultSchemaOptions
263− -- { useReferences = False }
264− -- @
265− --
266− -- Schema for @Objects@ __will not__ inline @Object@ schema because
267− -- it is nested in a @[]@ schema.
268− , useReferences :: Bool
269− -- | Hide the field name when a record constructor has only one field, like a newtype.
270− , unwrapUnaryRecords :: Bool
271− }
272−
273−-- | Default encoding @'SchemaOptions'@.
274−--
275−-- @
276−-- 'SchemaOptions'
277−-- { 'fieldLabelModifier' = id
278−-- , 'constructorTagModifier' = id
279−-- , 'datatypeNameModifier' = id
280−-- , 'allNullaryToStringTag' = True
281−-- , 'useReferences' = True
282−-- , 'unwrapUnaryRecords' = False
283−-- }
284−-- @
285−defaultSchemaOptions :: SchemaOptions
286−defaultSchemaOptions = SchemaOptions
287− { fieldLabelModifier = id
288− , constructorTagModifier = id
289− , datatypeNameModifier = id
290− , allNullaryToStringTag = True
291− , useReferences = True
292− , unwrapUnaryRecords = False
293− }
294−
295243-- | Default schema for @'Bounded'@, @'Integral'@ types.
296244toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
297245toSchemaBoundedIntegral _ = mempty