@@ -76,7 +76,7 @@ rename name (_, schema) = (name, schema)
7676-- data Coord = Coord { x :: Double, y :: Double }
7777--
7878-- instance ToSchema Coord where
79−-- toSchemaDefinitions = pure (Just "Coord", schema)
79+-- declareNamedSchema = pure (Just "Coord", schema)
8080-- where
8181-- schema = mempty
8282-- & schemaType .~ SwaggerObject
@@ -88,11 +88,11 @@ rename name (_, schema) = (name, schema)
8888-- @
8989--
9090-- Instead of manually writing your @'ToSchema'@ instance you can
91−-- use a default generic implementation of @'toSchemaDefinitions'@.
91+-- use a default generic implementation of @'declareNamedSchema'@.
9292--
9393-- To do that, simply add @deriving 'Generic'@ clause to your datatype
9494-- and declare a @'ToSchema'@ instance for your datatype without
95−-- giving definition for @'toSchemaDefinitions'@.
95+-- giving definition for @'declareNamedSchema'@.
9696--
9797-- For instance, the previous example can be simplified into this:
9898--
@@ -110,13 +110,13 @@ class ToSchema a where
110110 -- together with all used definitions.
111111 -- Note that the schema itself is included in definitions
112112 -- only if it is recursive (and thus needs its definition in scope).
113− toSchemaDefinitions :: proxy a -> Declare Definitions NamedSchema
114− default toSchemaDefinitions :: (Generic a, GToSchema (Rep a)) => proxy a -> Declare Definitions NamedSchema
115− toSchemaDefinitions = genericToSchemaDefinitions defaultSchemaOptions
113+ declareNamedSchema :: proxy a -> Declare Definitions NamedSchema
114+ default declareNamedSchema :: (Generic a, GToSchema (Rep a)) => proxy a -> Declare Definitions NamedSchema
115+ declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
116116
117117-- | Convert a type into an optionally named schema.
118118toNamedSchema :: ToSchema a => proxy a -> NamedSchema
119−toNamedSchema = undeclare . toSchemaDefinitions
119+toNamedSchema = undeclare . declareNamedSchema
120120
121121-- | Get type's schema name according to its @'ToSchema'@ instance.
122122schemaName :: ToSchema a => proxy a -> Maybe String
@@ -127,7 +127,7 @@ toSchema :: ToSchema a => proxy a -> Schema
127127toSchema = snd . toNamedSchema
128128
129129declareSchema :: ToSchema a => proxy a -> Declare Definitions Schema
130−declareSchema = fmap snd . toSchemaDefinitions
130+declareSchema = fmap snd . declareNamedSchema
131131
132132-- | Convert a type into a referenced schema if possible.
133133-- Only named schemas can be references, nameless schemas are inlined.
@@ -141,41 +141,41 @@ declareSchemaRef proxy = do
141141 known <- looks (HashMap.member (T.pack name))
142142 when (not known) $ do
143143 declare [(T.pack name, schema)]
144− void $ toSchemaDefinitions proxy
144+ void $ declareNamedSchema proxy
145145 return $ Ref (Reference ("#/definitions/" <> T.pack name))
146146 _ -> Inline <$> declareSchema proxy
147147
148148class GToSchema (f :: * -> *) where
149− gtoSchemaDefinitions :: SchemaOptions -> proxy f -> Schema -> Declare Definitions NamedSchema
149+ gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare Definitions NamedSchema
150150
151151instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
152− toSchemaDefinitions _ = do
152+ declareNamedSchema _ = do
153153 ref <- declareSchemaRef (Proxy :: Proxy a)
154154 return $ unnamed $ mempty
155155 & schemaType .~ SwaggerArray
156156 & schemaItems ?~ SchemaItemsObject ref
157157
158−instance {-# OVERLAPPING #-} ToSchema String where toSchemaDefinitions = plain . paramSchemaToSchema
159−instance ToSchema Bool where toSchemaDefinitions = plain . paramSchemaToSchema
160−instance ToSchema Integer where toSchemaDefinitions = plain . paramSchemaToSchema
161−instance ToSchema Int where toSchemaDefinitions = plain . paramSchemaToSchema
162−instance ToSchema Int8 where toSchemaDefinitions = plain . paramSchemaToSchema
163−instance ToSchema Int16 where toSchemaDefinitions = plain . paramSchemaToSchema
164−instance ToSchema Int32 where toSchemaDefinitions = plain . paramSchemaToSchema
165−instance ToSchema Int64 where toSchemaDefinitions = plain . paramSchemaToSchema
166−instance ToSchema Word where toSchemaDefinitions = plain . paramSchemaToSchema
167−instance ToSchema Word8 where toSchemaDefinitions = plain . paramSchemaToSchema
168−instance ToSchema Word16 where toSchemaDefinitions = plain . paramSchemaToSchema
169−instance ToSchema Word32 where toSchemaDefinitions = plain . paramSchemaToSchema
170−instance ToSchema Word64 where toSchemaDefinitions = plain . paramSchemaToSchema
171−
172−instance ToSchema Char where toSchemaDefinitions = plain . paramSchemaToSchema
173−instance ToSchema Scientific where toSchemaDefinitions = plain . paramSchemaToSchema
174−instance ToSchema Double where toSchemaDefinitions = plain . paramSchemaToSchema
175−instance ToSchema Float where toSchemaDefinitions = plain . paramSchemaToSchema
158+instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
159+instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
160+instance ToSchema Integer where declareNamedSchema = plain . paramSchemaToSchema
161+instance ToSchema Int where declareNamedSchema = plain . paramSchemaToSchema
162+instance ToSchema Int8 where declareNamedSchema = plain . paramSchemaToSchema
163+instance ToSchema Int16 where declareNamedSchema = plain . paramSchemaToSchema
164+instance ToSchema Int32 where declareNamedSchema = plain . paramSchemaToSchema
165+instance ToSchema Int64 where declareNamedSchema = plain . paramSchemaToSchema
166+instance ToSchema Word where declareNamedSchema = plain . paramSchemaToSchema
167+instance ToSchema Word8 where declareNamedSchema = plain . paramSchemaToSchema
168+instance ToSchema Word16 where declareNamedSchema = plain . paramSchemaToSchema
169+instance ToSchema Word32 where declareNamedSchema = plain . paramSchemaToSchema
170+instance ToSchema Word64 where declareNamedSchema = plain . paramSchemaToSchema
171+
172+instance ToSchema Char where declareNamedSchema = plain . paramSchemaToSchema
173+instance ToSchema Scientific where declareNamedSchema = plain . paramSchemaToSchema
174+instance ToSchema Double where declareNamedSchema = plain . paramSchemaToSchema
175+instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSchema
176176
177177instance ToSchema a => ToSchema (Maybe a) where
178− toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy a)
178+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy a)
179179
180180instance (ToSchema a, ToSchema b) => ToSchema (Either a b)
181181
@@ -197,69 +197,69 @@ timeSchema format = mempty
197197-- >>> toSchema (Proxy :: Proxy Day) ^. schemaFormat
198198-- Just "yyyy-mm-dd"
199199instance ToSchema Day where
200− toSchemaDefinitions _ = pure $ named "Day" (timeSchema "yyyy-mm-dd")
200+ declareNamedSchema _ = pure $ named "Day" (timeSchema "yyyy-mm-dd")
201201
202202-- |
203203-- >>> toSchema (Proxy :: Proxy LocalTime) ^. schemaFormat
204204-- Just "yyyy-mm-ddThh:MM:ss"
205205instance ToSchema LocalTime where
206− toSchemaDefinitions _ = pure $ named "LocalTime" (timeSchema "yyyy-mm-ddThh:MM:ss")
206+ declareNamedSchema _ = pure $ named "LocalTime" (timeSchema "yyyy-mm-ddThh:MM:ss")
207207
208208-- |
209209-- >>> toSchema (Proxy :: Proxy ZonedTime) ^. schemaFormat
210210-- Just "yyyy-mm-ddThh:MM:ss(Z|+hh:MM)"
211211instance ToSchema ZonedTime where
212− toSchemaDefinitions _ = pure $ named "ZonedTime" $ timeSchema "yyyy-mm-ddThh:MM:ss(Z|+hh:MM)"
212+ declareNamedSchema _ = pure $ named "ZonedTime" $ timeSchema "yyyy-mm-ddThh:MM:ss(Z|+hh:MM)"
213213 & schemaMinLength ?~ toInteger (length ("yyyy-mm-ddThh:MM:ssZ" :: String))
214214
215215instance ToSchema NominalDiffTime where
216− toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy Integer)
216+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Integer)
217217
218218-- |
219219-- >>> toSchema (Proxy :: Proxy UTCTime) ^. schemaFormat
220220-- Just "yyyy-mm-ddThh:MM:ssZ"
221221instance ToSchema UTCTime where
222− toSchemaDefinitions _ = pure $ named "UTCTime" (timeSchema "yyyy-mm-ddThh:MM:ssZ")
222+ declareNamedSchema _ = pure $ named "UTCTime" (timeSchema "yyyy-mm-ddThh:MM:ssZ")
223223
224−instance ToSchema T.Text where toSchemaDefinitions = plain . paramSchemaToSchema
225−instance ToSchema TL.Text where toSchemaDefinitions = plain . paramSchemaToSchema
224+instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
225+instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
226226
227−instance ToSchema IntSet where toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Set Int))
227+instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
228228
229229-- | NOTE: This schema does not account for the uniqueness of keys.
230230instance ToSchema a => ToSchema (IntMap a) where
231− toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy [(Int, a)])
231+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
232232
233233instance ToSchema a => ToSchema (Map String a) where
234− toSchemaDefinitions _ = do
234+ declareNamedSchema _ = do
235235 schema <- declareSchema (Proxy :: Proxy a)
236236 return $ unnamed $ mempty
237237 & schemaType .~ SwaggerObject
238238 & schemaAdditionalProperties ?~ schema
239239
240−instance ToSchema a => ToSchema (Map T.Text a) where toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Map String a))
241−instance ToSchema a => ToSchema (Map TL.Text a) where toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Map String a))
240+instance ToSchema a => ToSchema (Map T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
241+instance ToSchema a => ToSchema (Map TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
242242
243−instance ToSchema a => ToSchema (HashMap String a) where toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Map String a))
244−instance ToSchema a => ToSchema (HashMap T.Text a) where toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Map String a))
245−instance ToSchema a => ToSchema (HashMap TL.Text a) where toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Map String a))
243+instance ToSchema a => ToSchema (HashMap String a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
244+instance ToSchema a => ToSchema (HashMap T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
245+instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
246246
247247instance ToSchema a => ToSchema (Set a) where
248− toSchemaDefinitions _ = do
248+ declareNamedSchema _ = do
249249 schema <- declareSchema (Proxy :: Proxy [a])
250250 return $ unnamed $ schema
251251 & schemaUniqueItems ?~ True
252252
253−instance ToSchema a => ToSchema (HashSet a) where toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Set a))
253+instance ToSchema a => ToSchema (HashSet a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set a))
254254
255−instance ToSchema All where toSchemaDefinitions = plain . paramSchemaToSchema
256−instance ToSchema Any where toSchemaDefinitions = plain . paramSchemaToSchema
255+instance ToSchema All where declareNamedSchema = plain . paramSchemaToSchema
256+instance ToSchema Any where declareNamedSchema = plain . paramSchemaToSchema
257257
258−instance ToSchema a => ToSchema (Sum a) where toSchemaDefinitions _ = unname <$> toSchemaDefinitions (Proxy :: Proxy a)
259−instance ToSchema a => ToSchema (Product a) where toSchemaDefinitions _ = unname <$> toSchemaDefinitions (Proxy :: Proxy a)
260−instance ToSchema a => ToSchema (First a) where toSchemaDefinitions _ = unname <$> toSchemaDefinitions (Proxy :: Proxy a)
261−instance ToSchema a => ToSchema (Last a) where toSchemaDefinitions _ = unname <$> toSchemaDefinitions (Proxy :: Proxy a)
262−instance ToSchema a => ToSchema (Dual a) where toSchemaDefinitions _ = unname <$> toSchemaDefinitions (Proxy :: Proxy a)
258+instance ToSchema a => ToSchema (Sum a) where declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
259+instance ToSchema a => ToSchema (Product a) where declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
260+instance ToSchema a => ToSchema (First a) where declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
261+instance ToSchema a => ToSchema (Last a) where declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
262+instance ToSchema a => ToSchema (Dual a) where declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
263263
264264-- | Default schema for @'Bounded'@, @'Integral'@ types.
265265toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
@@ -282,14 +282,14 @@ genericToSchema opts = snd . genericToNamedSchema opts
282282
283283-- | A configurable generic @'NamedSchema'@ creator.
284284genericToNamedSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> NamedSchema
285−genericToNamedSchema opts = undeclare . genericToSchemaDefinitions opts
285+genericToNamedSchema opts = undeclare . genericDeclareNamedSchema opts
286286
287287-- | A configurable generic @'NamedSchema'@ creator with declarations.
288288-- This function applied to @'defaultSchemaOptions'@
289−-- is used as the default for @'toSchemaDefinitions'@
289+-- is used as the default for @'declareNamedSchema'@
290290-- when the type is an instance of @'Generic'@.
291−genericToSchemaDefinitions :: forall a proxy. (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare Definitions NamedSchema
292−genericToSchemaDefinitions opts _ = gtoSchemaDefinitions opts (Proxy :: Proxy (Rep a)) mempty
291+genericDeclareNamedSchema :: forall a proxy. (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare Definitions NamedSchema
292+genericDeclareNamedSchema opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
293293
294294gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe String
295295gdatatypeSchemaName opts _ = case name of
@@ -314,36 +314,36 @@ nullarySchema = mempty
314314 & schemaEnum ?~ [ toJSON () ]
315315
316316gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
317−gtoNamedSchema opts proxy = undeclare $ gtoSchemaDefinitions opts proxy mempty
317+gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
318318
319319gtoSchema :: GToSchema f => SchemaOptions -> proxy f -> Schema
320320gtoSchema opts = snd . gtoNamedSchema opts
321321
322322gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare Definitions Schema
323−gdeclareSchema opts proxy = snd <$> gtoSchemaDefinitions opts proxy mempty
323+gdeclareSchema opts proxy = snd <$> gdeclareNamedSchema opts proxy mempty
324324
325325gschemaName :: GToSchema f => SchemaOptions -> proxy f -> Maybe String
326326gschemaName opts = fst . gtoNamedSchema opts
327327
328328instance GToSchema U1 where
329− gtoSchemaDefinitions _ _ _ = plain nullarySchema
329+ gdeclareNamedSchema _ _ _ = plain nullarySchema
330330
331331instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
332− gtoSchemaDefinitions opts _ schema = do
333− (_, gschema) <- gtoSchemaDefinitions opts (Proxy :: Proxy g) schema
334− gtoSchemaDefinitions opts (Proxy :: Proxy f) gschema
332+ gdeclareNamedSchema opts _ schema = do
333+ (_, gschema) <- gdeclareNamedSchema opts (Proxy :: Proxy g) schema
334+ gdeclareNamedSchema opts (Proxy :: Proxy f) gschema
335335
336336instance (Datatype d, GToSchema f) => GToSchema (D1 d f) where
337− gtoSchemaDefinitions opts _ s = rename name <$> gtoSchemaDefinitions opts (Proxy :: Proxy f) s
337+ gdeclareNamedSchema opts _ s = rename name <$> gdeclareNamedSchema opts (Proxy :: Proxy f) s
338338 where
339339 name = gdatatypeSchemaName opts (Proxy :: Proxy d)
340340
341341instance {-# OVERLAPPABLE #-} GToSchema f => GToSchema (C1 c f) where
342− gtoSchemaDefinitions opts _ = gtoSchemaDefinitions opts (Proxy :: Proxy f)
342+ gdeclareNamedSchema opts _ = gdeclareNamedSchema opts (Proxy :: Proxy f)
343343
344344-- | Single field constructor.
345345instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
346− gtoSchemaDefinitions opts _ s
346+ gdeclareNamedSchema opts _ s
347347 | unwrapUnaryRecords opts = fieldSchema
348348 | otherwise = do
349349 (_, schema) <- recordSchema
@@ -351,8 +351,8 @@ instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
351351 Just (SchemaItemsArray [_]) -> fieldSchema
352352 _ -> pure (unnamed schema)
353353 where
354− recordSchema = gtoSchemaDefinitions opts (Proxy :: Proxy (S1 s f)) s
355− fieldSchema = gtoSchemaDefinitions opts (Proxy :: Proxy f) s
354+ recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
355+ fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
356356
357357gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare Definitions (Referenced Schema)
358358gdeclareSchemaRef opts proxy = do
@@ -361,7 +361,7 @@ gdeclareSchemaRef opts proxy = do
361361 known <- looks (HashMap.member (T.pack name))
362362 when (not known) $ do
363363 declare [(T.pack name, schema)]
364− void $ gtoSchemaDefinitions opts proxy mempty
364+ void $ gdeclareNamedSchema opts proxy mempty
365365 return $ Ref (Reference ("#/definitions/" <> T.pack name))
366366 _ -> Inline <$> gdeclareSchema opts proxy
367367
@@ -390,20 +390,20 @@ withFieldSchema opts _ isRequiredField schema = do
390390
391391-- | Optional record fields.
392392instance {-# OVERLAPPING #-} (Selector s, ToSchema c) => GToSchema (S1 s (K1 i (Maybe c))) where
393− gtoSchemaDefinitions opts _ = fmap unnamed . withFieldSchema opts (Proxy2 :: Proxy2 s (K1 i (Maybe c))) False
393+ gdeclareNamedSchema opts _ = fmap unnamed . withFieldSchema opts (Proxy2 :: Proxy2 s (K1 i (Maybe c))) False
394394
395395-- | Record fields.
396396instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) where
397− gtoSchemaDefinitions opts _ = fmap unnamed . withFieldSchema opts (Proxy2 :: Proxy2 s f) True
397+ gdeclareNamedSchema opts _ = fmap unnamed . withFieldSchema opts (Proxy2 :: Proxy2 s f) True
398398
399399instance {-# OVERLAPPING #-} ToSchema c => GToSchema (K1 i (Maybe c)) where
400− gtoSchemaDefinitions _ _ _ = toSchemaDefinitions (Proxy :: Proxy c)
400+ gdeclareNamedSchema _ _ _ = declareNamedSchema (Proxy :: Proxy c)
401401
402402instance {-# OVERLAPPABLE #-} ToSchema c => GToSchema (K1 i c) where
403− gtoSchemaDefinitions _ _ _ = toSchemaDefinitions (Proxy :: Proxy c)
403+ gdeclareNamedSchema _ _ _ = declareNamedSchema (Proxy :: Proxy c)
404404
405405instance (GSumToSchema f, GSumToSchema g) => GToSchema (f :+: g) where
406− gtoSchemaDefinitions opts _ s
406+ gdeclareNamedSchema opts _ s
407407 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
408408 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
409409 where