git.iko.soy/typeable/openapi3
on master help sign in
Rename toSchemaDefinitions -> declareNamedSchema
5ba36c0Nickolay Kudasov
src/Data/Swagger/Internal/Schema.hs+75−75
@@ -76,7 +76,7 @@ rename name (_, schema) = (name, schema)
76-- data Coord = Coord { x :: Double, y :: Double }
76-- data Coord = Coord { x :: Double, y :: Double }
77--
77--
78-- instance ToSchema Coord where
78-- instance ToSchema Coord where
79−-- toSchemaDefinitions = pure (Just "Coord", schema)
79+-- declareNamedSchema = pure (Just "Coord", schema)
80-- where
80-- where
81-- schema = mempty
81-- schema = mempty
82-- & schemaType .~ SwaggerObject
82-- & schemaType .~ SwaggerObject
@@ -88,11 +88,11 @@ rename name (_, schema) = (name, schema)
88-- @
88-- @
89--
89--
90-- Instead of manually writing your @'ToSchema'@ instance you can
90-- 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'@.
92--
92--
93-- To do that, simply add @deriving 'Generic'@ clause to your datatype
93-- To do that, simply add @deriving 'Generic'@ clause to your datatype
94-- and declare a @'ToSchema'@ instance for your datatype without
94-- and declare a @'ToSchema'@ instance for your datatype without
95−-- giving definition for @'toSchemaDefinitions'@.
95+-- giving definition for @'declareNamedSchema'@.
96--
96--
97-- For instance, the previous example can be simplified into this:
97-- For instance, the previous example can be simplified into this:
98--
98--
@@ -110,13 +110,13 @@ class ToSchema a where
110 -- together with all used definitions.
110 -- together with all used definitions.
111 -- Note that the schema itself is included in definitions
111 -- Note that the schema itself is included in definitions
112 -- only if it is recursive (and thus needs its definition in scope).
112 -- only if it is recursive (and thus needs its definition in scope).
113− toSchemaDefinitions :: proxy a -> Declare Definitions NamedSchema
113+ declareNamedSchema :: proxy a -> Declare Definitions NamedSchema
114− default toSchemaDefinitions :: (Generic a, GToSchema (Rep a)) => proxy a -> Declare Definitions NamedSchema
114+ default declareNamedSchema :: (Generic a, GToSchema (Rep a)) => proxy a -> Declare Definitions NamedSchema
115− toSchemaDefinitions = genericToSchemaDefinitions defaultSchemaOptions
115+ declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
116
116
117-- | Convert a type into an optionally named schema.
117-- | Convert a type into an optionally named schema.
118toNamedSchema :: ToSchema a => proxy a -> NamedSchema
118toNamedSchema :: ToSchema a => proxy a -> NamedSchema
119−toNamedSchema = undeclare . toSchemaDefinitions
119+toNamedSchema = undeclare . declareNamedSchema
120
120
121-- | Get type's schema name according to its @'ToSchema'@ instance.
121-- | Get type's schema name according to its @'ToSchema'@ instance.
122schemaName :: ToSchema a => proxy a -> Maybe String
122schemaName :: ToSchema a => proxy a -> Maybe String
@@ -127,7 +127,7 @@ toSchema :: ToSchema a => proxy a -> Schema
127toSchema = snd . toNamedSchema
127toSchema = snd . toNamedSchema
128
128
129declareSchema :: ToSchema a => proxy a -> Declare Definitions Schema
129declareSchema :: ToSchema a => proxy a -> Declare Definitions Schema
130−declareSchema = fmap snd . toSchemaDefinitions
130+declareSchema = fmap snd . declareNamedSchema
131
131
132-- | Convert a type into a referenced schema if possible.
132-- | Convert a type into a referenced schema if possible.
133-- Only named schemas can be references, nameless schemas are inlined.
133-- Only named schemas can be references, nameless schemas are inlined.
@@ -141,41 +141,41 @@ declareSchemaRef proxy = do
141 known <- looks (HashMap.member (T.pack name))
141 known <- looks (HashMap.member (T.pack name))
142 when (not known) $ do
142 when (not known) $ do
143 declare [(T.pack name, schema)]
143 declare [(T.pack name, schema)]
144− void $ toSchemaDefinitions proxy
144+ void $ declareNamedSchema proxy
145 return $ Ref (Reference ("#/definitions/" <> T.pack name))
145 return $ Ref (Reference ("#/definitions/" <> T.pack name))
146 _ -> Inline <$> declareSchema proxy
146 _ -> Inline <$> declareSchema proxy
147
147
148class GToSchema (f :: * -> *) where
148class GToSchema (f :: * -> *) where
149− gtoSchemaDefinitions :: SchemaOptions -> proxy f -> Schema -> Declare Definitions NamedSchema
149+ gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare Definitions NamedSchema
150
150
151instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
151instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
152− toSchemaDefinitions _ = do
152+ declareNamedSchema _ = do
153 ref <- declareSchemaRef (Proxy :: Proxy a)
153 ref <- declareSchemaRef (Proxy :: Proxy a)
154 return $ unnamed $ mempty
154 return $ unnamed $ mempty
155 & schemaType .~ SwaggerArray
155 & schemaType .~ SwaggerArray
156 & schemaItems ?~ SchemaItemsObject ref
156 & schemaItems ?~ SchemaItemsObject ref
157
157
158−instance {-# OVERLAPPING #-} ToSchema String where toSchemaDefinitions = plain . paramSchemaToSchema
158+instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
159−instance ToSchema Bool where toSchemaDefinitions = plain . paramSchemaToSchema
159+instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
160−instance ToSchema Integer where toSchemaDefinitions = plain . paramSchemaToSchema
160+instance ToSchema Integer where declareNamedSchema = plain . paramSchemaToSchema
161−instance ToSchema Int where toSchemaDefinitions = plain . paramSchemaToSchema
161+instance ToSchema Int where declareNamedSchema = plain . paramSchemaToSchema
162−instance ToSchema Int8 where toSchemaDefinitions = plain . paramSchemaToSchema
162+instance ToSchema Int8 where declareNamedSchema = plain . paramSchemaToSchema
163−instance ToSchema Int16 where toSchemaDefinitions = plain . paramSchemaToSchema
163+instance ToSchema Int16 where declareNamedSchema = plain . paramSchemaToSchema
164−instance ToSchema Int32 where toSchemaDefinitions = plain . paramSchemaToSchema
164+instance ToSchema Int32 where declareNamedSchema = plain . paramSchemaToSchema
165−instance ToSchema Int64 where toSchemaDefinitions = plain . paramSchemaToSchema
165+instance ToSchema Int64 where declareNamedSchema = plain . paramSchemaToSchema
166−instance ToSchema Word where toSchemaDefinitions = plain . paramSchemaToSchema
166+instance ToSchema Word where declareNamedSchema = plain . paramSchemaToSchema
167−instance ToSchema Word8 where toSchemaDefinitions = plain . paramSchemaToSchema
167+instance ToSchema Word8 where declareNamedSchema = plain . paramSchemaToSchema
168−instance ToSchema Word16 where toSchemaDefinitions = plain . paramSchemaToSchema
168+instance ToSchema Word16 where declareNamedSchema = plain . paramSchemaToSchema
169−instance ToSchema Word32 where toSchemaDefinitions = plain . paramSchemaToSchema
169+instance ToSchema Word32 where declareNamedSchema = plain . paramSchemaToSchema
170−instance ToSchema Word64 where toSchemaDefinitions = plain . paramSchemaToSchema
170+instance ToSchema Word64 where declareNamedSchema = plain . paramSchemaToSchema
171−
171+
172−instance ToSchema Char where toSchemaDefinitions = plain . paramSchemaToSchema
172+instance ToSchema Char where declareNamedSchema = plain . paramSchemaToSchema
173−instance ToSchema Scientific where toSchemaDefinitions = plain . paramSchemaToSchema
173+instance ToSchema Scientific where declareNamedSchema = plain . paramSchemaToSchema
174−instance ToSchema Double where toSchemaDefinitions = plain . paramSchemaToSchema
174+instance ToSchema Double where declareNamedSchema = plain . paramSchemaToSchema
175−instance ToSchema Float where toSchemaDefinitions = plain . paramSchemaToSchema
175+instance ToSchema Float where declareNamedSchema = plain . paramSchemaToSchema
176
176
177instance ToSchema a => ToSchema (Maybe a) where
177instance ToSchema a => ToSchema (Maybe a) where
178− toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy a)
178+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy a)
179
179
180instance (ToSchema a, ToSchema b) => ToSchema (Either a b)
180instance (ToSchema a, ToSchema b) => ToSchema (Either a b)
181
181
@@ -197,69 +197,69 @@ timeSchema format = mempty
197-- >>> toSchema (Proxy :: Proxy Day) ^. schemaFormat
197-- >>> toSchema (Proxy :: Proxy Day) ^. schemaFormat
198-- Just "yyyy-mm-dd"
198-- Just "yyyy-mm-dd"
199instance ToSchema Day where
199instance ToSchema Day where
200− toSchemaDefinitions _ = pure $ named "Day" (timeSchema "yyyy-mm-dd")
200+ declareNamedSchema _ = pure $ named "Day" (timeSchema "yyyy-mm-dd")
201
201
202-- |
202-- |
203-- >>> toSchema (Proxy :: Proxy LocalTime) ^. schemaFormat
203-- >>> toSchema (Proxy :: Proxy LocalTime) ^. schemaFormat
204-- Just "yyyy-mm-ddThh:MM:ss"
204-- Just "yyyy-mm-ddThh:MM:ss"
205instance ToSchema LocalTime where
205instance 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")
207
207
208-- |
208-- |
209-- >>> toSchema (Proxy :: Proxy ZonedTime) ^. schemaFormat
209-- >>> toSchema (Proxy :: Proxy ZonedTime) ^. schemaFormat
210-- Just "yyyy-mm-ddThh:MM:ss(Z|+hh:MM)"
210-- Just "yyyy-mm-ddThh:MM:ss(Z|+hh:MM)"
211instance ToSchema ZonedTime where
211instance 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)"
213 & schemaMinLength ?~ toInteger (length ("yyyy-mm-ddThh:MM:ssZ" :: String))
213 & schemaMinLength ?~ toInteger (length ("yyyy-mm-ddThh:MM:ssZ" :: String))
214
214
215instance ToSchema NominalDiffTime where
215instance ToSchema NominalDiffTime where
216− toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy Integer)
216+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Integer)
217
217
218-- |
218-- |
219-- >>> toSchema (Proxy :: Proxy UTCTime) ^. schemaFormat
219-- >>> toSchema (Proxy :: Proxy UTCTime) ^. schemaFormat
220-- Just "yyyy-mm-ddThh:MM:ssZ"
220-- Just "yyyy-mm-ddThh:MM:ssZ"
221instance ToSchema UTCTime where
221instance 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")
223
223
224−instance ToSchema T.Text where toSchemaDefinitions = plain . paramSchemaToSchema
224+instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
225−instance ToSchema TL.Text where toSchemaDefinitions = plain . paramSchemaToSchema
225+instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
226
226
227−instance ToSchema IntSet where toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Set Int))
227+instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
228
228
229-- | NOTE: This schema does not account for the uniqueness of keys.
229-- | NOTE: This schema does not account for the uniqueness of keys.
230instance ToSchema a => ToSchema (IntMap a) where
230instance ToSchema a => ToSchema (IntMap a) where
231− toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy [(Int, a)])
231+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
232
232
233instance ToSchema a => ToSchema (Map String a) where
233instance ToSchema a => ToSchema (Map String a) where
234− toSchemaDefinitions _ = do
234+ declareNamedSchema _ = do
235 schema <- declareSchema (Proxy :: Proxy a)
235 schema <- declareSchema (Proxy :: Proxy a)
236 return $ unnamed $ mempty
236 return $ unnamed $ mempty
237 & schemaType .~ SwaggerObject
237 & schemaType .~ SwaggerObject
238 & schemaAdditionalProperties ?~ schema
238 & schemaAdditionalProperties ?~ schema
239
239
240−instance ToSchema a => ToSchema (Map T.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 toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Map String a))
241+instance ToSchema a => ToSchema (Map TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
242
242
243−instance ToSchema a => ToSchema (HashMap String 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 toSchemaDefinitions _ = toSchemaDefinitions (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 toSchemaDefinitions _ = toSchemaDefinitions (Proxy :: Proxy (Map String a))
245+instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
246
246
247instance ToSchema a => ToSchema (Set a) where
247instance ToSchema a => ToSchema (Set a) where
248− toSchemaDefinitions _ = do
248+ declareNamedSchema _ = do
249 schema <- declareSchema (Proxy :: Proxy [a])
249 schema <- declareSchema (Proxy :: Proxy [a])
250 return $ unnamed $ schema
250 return $ unnamed $ schema
251 & schemaUniqueItems ?~ True
251 & schemaUniqueItems ?~ True
252
252
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))
254
254
255−instance ToSchema All where toSchemaDefinitions = plain . paramSchemaToSchema
255+instance ToSchema All where declareNamedSchema = plain . paramSchemaToSchema
256−instance ToSchema Any where toSchemaDefinitions = plain . paramSchemaToSchema
256+instance ToSchema Any where declareNamedSchema = plain . paramSchemaToSchema
257
257
258−instance ToSchema a => ToSchema (Sum 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 toSchemaDefinitions _ = unname <$> toSchemaDefinitions (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 toSchemaDefinitions _ = unname <$> toSchemaDefinitions (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 toSchemaDefinitions _ = unname <$> toSchemaDefinitions (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 toSchemaDefinitions _ = unname <$> toSchemaDefinitions (Proxy :: Proxy a)
262+instance ToSchema a => ToSchema (Dual a) where declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
263
263
264-- | Default schema for @'Bounded'@, @'Integral'@ types.
264-- | Default schema for @'Bounded'@, @'Integral'@ types.
265toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
265toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
@@ -282,14 +282,14 @@ genericToSchema opts = snd . genericToNamedSchema opts
282
282
283-- | A configurable generic @'NamedSchema'@ creator.
283-- | A configurable generic @'NamedSchema'@ creator.
284genericToNamedSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> NamedSchema
284genericToNamedSchema :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> NamedSchema
285−genericToNamedSchema opts = undeclare . genericToSchemaDefinitions opts
285+genericToNamedSchema opts = undeclare . genericDeclareNamedSchema opts
286
286
287-- | A configurable generic @'NamedSchema'@ creator with declarations.
287-- | A configurable generic @'NamedSchema'@ creator with declarations.
288-- This function applied to @'defaultSchemaOptions'@
288-- This function applied to @'defaultSchemaOptions'@
289−-- is used as the default for @'toSchemaDefinitions'@
289+-- is used as the default for @'declareNamedSchema'@
290-- when the type is an instance of @'Generic'@.
290-- when the type is an instance of @'Generic'@.
291−genericToSchemaDefinitions :: forall a proxy. (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare Definitions NamedSchema
291+genericDeclareNamedSchema :: forall a proxy. (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare Definitions NamedSchema
292−genericToSchemaDefinitions opts _ = gtoSchemaDefinitions opts (Proxy :: Proxy (Rep a)) mempty
292+genericDeclareNamedSchema opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
293
293
294gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe String
294gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe String
295gdatatypeSchemaName opts _ = case name of
295gdatatypeSchemaName opts _ = case name of
@@ -314,36 +314,36 @@ nullarySchema = mempty
314 & schemaEnum ?~ [ toJSON () ]
314 & schemaEnum ?~ [ toJSON () ]
315
315
316gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
316gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
317−gtoNamedSchema opts proxy = undeclare $ gtoSchemaDefinitions opts proxy mempty
317+gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
318
318
319gtoSchema :: GToSchema f => SchemaOptions -> proxy f -> Schema
319gtoSchema :: GToSchema f => SchemaOptions -> proxy f -> Schema
320gtoSchema opts = snd . gtoNamedSchema opts
320gtoSchema opts = snd . gtoNamedSchema opts
321
321
322gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare Definitions Schema
322gdeclareSchema :: 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
324
324
325gschemaName :: GToSchema f => SchemaOptions -> proxy f -> Maybe String
325gschemaName :: GToSchema f => SchemaOptions -> proxy f -> Maybe String
326gschemaName opts = fst . gtoNamedSchema opts
326gschemaName opts = fst . gtoNamedSchema opts
327
327
328instance GToSchema U1 where
328instance GToSchema U1 where
329− gtoSchemaDefinitions _ _ _ = plain nullarySchema
329+ gdeclareNamedSchema _ _ _ = plain nullarySchema
330
330
331instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
331instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
332− gtoSchemaDefinitions opts _ schema = do
332+ gdeclareNamedSchema opts _ schema = do
333− (_, gschema) <- gtoSchemaDefinitions opts (Proxy :: Proxy g) schema
333+ (_, gschema) <- gdeclareNamedSchema opts (Proxy :: Proxy g) schema
334− gtoSchemaDefinitions opts (Proxy :: Proxy f) gschema
334+ gdeclareNamedSchema opts (Proxy :: Proxy f) gschema
335
335
336instance (Datatype d, GToSchema f) => GToSchema (D1 d f) where
336instance (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
338 where
338 where
339 name = gdatatypeSchemaName opts (Proxy :: Proxy d)
339 name = gdatatypeSchemaName opts (Proxy :: Proxy d)
340
340
341instance {-# OVERLAPPABLE #-} GToSchema f => GToSchema (C1 c f) where
341instance {-# OVERLAPPABLE #-} GToSchema f => GToSchema (C1 c f) where
342− gtoSchemaDefinitions opts _ = gtoSchemaDefinitions opts (Proxy :: Proxy f)
342+ gdeclareNamedSchema opts _ = gdeclareNamedSchema opts (Proxy :: Proxy f)
343
343
344-- | Single field constructor.
344-- | Single field constructor.
345instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
345instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
346− gtoSchemaDefinitions opts _ s
346+ gdeclareNamedSchema opts _ s
347 | unwrapUnaryRecords opts = fieldSchema
347 | unwrapUnaryRecords opts = fieldSchema
348 | otherwise = do
348 | otherwise = do
349 (_, schema) <- recordSchema
349 (_, schema) <- recordSchema
@@ -351,8 +351,8 @@ instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
351 Just (SchemaItemsArray [_]) -> fieldSchema
351 Just (SchemaItemsArray [_]) -> fieldSchema
352 _ -> pure (unnamed schema)
352 _ -> pure (unnamed schema)
353 where
353 where
354− recordSchema = gtoSchemaDefinitions opts (Proxy :: Proxy (S1 s f)) s
354+ recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
355− fieldSchema = gtoSchemaDefinitions opts (Proxy :: Proxy f) s
355+ fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
356
356
357gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare Definitions (Referenced Schema)
357gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare Definitions (Referenced Schema)
358gdeclareSchemaRef opts proxy = do
358gdeclareSchemaRef opts proxy = do
@@ -361,7 +361,7 @@ gdeclareSchemaRef opts proxy = do
361 known <- looks (HashMap.member (T.pack name))
361 known <- looks (HashMap.member (T.pack name))
362 when (not known) $ do
362 when (not known) $ do
363 declare [(T.pack name, schema)]
363 declare [(T.pack name, schema)]
364− void $ gtoSchemaDefinitions opts proxy mempty
364+ void $ gdeclareNamedSchema opts proxy mempty
365 return $ Ref (Reference ("#/definitions/" <> T.pack name))
365 return $ Ref (Reference ("#/definitions/" <> T.pack name))
366 _ -> Inline <$> gdeclareSchema opts proxy
366 _ -> Inline <$> gdeclareSchema opts proxy
367
367
@@ -390,20 +390,20 @@ withFieldSchema opts _ isRequiredField schema = do
390
390
391-- | Optional record fields.
391-- | Optional record fields.
392instance {-# OVERLAPPING #-} (Selector s, ToSchema c) => GToSchema (S1 s (K1 i (Maybe c))) where
392instance {-# 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
394
394
395-- | Record fields.
395-- | Record fields.
396instance {-# OVERLAPPABLE #-} (Selector s, GToSchema f) => GToSchema (S1 s f) where
396instance {-# 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
398
398
399instance {-# OVERLAPPING #-} ToSchema c => GToSchema (K1 i (Maybe c)) where
399instance {-# OVERLAPPING #-} ToSchema c => GToSchema (K1 i (Maybe c)) where
400− gtoSchemaDefinitions _ _ _ = toSchemaDefinitions (Proxy :: Proxy c)
400+ gdeclareNamedSchema _ _ _ = declareNamedSchema (Proxy :: Proxy c)
401
401
402instance {-# OVERLAPPABLE #-} ToSchema c => GToSchema (K1 i c) where
402instance {-# OVERLAPPABLE #-} ToSchema c => GToSchema (K1 i c) where
403− gtoSchemaDefinitions _ _ _ = toSchemaDefinitions (Proxy :: Proxy c)
403+ gdeclareNamedSchema _ _ _ = declareNamedSchema (Proxy :: Proxy c)
404
404
405instance (GSumToSchema f, GSumToSchema g) => GToSchema (f :+: g) where
405instance (GSumToSchema f, GSumToSchema g) => GToSchema (f :+: g) where
406− gtoSchemaDefinitions opts _ s
406+ gdeclareNamedSchema opts _ s
407 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
407 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
408 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
408 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
409 where
409 where
src/Data/Swagger/Schema.hs+1−1
@@ -17,7 +17,7 @@ module Data.Swagger.Schema (
17 -- * Generic schema encoding
17 -- * Generic schema encoding
18 genericToSchema,
18 genericToSchema,
19 genericToNamedSchema,
19 genericToNamedSchema,
20− genericToSchemaDefinitions,
20+ genericDeclareNamedSchema,
21 genericToNamedSchemaBoundedIntegral,
21 genericToNamedSchemaBoundedIntegral,
22 toSchemaBoundedIntegral,
22 toSchemaBoundedIntegral,
23 paramSchemaToNamedSchema,
23 paramSchemaToNamedSchema,
test/Data/Swagger/SchemaSpec.hs+8−8
@@ -35,7 +35,7 @@ checkDefs proxy names =
35 it ("uses these definitions " ++ show names) $
35 it ("uses these definitions " ++ show names) $
36 Set.fromList (HashMap.keys defs) `shouldBe` Set.fromList (map Text.pack names)
36 Set.fromList (HashMap.keys defs) `shouldBe` Set.fromList (map Text.pack names)
37 where
37 where
38− defs = execDeclare (toSchemaDefinitions proxy) mempty
38+ defs = execDeclare (declareNamedSchema proxy) mempty
39
39
40spec :: Spec
40spec :: Spec
41spec = do
41spec = do
@@ -124,7 +124,7 @@ data Point = Point
124 } deriving (Generic)
124 } deriving (Generic)
125
125
126instance ToSchema Point where
126instance ToSchema Point where
127− toSchemaDefinitions = genericToSchemaDefinitions defaultSchemaOptions
127+ declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
128 { fieldLabelModifier = map toLower . drop (length "point") }
128 { fieldLabelModifier = map toLower . drop (length "point") }
129
129
130pointSchemaJSON :: Value
130pointSchemaJSON :: Value
@@ -164,7 +164,7 @@ colorSchemaJSON = [aesonQQ|
164
164
165data Shade = Dim | Bright deriving (Generic, ToParamSchema)
165data Shade = Dim | Bright deriving (Generic, ToParamSchema)
166
166
167−instance ToSchema Shade where toSchemaDefinitions = pure . paramSchemaToNamedSchema defaultSchemaOptions
167+instance ToSchema Shade where declareNamedSchema = pure . paramSchemaToNamedSchema defaultSchemaOptions
168
168
169shadeSchemaJSON :: Value
169shadeSchemaJSON :: Value
170shadeSchemaJSON = [aesonQQ|
170shadeSchemaJSON = [aesonQQ|
@@ -204,7 +204,7 @@ newtype Email = Email { getEmail :: String }
204 deriving (Generic)
204 deriving (Generic)
205
205
206instance ToSchema Email where
206instance ToSchema Email where
207− toSchemaDefinitions = genericToSchemaDefinitions defaultSchemaOptions
207+ declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
208 { unwrapUnaryRecords = True }
208 { unwrapUnaryRecords = True }
209
209
210emailSchemaJSON :: Value
210emailSchemaJSON :: Value
@@ -277,7 +277,7 @@ data MyRoseTree = MyRoseTree
277 } deriving (Generic)
277 } deriving (Generic)
278
278
279instance ToSchema MyRoseTree where
279instance ToSchema MyRoseTree where
280− toSchemaDefinitions = genericToSchemaDefinitions defaultSchemaOptions
280+ declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
281 { datatypeNameModifier = drop (length "My") }
281 { datatypeNameModifier = drop (length "My") }
282
282
283myRoseTreeSchemaJSON :: Value
283myRoseTreeSchemaJSON :: Value
@@ -307,7 +307,7 @@ myRoseTreeSchemaJSON = [aesonQQ|
307newtype Inlined a = Inlined { getInlined :: a }
307newtype Inlined a = Inlined { getInlined :: a }
308
308
309instance ToSchema a => ToSchema (Inlined a) where
309instance ToSchema a => ToSchema (Inlined a) where
310− toSchemaDefinitions _ = unname <$> toSchemaDefinitions (Proxy :: Proxy a)
310+ declareNamedSchema _ = unname <$> declareNamedSchema (Proxy :: Proxy a)
311 where
311 where
312 unname (_, schema) = (Nothing, schema)
312 unname (_, schema) = (Nothing, schema)
313
313
@@ -343,7 +343,7 @@ data Status
343 deriving (Generic)
343 deriving (Generic)
344
344
345instance ToSchema Status where
345instance ToSchema Status where
346− toSchemaDefinitions = genericToSchemaDefinitions defaultSchemaOptions
346+ declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
347 { constructorTagModifier = map toLower . drop (length "Status") }
347 { constructorTagModifier = map toLower . drop (length "Status") }
348
348
349statusSchemaJSON :: Value
349statusSchemaJSON :: Value
@@ -418,7 +418,7 @@ data Light
418 deriving (Generic)
418 deriving (Generic)
419
419
420instance ToSchema Light where
420instance ToSchema Light where
421− toSchemaDefinitions = genericToSchemaDefinitions defaultSchemaOptions
421+ declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
422 { unwrapUnaryRecords = True }
422 { unwrapUnaryRecords = True }
423
423
424lightSchemaJSON :: Value
424lightSchemaJSON :: Value