@@ -32,7 +32,7 @@ import Data.Data.Lens (template)
33import Control.Monad
33import Control.Monad
34import Control.Monad.Writer
34import Control.Monad.Writer
35−import Data.Aeson (ToJSON (..), ToJSONKey (..), ToJSONKeyFunction (..), Value (..), Object(..))
35+import Data.Aeson (ToJSON (..), ToJSONKey (..), ToJSONKeyFunction (..), Value (..))
36import Data.Char
36import Data.Char
37import Data.Data (Data)
37import Data.Data (Data)
38import Data.Foldable (traverse_)
38import Data.Foldable (traverse_)
@@ -44,7 +44,6 @@ import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
44import Data.Int
44import Data.Int
45import Data.IntSet (IntSet)
45import Data.IntSet (IntSet)
46import Data.IntMap (IntMap)
46import Data.IntMap (IntMap)
47−import Data.List.NonEmpty.Compat (NonEmpty)
48import Data.Map (Map)
47import Data.Map (Map)
49import Data.Proxy
48import Data.Proxy
50import Data.Scientific (Scientific)
49import Data.Scientific (Scientific)
@@ -57,8 +56,7 @@ import qualified Data.Vector as V
57import qualified Data.Vector.Primitive as VP
56import qualified Data.Vector.Primitive as VP
58import qualified Data.Vector.Storable as VS
57import qualified Data.Vector.Storable as VS
59import qualified Data.Vector.Unboxed as VU
58import qualified Data.Vector.Unboxed as VU
60−import Data.Version (Version)
61−import Numeric.Natural.Compat (Natural)
59+import Numeric.Natural
62import Data.Word
60import Data.Word
63import GHC.Generics
61import GHC.Generics
64import qualified Data.UUID.Types as UUID
62import qualified Data.UUID.Types as UUID
@@ -75,6 +73,7 @@ import Data.Swagger.Internal.TypeShape
76import qualified Data.ByteString as BS
74import qualified Data.ByteString as BS
77import qualified Data.ByteString.Lazy as BSL
75import qualified Data.ByteString.Lazy as BSL
76+import Data.List.NonEmpty (NonEmpty)
78import GHC.TypeLits (TypeError, ErrorMessage(..))
77import GHC.TypeLits (TypeError, ErrorMessage(..))
@@ -111,7 +110,7 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
111-- declareNamedSchema _ = do
110-- declareNamedSchema _ = do
112-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
111-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
113-- return $ NamedSchema (Just \"Coord\") $ mempty
112-- return $ NamedSchema (Just \"Coord\") $ mempty
114−-- & type_ ?~ SwaggerObject
113+-- & type_ .~ SwaggerObject
115-- & properties .~
114-- & properties .~
116-- [ (\"x\", doubleSchema)
115-- [ (\"x\", doubleSchema)
117-- , (\"y\", doubleSchema)
116-- , (\"y\", doubleSchema)
@@ -142,17 +141,13 @@ class ToSchema a where
142 -- together with all used definitions.
141 -- together with all used definitions.
143 -- Note that the schema itself is included in definitions
142 -- Note that the schema itself is included in definitions
144 -- only if it is recursive (and thus needs its definition in scope).
143 -- only if it is recursive (and thus needs its definition in scope).
145− declareNamedSchema :: Proxy a -> Declare (Definitions Schema) NamedSchema
144+ declareNamedSchema :: proxy a -> Declare (Definitions Schema) NamedSchema
146 default declareNamedSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
145 default declareNamedSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
147− Proxy a -> Declare (Definitions Schema) NamedSchema
146+ proxy a -> Declare (Definitions Schema) NamedSchema
148 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
147 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
150−instance ToSchema TimeOfDay where
151− declareNamedSchema _ = pure $ named "TimeOfDay" $ timeSchema "hh:MM:ss"
152− & example ?~ toJSON (TimeOfDay 12 33 15)
154-- | Convert a type into a schema and declare all used schema definitions.
149-- | Convert a type into a schema and declare all used schema definitions.
155−declareSchema :: ToSchema a => Proxy a -> Declare (Definitions Schema) Schema
150+declareSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) Schema
156declareSchema = fmap _namedSchemaSchema . declareNamedSchema
151declareSchema = fmap _namedSchemaSchema . declareNamedSchema
158-- | Convert a type into an optionally named schema.
153-- | Convert a type into an optionally named schema.
@@ -166,7 +161,7 @@ declareSchema = fmap _namedSchemaSchema . declareNamedSchema
166-- Just "Day"
161-- Just "Day"
167-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
162-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
168-- "{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}"
163-- "{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}"
169−toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
164+toNamedSchema :: ToSchema a => proxy a -> NamedSchema
170toNamedSchema = undeclare . declareNamedSchema
165toNamedSchema = undeclare . declareNamedSchema
172-- | Get type's schema name according to its @'ToSchema'@ instance.
167-- | Get type's schema name according to its @'ToSchema'@ instance.
@@ -176,7 +171,7 @@ toNamedSchema = undeclare . declareNamedSchema
177-- >>> schemaName (Proxy :: Proxy UTCTime)
172-- >>> schemaName (Proxy :: Proxy UTCTime)
178-- Just "UTCTime"
173-- Just "UTCTime"
179−schemaName :: ToSchema a => Proxy a -> Maybe T.Text
174+schemaName :: ToSchema a => proxy a -> Maybe T.Text
180schemaName = _namedSchemaName . toNamedSchema
175schemaName = _namedSchemaName . toNamedSchema
182-- | Convert a type into a schema.
177-- | Convert a type into a schema.
@@ -186,7 +181,7 @@ schemaName = _namedSchemaName . toNamedSchema
187-- >>> encode $ toSchema (Proxy :: Proxy [Day])
182-- >>> encode $ toSchema (Proxy :: Proxy [Day])
188-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
183-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
189−toSchema :: ToSchema a => Proxy a -> Schema
184+toSchema :: ToSchema a => proxy a -> Schema
190toSchema = _namedSchemaSchema . toNamedSchema
185toSchema = _namedSchemaSchema . toNamedSchema
192-- | Convert a type into a referenced schema if possible.
187-- | Convert a type into a referenced schema if possible.
@@ -197,7 +192,7 @@ toSchema = _namedSchemaSchema . toNamedSchema
198-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
193-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
199-- "{\"$ref\":\"#/definitions/Day\"}"
194-- "{\"$ref\":\"#/definitions/Day\"}"
200−toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
195+toSchemaRef :: ToSchema a => proxy a -> Referenced Schema
201toSchemaRef = undeclare . declareSchemaRef
196toSchemaRef = undeclare . declareSchemaRef
203-- | Convert a type into a referenced schema if possible
198-- | Convert a type into a referenced schema if possible
@@ -207,7 +202,7 @@ toSchemaRef = undeclare . declareSchemaRef
207-- Schema definitions are typically declared for every referenced schema.
202-- Schema definitions are typically declared for every referenced schema.
208-- If @'declareSchemaRef'@ returns a reference, a corresponding schema
203-- If @'declareSchemaRef'@ returns a reference, a corresponding schema
209-- will be declared (regardless of whether it is recusive or not).
204-- will be declared (regardless of whether it is recusive or not).
210−declareSchemaRef :: ToSchema a => Proxy a -> Declare (Definitions Schema) (Referenced Schema)
205+declareSchemaRef :: ToSchema a => proxy a -> Declare (Definitions Schema) (Referenced Schema)
211declareSchemaRef proxy = do
206declareSchemaRef proxy = do
212 case toNamedSchema proxy of
207 case toNamedSchema proxy of
213 NamedSchema (Just name) schema -> do
208 NamedSchema (Just name) schema -> do
@@ -269,7 +264,7 @@ inlineAllSchemas = inlineSchemasWhen (const True)
270-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
265-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
271-- when inlining recursive schemas.
266-- when inlining recursive schemas.
272−toInlinedSchema :: ToSchema a => Proxy a -> Schema
267+toInlinedSchema :: ToSchema a => proxy a -> Schema
273toInlinedSchema proxy = inlineAllSchemas defs schema
268toInlinedSchema proxy = inlineAllSchemas defs schema
275 (defs, schema) = runDeclare (declareSchema proxy) mempty
270 (defs, schema) = runDeclare (declareSchema proxy) mempty
@@ -298,20 +293,20 @@ inlineNonRecursiveSchemas defs = inlineSchemasWhen nonRecursive defs
298-- | Default schema for binary data (any sequence of octets).
293-- | Default schema for binary data (any sequence of octets).
299binarySchema :: Schema
294binarySchema :: Schema
300binarySchema = mempty
295binarySchema = mempty
301− & type_ ?~ SwaggerString
296+ & type_ .~ SwaggerString
302 & format ?~ "binary"
297 & format ?~ "binary"
304-- | Default schema for binary data (base64 encoded).
299-- | Default schema for binary data (base64 encoded).
305byteSchema :: Schema
300byteSchema :: Schema
306byteSchema = mempty
301byteSchema = mempty
307− & type_ ?~ SwaggerString
302+ & type_ .~ SwaggerString
308 & format ?~ "byte"
303 & format ?~ "byte"
310-- | Default schema for password string.
305-- | Default schema for password string.
311-- @"password"@ format is used to hint UIs the input needs to be obscured.
306-- @"password"@ format is used to hint UIs the input needs to be obscured.
312passwordSchema :: Schema
307passwordSchema :: Schema
313passwordSchema = mempty
308passwordSchema = mempty
314− & type_ ?~ SwaggerString
309+ & type_ .~ SwaggerString
315 & format ?~ "password"
310 & format ?~ "password"
317-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
312-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
@@ -337,12 +332,12 @@ sketchSchema = sketch . toJSON
337 sketch js@(Bool _) = go js
332 sketch js@(Bool _) = go js
338 sketch js = go js & example ?~ js
333 sketch js = go js & example ?~ js
340− go Null = mempty & type_ ?~ SwaggerNull
335+ go Null = mempty & type_ .~ SwaggerNull
341− go (Bool _) = mempty & type_ ?~ SwaggerBoolean
336+ go (Bool _) = mempty & type_ .~ SwaggerBoolean
342− go (String _) = mempty & type_ ?~ SwaggerString
337+ go (String _) = mempty & type_ .~ SwaggerString
343− go (Number _) = mempty & type_ ?~ SwaggerNumber
338+ go (Number _) = mempty & type_ .~ SwaggerNumber
344 go (Array xs) = mempty
339 go (Array xs) = mempty
345− & type_ ?~ SwaggerArray
340+ & type_ .~ SwaggerArray
346 & items ?~ case ischema of
341 & items ?~ case ischema of
347 Just s -> SwaggerItemsObject (Inline s)
342 Just s -> SwaggerItemsObject (Inline s)
348 _ -> SwaggerItemsArray (map Inline ys)
343 _ -> SwaggerItemsArray (map Inline ys)
@@ -354,7 +349,7 @@ sketchSchema = sketch . toJSON
354 (z:_) | allSame -> Just z
349 (z:_) | allSame -> Just z
355 _ -> Nothing
350 _ -> Nothing
356 go (Object o) = mempty
351 go (Object o) = mempty
357− & type_ ?~ SwaggerObject
352+ & type_ .~ SwaggerObject
358 & required .~ HashMap.keys o
353 & required .~ HashMap.keys o
359 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
354 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
@@ -377,24 +372,24 @@ sketchSchema = sketch . toJSON
377sketchStrictSchema :: ToJSON a => a -> Schema
372sketchStrictSchema :: ToJSON a => a -> Schema
378sketchStrictSchema = go . toJSON
373sketchStrictSchema = go . toJSON
380− go Null = mempty & type_ ?~ SwaggerNull
375+ go Null = mempty & type_ .~ SwaggerNull
381 go js@(Bool _) = mempty
376 go js@(Bool _) = mempty
382− & type_ ?~ SwaggerBoolean
377+ & type_ .~ SwaggerBoolean
383 & enum_ ?~ [js]
378 & enum_ ?~ [js]
384 go js@(String s) = mempty
379 go js@(String s) = mempty
385− & type_ ?~ SwaggerString
380+ & type_ .~ SwaggerString
386 & maxLength ?~ fromIntegral (T.length s)
381 & maxLength ?~ fromIntegral (T.length s)
387 & minLength ?~ fromIntegral (T.length s)
382 & minLength ?~ fromIntegral (T.length s)
388 & pattern ?~ s
383 & pattern ?~ s
389 & enum_ ?~ [js]
384 & enum_ ?~ [js]
390 go js@(Number n) = mempty
385 go js@(Number n) = mempty
391− & type_ ?~ SwaggerNumber
386+ & type_ .~ SwaggerNumber
392 & maximum_ ?~ n
387 & maximum_ ?~ n
393 & minimum_ ?~ n
388 & minimum_ ?~ n
394 & multipleOf ?~ n
389 & multipleOf ?~ n
395 & enum_ ?~ [js]
390 & enum_ ?~ [js]
396 go js@(Array xs) = mempty
391 go js@(Array xs) = mempty
397− & type_ ?~ SwaggerArray
392+ & type_ .~ SwaggerArray
398 & maxItems ?~ fromIntegral sz
393 & maxItems ?~ fromIntegral sz
399 & minItems ?~ fromIntegral sz
394 & minItems ?~ fromIntegral sz
400 & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
395 & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
@@ -404,7 +399,7 @@ sketchStrictSchema = go . toJSON
404 sz = length xs
399 sz = length xs
405 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
400 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
406 go js@(Object o) = mempty
401 go js@(Object o) = mempty
407− & type_ ?~ SwaggerObject
402+ & type_ .~ SwaggerObject
408 & required .~ names
403 & required .~ names
409 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
404 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
410 & maxProperties ?~ fromIntegral (length names)
405 & maxProperties ?~ fromIntegral (length names)
@@ -414,13 +409,13 @@ sketchStrictSchema = go . toJSON
414 names = HashMap.keys o
409 names = HashMap.keys o
416class GToSchema (f :: * -> *) where
411class GToSchema (f :: * -> *) where
417− gdeclareNamedSchema :: SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
412+ gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
419instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
414instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
420 declareNamedSchema _ = do
415 declareNamedSchema _ = do
421 ref <- declareSchemaRef (Proxy :: Proxy a)
416 ref <- declareSchemaRef (Proxy :: Proxy a)
422 return $ unnamed $ mempty
417 return $ unnamed $ mempty
423− & type_ ?~ SwaggerArray
418+ & type_ .~ SwaggerArray
424 & items ?~ SwaggerItemsObject ref
419 & items ?~ SwaggerItemsObject ref
426instance OVERLAPPING_ ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
421instance OVERLAPPING_ ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
@@ -470,7 +465,7 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f
471timeSchema :: T.Text -> Schema
466timeSchema :: T.Text -> Schema
472timeSchema fmt = mempty
467timeSchema fmt = mempty
473− & type_ ?~ SwaggerString
468+ & type_ .~ SwaggerString
474 & format ?~ fmt
469 & format ?~ fmt
476-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
471-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -503,8 +498,6 @@ instance ToSchema UTCTime where
503instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
498instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
504instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
499instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
506−instance ToSchema Version where declareNamedSchema = plain . paramSchemaToSchema
508#if __GLASGOW_HASKELL__ < 800
501#if __GLASGOW_HASKELL__ < 800
510type family ToSchemaByteStringError bs where
503type family ToSchemaByteStringError bs where
@@ -532,8 +525,8 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
532 declareObjectMapSchema = do
525 declareObjectMapSchema = do
533 schema <- declareSchemaRef (Proxy :: Proxy v)
526 schema <- declareSchemaRef (Proxy :: Proxy v)
534 return $ unnamed $ mempty
527 return $ unnamed $ mempty
535− & type_ ?~ SwaggerObject
528+ & type_ .~ SwaggerObject
536− & additionalProperties ?~ AdditionalPropertiesSchema schema
529+ & additionalProperties ?~ schema
538instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
531instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
539 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
532 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
@@ -544,7 +537,7 @@ instance ToSchema a => ToSchema (Map String a) where
544 declareNamedSchema _ = do
537 declareNamedSchema _ = do
545 schema <- declareSchemaRef (Proxy :: Proxy a)
538 schema <- declareSchemaRef (Proxy :: Proxy a)
546 return $ unnamed $ mempty
539 return $ unnamed $ mempty
547− & type_ ?~ SwaggerObject
540+ & type_ .~ SwaggerObject
548 & additionalProperties ?~ schema
541 & additionalProperties ?~ schema
550instance ToSchema a => ToSchema (Map T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
543instance ToSchema a => ToSchema (Map T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
@@ -556,12 +549,6 @@ instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ =
559−instance OVERLAPPING_ ToSchema Object where
560− declareNamedSchema _ = pure $ NamedSchema (Just "Object") $ mempty
561− & type_ ?~ SwaggerObject
562− & description ?~ "Arbitrary JSON object."
563− & additionalProperties ?~ AdditionalPropertiesAllowed True
565instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
552instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
566instance ToSchema a => ToSchema (VU.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
553instance ToSchema a => ToSchema (VU.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
567instance ToSchema a => ToSchema (VS.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
554instance ToSchema a => ToSchema (VS.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
@@ -575,12 +562,14 @@ instance ToSchema a => ToSchema (Set a) where
576instance ToSchema a => ToSchema (HashSet a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set a))
563instance ToSchema a => ToSchema (HashSet a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set a))
578−-- | @since 2.2.1
565+#if __GLASGOW_HASKELL__ < 800
579instance ToSchema a => ToSchema (NonEmpty a) where
567instance ToSchema a => ToSchema (NonEmpty a) where
580 declareNamedSchema _ = do
568 declareNamedSchema _ = do
581 schema <- declareSchema (Proxy :: Proxy [a])
569 schema <- declareSchema (Proxy :: Proxy [a])
582 return $ unnamed $ schema
570 return $ unnamed $ schema
583 & minItems .~ Just 1
571 & minItems .~ Just 1
585instance ToSchema All where declareNamedSchema = plain . paramSchemaToSchema
574instance ToSchema All where declareNamedSchema = plain . paramSchemaToSchema
586instance ToSchema Any where declareNamedSchema = plain . paramSchemaToSchema
575instance ToSchema Any where declareNamedSchema = plain . paramSchemaToSchema
@@ -597,26 +586,26 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
598-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
587-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
599-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
588-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
600−toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
589+toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
601toSchemaBoundedIntegral _ = mempty
590toSchemaBoundedIntegral _ = mempty
602− & type_ ?~ SwaggerInteger
591+ & type_ .~ SwaggerInteger
603 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
592 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
604 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
593 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
606-- | Default generic named schema for @'Bounded'@, @'Integral'@ types.
595-- | Default generic named schema for @'Bounded'@, @'Integral'@ types.
607−genericToNamedSchemaBoundedIntegral :: forall a d f.
596+genericToNamedSchemaBoundedIntegral :: forall a d f proxy.
608 ( Bounded a, Integral a
597 ( Bounded a, Integral a
609 , Generic a, Rep a ~ D1 d f, Datatype d)
598 , Generic a, Rep a ~ D1 d f, Datatype d)
610− => SchemaOptions -> Proxy a -> NamedSchema
599+ => SchemaOptions -> proxy a -> NamedSchema
611genericToNamedSchemaBoundedIntegral opts proxy
600genericToNamedSchemaBoundedIntegral opts proxy
612 = genericNameSchema opts proxy (toSchemaBoundedIntegral proxy)
601 = genericNameSchema opts proxy (toSchemaBoundedIntegral proxy)
614-- | Declare a named schema for a @newtype@ wrapper.
603-- | Declare a named schema for a @newtype@ wrapper.
615−genericDeclareNamedSchemaNewtype :: forall a d c s i inner.
604+genericDeclareNamedSchemaNewtype :: forall proxy a d c s i inner.
616 (Generic a, Datatype d, Rep a ~ D1 d (C1 c (S1 s (K1 i inner))))
605 (Generic a, Datatype d, Rep a ~ D1 d (C1 c (S1 s (K1 i inner))))
617 => SchemaOptions -- ^ How to derive the name.
606 => SchemaOptions -- ^ How to derive the name.
618 -> (Proxy inner -> Declare (Definitions Schema) Schema) -- ^ How to create a schema for the wrapped type.
607 -> (Proxy inner -> Declare (Definitions Schema) Schema) -- ^ How to create a schema for the wrapped type.
619− -> Proxy a
608+ -> proxy a
620 -> Declare (Definitions Schema) NamedSchema
609 -> Declare (Definitions Schema) NamedSchema
621genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$> f (Proxy :: Proxy inner)
610genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$> f (Proxy :: Proxy inner)
@@ -633,9 +622,9 @@ genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$>
634-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
623-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
635-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
624-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
636−declareSchemaBoundedEnumKeyMapping :: forall map key value.
625+declareSchemaBoundedEnumKeyMapping :: forall map key value proxy.
637 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
626 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
638− => Proxy (map key value) -> Declare (Definitions Schema) Schema
627+ => proxy (map key value) -> Declare (Definitions Schema) Schema
639declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key of
628declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key of
640 ToJSONKeyText keyToText _ -> objectSchema keyToText
629 ToJSONKeyText keyToText _ -> objectSchema keyToText
641 ToJSONKeyValue _ _ -> declareSchema (Proxy :: Proxy [(key, value)])
630 ToJSONKeyValue _ _ -> declareSchema (Proxy :: Proxy [(key, value)])
@@ -645,7 +634,7 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
645 let allKeys = [minBound..maxBound :: key]
634 let allKeys = [minBound..maxBound :: key]
646 mkPair k = (keyToText k, valueRef)
635 mkPair k = (keyToText k, valueRef)
647 return $ mempty
636 return $ mempty
648− & type_ ?~ SwaggerObject
637+ & type_ .~ SwaggerObject
649 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
638 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
651-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
640-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
@@ -661,46 +650,46 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
662-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
651-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
663-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
652-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
664−toSchemaBoundedEnumKeyMapping :: forall map key value.
653+toSchemaBoundedEnumKeyMapping :: forall map key value proxy.
665 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
654 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
666− => Proxy (map key value) -> Schema
655+ => proxy (map key value) -> Schema
667toSchemaBoundedEnumKeyMapping = flip evalDeclare mempty . declareSchemaBoundedEnumKeyMapping
656toSchemaBoundedEnumKeyMapping = flip evalDeclare mempty . declareSchemaBoundedEnumKeyMapping
669-- | A configurable generic @'Schema'@ creator.
658-- | A configurable generic @'Schema'@ creator.
670genericDeclareSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareSchemaUnrestricted") =>
659genericDeclareSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareSchemaUnrestricted") =>
671− SchemaOptions -> Proxy a -> Declare (Definitions Schema) Schema
660+ SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
672genericDeclareSchema = genericDeclareSchemaUnrestricted
661genericDeclareSchema = genericDeclareSchemaUnrestricted
674-- | A configurable generic @'NamedSchema'@ creator.
663-- | A configurable generic @'NamedSchema'@ creator.
675-- This function applied to @'defaultSchemaOptions'@
664-- This function applied to @'defaultSchemaOptions'@
676-- is used as the default for @'declareNamedSchema'@
665-- is used as the default for @'declareNamedSchema'@
677-- when the type is an instance of @'Generic'@.
666-- when the type is an instance of @'Generic'@.
678−genericDeclareNamedSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
667+genericDeclareNamedSchema :: forall a proxy. (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
679− SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
668+ SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
680genericDeclareNamedSchema = genericDeclareNamedSchemaUnrestricted
669genericDeclareNamedSchema = genericDeclareNamedSchemaUnrestricted
682-- | A configurable generic @'Schema'@ creator.
671-- | A configurable generic @'Schema'@ creator.
684-- Unlike 'genericDeclareSchema' also works for mixed sum types.
673-- Unlike 'genericDeclareSchema' also works for mixed sum types.
685-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
674-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
686−genericDeclareSchemaUnrestricted :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> Proxy a -> Declare (Definitions Schema) Schema
675+genericDeclareSchemaUnrestricted :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
687genericDeclareSchemaUnrestricted opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchemaUnrestricted opts proxy
676genericDeclareSchemaUnrestricted opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchemaUnrestricted opts proxy
689-- | A configurable generic @'NamedSchema'@ creator.
678-- | A configurable generic @'NamedSchema'@ creator.
691-- Unlike 'genericDeclareNamedSchema' also works for mixed sum types.
680-- Unlike 'genericDeclareNamedSchema' also works for mixed sum types.
692-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
681-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
693−genericDeclareNamedSchemaUnrestricted :: forall a. (Generic a, GToSchema (Rep a)) =>
682+genericDeclareNamedSchemaUnrestricted :: forall a proxy. (Generic a, GToSchema (Rep a)) =>
694− SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
683+ SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
695genericDeclareNamedSchemaUnrestricted opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
684genericDeclareNamedSchemaUnrestricted opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
697-- | Derive a 'Generic'-based name for a datatype and assign it to a given 'Schema'.
686-- | Derive a 'Generic'-based name for a datatype and assign it to a given 'Schema'.
698−genericNameSchema :: forall a d f.
687+genericNameSchema :: forall a d f proxy.
699 (Generic a, Rep a ~ D1 d f, Datatype d)
688 (Generic a, Rep a ~ D1 d f, Datatype d)
700− => SchemaOptions -> Proxy a -> Schema -> NamedSchema
689+ => SchemaOptions -> proxy a -> Schema -> NamedSchema
701genericNameSchema opts _ = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d))
690genericNameSchema opts _ = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d))
703−gdatatypeSchemaName :: forall d. Datatype d => SchemaOptions -> Proxy d -> Maybe T.Text
692+gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe T.Text
704gdatatypeSchemaName opts _ = case orig of
693gdatatypeSchemaName opts _ = case orig of
705 (c:_) | isAlpha c && isUpper c -> Just (T.pack name)
694 (c:_) | isAlpha c && isUpper c -> Just (T.pack name)
706 _ -> Nothing
695 _ -> Nothing
@@ -709,23 +698,24 @@ gdatatypeSchemaName opts _ = case orig of
709 name = datatypeNameModifier opts orig
698 name = datatypeNameModifier opts orig
711-- | Lift a plain @'ParamSchema'@ into a model @'NamedSchema'@.
700-- | Lift a plain @'ParamSchema'@ into a model @'NamedSchema'@.
701+paramSchemaToNamedSchema :: forall a d f proxy.
712−paramSchemaToNamedSchema :: (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d) =>
702+ (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d)
713− SchemaOptions -> Proxy a -> NamedSchema
703+ => SchemaOptions -> proxy a -> NamedSchema
714paramSchemaToNamedSchema opts proxy = genericNameSchema opts proxy (paramSchemaToSchema proxy)
704paramSchemaToNamedSchema opts proxy = genericNameSchema opts proxy (paramSchemaToSchema proxy)
716-- | Lift a plain @'ParamSchema'@ into a model @'Schema'@.
706-- | Lift a plain @'ParamSchema'@ into a model @'Schema'@.
717−paramSchemaToSchema :: ToParamSchema a => Proxy a -> Schema
707+paramSchemaToSchema :: forall a proxy. ToParamSchema a => proxy a -> Schema
718−paramSchemaToSchema proxy = mempty & paramSchema .~ toParamSchema proxy
708+paramSchemaToSchema _ = mempty & paramSchema .~ toParamSchema (Proxy :: Proxy a)
720nullarySchema :: Schema
710nullarySchema :: Schema
721nullarySchema = mempty
711nullarySchema = mempty
722− & type_ ?~ SwaggerArray
712+ & type_ .~ SwaggerArray
723 & items ?~ SwaggerItemsArray []
713 & items ?~ SwaggerItemsArray []
725−gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
715+gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
726gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
716gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
728−gdeclareSchema :: GToSchema f => SchemaOptions -> Proxy f -> Declare (Definitions Schema) Schema
718+gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare (Definitions Schema) Schema
729gdeclareSchema opts proxy = _namedSchemaSchema <$> gdeclareNamedSchema opts proxy mempty
719gdeclareSchema opts proxy = _namedSchemaSchema <$> gdeclareNamedSchema opts proxy mempty
731instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
721instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
@@ -759,7 +749,7 @@ instance (Selector s, GToSchema f, GToSchema (S1 s f)) => GToSchema (C1 c (S1 s
759 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
749 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
760 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
750 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
762−gdeclareSchemaRef :: GToSchema a => SchemaOptions -> Proxy a -> Declare (Definitions Schema) (Referenced Schema)
752+gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare (Definitions Schema) (Referenced Schema)
763gdeclareSchemaRef opts proxy = do
753gdeclareSchemaRef opts proxy = do
764 case gtoNamedSchema opts proxy of
754 case gtoNamedSchema opts proxy of
765 NamedSchema (Just name) schema -> do
755 NamedSchema (Just name) schema -> do
@@ -790,12 +780,12 @@ withFieldSchema opts _ isRequiredField schema = do
791 if T.null fname
781 if T.null fname
792 then schema
782 then schema
793− & type_ ?~ SwaggerArray
783+ & type_ .~ SwaggerArray
794 & items %~ appendItem ref
784 & items %~ appendItem ref
795 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
785 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
796 & minItems %~ Just . maybe 1 (+1) -- increment minItems
786 & minItems %~ Just . maybe 1 (+1) -- increment minItems
797 else schema
787 else schema
798− & type_ ?~ SwaggerObject
788+ & type_ .~ SwaggerObject
799 & properties . at fname ?~ ref
789 & properties . at fname ?~ ref
800 & if isRequiredField
790 & if isRequiredField
801 then required %~ (++ [fname])
791 then required %~ (++ [fname])
@@ -823,7 +813,7 @@ instance ( GSumToSchema f
824 gdeclareNamedSchema = gdeclareNamedSumSchema
814 gdeclareNamedSchema = gdeclareNamedSumSchema
826−gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
816+gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
827gdeclareNamedSumSchema opts proxy s
817gdeclareNamedSumSchema opts proxy s
828 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
818 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
829 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
819 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
@@ -832,29 +822,29 @@ gdeclareNamedSumSchema opts proxy s
832 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
822 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
834 toStringTag schema = mempty
824 toStringTag schema = mempty
835− & type_ ?~ SwaggerString
825+ & type_ .~ SwaggerString
836 & enum_ ?~ map toJSON (schema ^.. properties.ifolded.asIndex)
826 & enum_ ?~ map toJSON (schema ^.. properties.ifolded.asIndex)
838type AllNullary = All
828type AllNullary = All
840class GSumToSchema (f :: * -> *) where
830class GSumToSchema (f :: * -> *) where
841− gsumToSchema :: SchemaOptions -> Proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
831+ gsumToSchema :: SchemaOptions -> proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
843instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
833instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
844 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) >=> gsumToSchema opts (Proxy :: Proxy g)
834 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) >=> gsumToSchema opts (Proxy :: Proxy g)
846−gsumConToSchemaWith :: forall c f. (GToSchema (C1 c f), Constructor c) =>
836+gsumConToSchemaWith :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
847− Referenced Schema -> SchemaOptions -> Proxy (C1 c f) -> Schema -> Schema
837+ Referenced Schema -> SchemaOptions -> proxy (C1 c f) -> Schema -> Schema
848gsumConToSchemaWith ref opts _ schema = schema
838gsumConToSchemaWith ref opts _ schema = schema
849− & type_ ?~ SwaggerObject
839+ & type_ .~ SwaggerObject
850 & properties . at tag ?~ ref
840 & properties . at tag ?~ ref
851 & maxProperties ?~ 1
841 & maxProperties ?~ 1
852 & minProperties ?~ 1
842 & minProperties ?~ 1
854 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
844 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
856−gsumConToSchema :: (GToSchema (C1 c f), Constructor c) =>
846+gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
857− SchemaOptions -> Proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
847+ SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
858gsumConToSchema opts proxy schema = do
848gsumConToSchema opts proxy schema = do
859 ref <- gdeclareSchemaRef opts proxy
849 ref <- gdeclareSchemaRef opts proxy
860 return $ gsumConToSchemaWith ref opts proxy schema
850 return $ gsumConToSchemaWith ref opts proxy schema