@@ -32,7 +32,7 @@ import Data.Data.Lens (template)
3232
3333import Control.Monad
3434import Control.Monad.Writer
35−import Data.Aeson (ToJSON (..), ToJSONKey (..), ToJSONKeyFunction (..), Value (..), Object(..))
35+import Data.Aeson
3636import Data.Char
3737import Data.Data (Data)
3838import Data.Foldable (traverse_)
@@ -44,7 +44,6 @@ import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
4444import Data.Int
4545import Data.IntSet (IntSet)
4646import Data.IntMap (IntMap)
47−import Data.List.NonEmpty.Compat (NonEmpty)
4847import Data.Map (Map)
4948import Data.Proxy
5049import Data.Scientific (Scientific)
@@ -57,8 +56,6 @@ import qualified Data.Vector as V
5756import qualified Data.Vector.Primitive as VP
5857import qualified Data.Vector.Storable as VS
5958import qualified Data.Vector.Unboxed as VU
60−import Data.Version (Version)
61−import Numeric.Natural.Compat (Natural)
6259import Data.Word
6360import GHC.Generics
6461import qualified Data.UUID.Types as UUID
@@ -111,7 +108,7 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
111108-- declareNamedSchema _ = do
112109-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
113110-- return $ NamedSchema (Just \"Coord\") $ mempty
114−-- & type_ ?~ SwaggerObject
111+-- & type_ .~ SwaggerObject
115112-- & properties .~
116113-- [ (\"x\", doubleSchema)
117114-- , (\"y\", doubleSchema)
@@ -142,17 +139,13 @@ class ToSchema a where
142139 -- together with all used definitions.
143140 -- Note that the schema itself is included in definitions
144141 -- only if it is recursive (and thus needs its definition in scope).
145− declareNamedSchema :: Proxy a -> Declare (Definitions Schema) NamedSchema
142+ declareNamedSchema :: proxy a -> Declare (Definitions Schema) NamedSchema
146143 default declareNamedSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
147− Proxy a -> Declare (Definitions Schema) NamedSchema
144+ proxy a -> Declare (Definitions Schema) NamedSchema
148145 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
149146
150−instance ToSchema TimeOfDay where
151− declareNamedSchema _ = pure $ named "TimeOfDay" $ timeSchema "hh:MM:ss"
152− & example ?~ toJSON (TimeOfDay 12 33 15)
153−
154147-- | Convert a type into a schema and declare all used schema definitions.
155−declareSchema :: ToSchema a => Proxy a -> Declare (Definitions Schema) Schema
148+declareSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) Schema
156149declareSchema = fmap _namedSchemaSchema . declareNamedSchema
157150
158151-- | Convert a type into an optionally named schema.
@@ -166,7 +159,7 @@ declareSchema = fmap _namedSchemaSchema . declareNamedSchema
166159-- Just "Day"
167160-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
168161-- "{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}"
169−toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
162+toNamedSchema :: ToSchema a => proxy a -> NamedSchema
170163toNamedSchema = undeclare . declareNamedSchema
171164
172165-- | Get type's schema name according to its @'ToSchema'@ instance.
@@ -176,7 +169,7 @@ toNamedSchema = undeclare . declareNamedSchema
176169--
177170-- >>> schemaName (Proxy :: Proxy UTCTime)
178171-- Just "UTCTime"
179−schemaName :: ToSchema a => Proxy a -> Maybe T.Text
172+schemaName :: ToSchema a => proxy a -> Maybe T.Text
180173schemaName = _namedSchemaName . toNamedSchema
181174
182175-- | Convert a type into a schema.
@@ -186,7 +179,7 @@ schemaName = _namedSchemaName . toNamedSchema
186179--
187180-- >>> encode $ toSchema (Proxy :: Proxy [Day])
188181-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
189−toSchema :: ToSchema a => Proxy a -> Schema
182+toSchema :: ToSchema a => proxy a -> Schema
190183toSchema = _namedSchemaSchema . toNamedSchema
191184
192185-- | Convert a type into a referenced schema if possible.
@@ -197,7 +190,7 @@ toSchema = _namedSchemaSchema . toNamedSchema
197190--
198191-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
199192-- "{\"$ref\":\"#/definitions/Day\"}"
200−toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
193+toSchemaRef :: ToSchema a => proxy a -> Referenced Schema
201194toSchemaRef = undeclare . declareSchemaRef
202195
203196-- | Convert a type into a referenced schema if possible
@@ -207,7 +200,7 @@ toSchemaRef = undeclare . declareSchemaRef
207200-- Schema definitions are typically declared for every referenced schema.
208201-- If @'declareSchemaRef'@ returns a reference, a corresponding schema
209202-- will be declared (regardless of whether it is recusive or not).
210−declareSchemaRef :: ToSchema a => Proxy a -> Declare (Definitions Schema) (Referenced Schema)
203+declareSchemaRef :: ToSchema a => proxy a -> Declare (Definitions Schema) (Referenced Schema)
211204declareSchemaRef proxy = do
212205 case toNamedSchema proxy of
213206 NamedSchema (Just name) schema -> do
@@ -269,7 +262,7 @@ inlineAllSchemas = inlineSchemasWhen (const True)
269262--
270263-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
271264-- when inlining recursive schemas.
272−toInlinedSchema :: ToSchema a => Proxy a -> Schema
265+toInlinedSchema :: ToSchema a => proxy a -> Schema
273266toInlinedSchema proxy = inlineAllSchemas defs schema
274267 where
275268 (defs, schema) = runDeclare (declareSchema proxy) mempty
@@ -298,20 +291,20 @@ inlineNonRecursiveSchemas defs = inlineSchemasWhen nonRecursive defs
298291-- | Default schema for binary data (any sequence of octets).
299292binarySchema :: Schema
300293binarySchema = mempty
301− & type_ ?~ SwaggerString
294+ & type_ .~ SwaggerString
302295 & format ?~ "binary"
303296
304297-- | Default schema for binary data (base64 encoded).
305298byteSchema :: Schema
306299byteSchema = mempty
307− & type_ ?~ SwaggerString
300+ & type_ .~ SwaggerString
308301 & format ?~ "byte"
309302
310303-- | Default schema for password string.
311304-- @"password"@ format is used to hint UIs the input needs to be obscured.
312305passwordSchema :: Schema
313306passwordSchema = mempty
314− & type_ ?~ SwaggerString
307+ & type_ .~ SwaggerString
315308 & format ?~ "password"
316309
317310-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
@@ -337,12 +330,12 @@ sketchSchema = sketch . toJSON
337330 sketch js@(Bool _) = go js
338331 sketch js = go js & example ?~ js
339332
340− go Null = mempty & type_ ?~ SwaggerNull
341− go (Bool _) = mempty & type_ ?~ SwaggerBoolean
342− go (String _) = mempty & type_ ?~ SwaggerString
343− go (Number _) = mempty & type_ ?~ SwaggerNumber
333+ go Null = mempty & type_ .~ SwaggerNull
334+ go (Bool _) = mempty & type_ .~ SwaggerBoolean
335+ go (String _) = mempty & type_ .~ SwaggerString
336+ go (Number _) = mempty & type_ .~ SwaggerNumber
344337 go (Array xs) = mempty
345− & type_ ?~ SwaggerArray
338+ & type_ .~ SwaggerArray
346339 & items ?~ case ischema of
347340 Just s -> SwaggerItemsObject (Inline s)
348341 _ -> SwaggerItemsArray (map Inline ys)
@@ -354,7 +347,7 @@ sketchSchema = sketch . toJSON
354347 (z:_) | allSame -> Just z
355348 _ -> Nothing
356349 go (Object o) = mempty
357− & type_ ?~ SwaggerObject
350+ & type_ .~ SwaggerObject
358351 & required .~ HashMap.keys o
359352 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
360353
@@ -377,24 +370,24 @@ sketchSchema = sketch . toJSON
377370sketchStrictSchema :: ToJSON a => a -> Schema
378371sketchStrictSchema = go . toJSON
379372 where
380− go Null = mempty & type_ ?~ SwaggerNull
373+ go Null = mempty & type_ .~ SwaggerNull
381374 go js@(Bool _) = mempty
382− & type_ ?~ SwaggerBoolean
375+ & type_ .~ SwaggerBoolean
383376 & enum_ ?~ [js]
384377 go js@(String s) = mempty
385− & type_ ?~ SwaggerString
378+ & type_ .~ SwaggerString
386379 & maxLength ?~ fromIntegral (T.length s)
387380 & minLength ?~ fromIntegral (T.length s)
388381 & pattern ?~ s
389382 & enum_ ?~ [js]
390383 go js@(Number n) = mempty
391− & type_ ?~ SwaggerNumber
384+ & type_ .~ SwaggerNumber
392385 & maximum_ ?~ n
393386 & minimum_ ?~ n
394387 & multipleOf ?~ n
395388 & enum_ ?~ [js]
396389 go js@(Array xs) = mempty
397− & type_ ?~ SwaggerArray
390+ & type_ .~ SwaggerArray
398391 & maxItems ?~ fromIntegral sz
399392 & minItems ?~ fromIntegral sz
400393 & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
@@ -404,7 +397,7 @@ sketchStrictSchema = go . toJSON
404397 sz = length xs
405398 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
406399 go js@(Object o) = mempty
407− & type_ ?~ SwaggerObject
400+ & type_ .~ SwaggerObject
408401 & required .~ names
409402 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
410403 & maxProperties ?~ fromIntegral (length names)
@@ -414,19 +407,18 @@ sketchStrictSchema = go . toJSON
414407 names = HashMap.keys o
415408
416409class GToSchema (f :: * -> *) where
417− gdeclareNamedSchema :: SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
410+ gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
418411
419412instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
420413 declareNamedSchema _ = do
421414 ref <- declareSchemaRef (Proxy :: Proxy a)
422415 return $ unnamed $ mempty
423− & type_ ?~ SwaggerArray
416+ & type_ .~ SwaggerArray
424417 & items ?~ SwaggerItemsObject ref
425418
426419instance OVERLAPPING_ ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
427420instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
428421instance ToSchema Integer where declareNamedSchema = plain . paramSchemaToSchema
429−instance ToSchema Natural where declareNamedSchema = plain . paramSchemaToSchema
430422instance ToSchema Int where declareNamedSchema = plain . paramSchemaToSchema
431423instance ToSchema Int8 where declareNamedSchema = plain . paramSchemaToSchema
432424instance ToSchema Int16 where declareNamedSchema = plain . paramSchemaToSchema
@@ -470,7 +462,7 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f
470462
471463timeSchema :: T.Text -> Schema
472464timeSchema fmt = mempty
473− & type_ ?~ SwaggerString
465+ & type_ .~ SwaggerString
474466 & format ?~ fmt
475467
476468-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -503,8 +495,6 @@ instance ToSchema UTCTime where
503495instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
504496instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
505497
506−instance ToSchema Version where declareNamedSchema = plain . paramSchemaToSchema
507−
508498#if __GLASGOW_HASKELL__ < 800
509499#else
510500type family ToSchemaByteStringError bs where
@@ -532,8 +522,8 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
532522 declareObjectMapSchema = do
533523 schema <- declareSchemaRef (Proxy :: Proxy v)
534524 return $ unnamed $ mempty
535− & type_ ?~ SwaggerObject
536− & additionalProperties ?~ AdditionalPropertiesSchema schema
525+ & type_ .~ SwaggerObject
526+ & additionalProperties ?~ schema
537527
538528instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
539529 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
@@ -544,7 +534,7 @@ instance ToSchema a => ToSchema (Map String a) where
544534 declareNamedSchema _ = do
545535 schema <- declareSchemaRef (Proxy :: Proxy a)
546536 return $ unnamed $ mempty
547− & type_ ?~ SwaggerObject
537+ & type_ .~ SwaggerObject
548538 & additionalProperties ?~ schema
549539
550540instance ToSchema a => ToSchema (Map T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
@@ -556,12 +546,6 @@ instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ =
556546
557547#endif
558548
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
564−
565549instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
566550instance ToSchema a => ToSchema (VU.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
567551instance ToSchema a => ToSchema (VS.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
@@ -575,13 +559,6 @@ instance ToSchema a => ToSchema (Set a) where
575559
576560instance ToSchema a => ToSchema (HashSet a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set a))
577561
578−-- | @since 2.2.1
579−instance ToSchema a => ToSchema (NonEmpty a) where
580− declareNamedSchema _ = do
581− schema <- declareSchema (Proxy :: Proxy [a])
582− return $ unnamed $ schema
583− & minItems .~ Just 1
584−
585562instance ToSchema All where declareNamedSchema = plain . paramSchemaToSchema
586563instance ToSchema Any where declareNamedSchema = plain . paramSchemaToSchema
587564
@@ -597,135 +574,74 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
597574--
598575-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
599576-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
600−toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
577+toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
601578toSchemaBoundedIntegral _ = mempty
602− & type_ ?~ SwaggerInteger
579+ & type_ .~ SwaggerInteger
603580 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
604581 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
605582
606583-- | Default generic named schema for @'Bounded'@, @'Integral'@ types.
607−genericToNamedSchemaBoundedIntegral :: forall a d f.
584+genericToNamedSchemaBoundedIntegral :: forall a d f proxy.
608585 ( Bounded a, Integral a
609586 , Generic a, Rep a ~ D1 d f, Datatype d)
610− => SchemaOptions -> Proxy a -> NamedSchema
587+ => SchemaOptions -> proxy a -> NamedSchema
611588genericToNamedSchemaBoundedIntegral opts proxy
612− = genericNameSchema opts proxy (toSchemaBoundedIntegral proxy)
613−
614−-- | Declare a named schema for a @newtype@ wrapper.
615−genericDeclareNamedSchemaNewtype :: forall a d c s i inner.
616− (Generic a, Datatype d, Rep a ~ D1 d (C1 c (S1 s (K1 i inner))))
617− => SchemaOptions -- ^ How to derive the name.
618− -> (Proxy inner -> Declare (Definitions Schema) Schema) -- ^ How to create a schema for the wrapped type.
619− -> Proxy a
620− -> Declare (Definitions Schema) NamedSchema
621−genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$> f (Proxy :: Proxy inner)
622−
623−-- | Declare 'Schema' for a mapping with 'Bounded' 'Enum' keys.
624−-- This makes a much more useful schema when there aren't many options for key values.
625−--
626−-- >>> data ButtonState = Neutral | Focus | Active | Hover | Disabled deriving (Show, Bounded, Enum, Generic)
627−-- >>> instance ToJSON ButtonState
628−-- >>> instance ToSchema ButtonState
629−-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
630−-- >>> type ImageUrl = T.Text
631−-- >>> encode $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
632−-- "{\"properties\":{\"Neutral\":{\"type\":\"string\"},\"Focus\":{\"type\":\"string\"},\"Active\":{\"type\":\"string\"},\"Hover\":{\"type\":\"string\"},\"Disabled\":{\"type\":\"string\"}},\"type\":\"object\"}"
633−--
634−-- 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.
636−declareSchemaBoundedEnumKeyMapping :: forall map key value.
637− (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
638− => Proxy (map key value) -> Declare (Definitions Schema) Schema
639−declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key of
640− ToJSONKeyText keyToText _ -> objectSchema keyToText
641− ToJSONKeyValue _ _ -> declareSchema (Proxy :: Proxy [(key, value)])
642− where
643− objectSchema keyToText = do
644− valueRef <- declareSchemaRef (Proxy :: Proxy value)
645− let allKeys = [minBound..maxBound :: key]
646− mkPair k = (keyToText k, valueRef)
647− return $ mempty
648− & type_ ?~ SwaggerObject
649− & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
650−
651−-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
652−-- This makes a much more useful schema when there aren't many options for key values.
653−--
654−-- >>> data ButtonState = Neutral | Focus | Active | Hover | Disabled deriving (Show, Bounded, Enum, Generic)
655−-- >>> instance ToJSON ButtonState
656−-- >>> instance ToSchema ButtonState
657−-- >>> instance ToJSONKey ButtonState where toJSONKey = toJSONKeyText (T.pack . show)
658−-- >>> type ImageUrl = T.Text
659−-- >>> encode $ toSchemaBoundedEnumKeyMapping (Proxy :: Proxy (Map ButtonState ImageUrl))
660−-- "{\"properties\":{\"Neutral\":{\"type\":\"string\"},\"Focus\":{\"type\":\"string\"},\"Active\":{\"type\":\"string\"},\"Hover\":{\"type\":\"string\"},\"Disabled\":{\"type\":\"string\"}},\"type\":\"object\"}"
661−--
662−-- 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.
664−toSchemaBoundedEnumKeyMapping :: forall map key value.
665− (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
666− => Proxy (map key value) -> Schema
667−toSchemaBoundedEnumKeyMapping = flip evalDeclare mempty . declareSchemaBoundedEnumKeyMapping
589+ = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d)) (toSchemaBoundedIntegral proxy)
668590
669591-- | A configurable generic @'Schema'@ creator.
670592genericDeclareSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareSchemaUnrestricted") =>
671− SchemaOptions -> Proxy a -> Declare (Definitions Schema) Schema
593+ SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
672594genericDeclareSchema = genericDeclareSchemaUnrestricted
673595
674596-- | A configurable generic @'NamedSchema'@ creator.
675597-- This function applied to @'defaultSchemaOptions'@
676598-- is used as the default for @'declareNamedSchema'@
677599-- when the type is an instance of @'Generic'@.
678−genericDeclareNamedSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
679− SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
600+genericDeclareNamedSchema :: forall a proxy. (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
601+ SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
680602genericDeclareNamedSchema = genericDeclareNamedSchemaUnrestricted
681603
682604-- | A configurable generic @'Schema'@ creator.
683605--
684606-- Unlike 'genericDeclareSchema' also works for mixed sum types.
685607-- 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
608+genericDeclareSchemaUnrestricted :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
687609genericDeclareSchemaUnrestricted opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchemaUnrestricted opts proxy
688610
689611-- | A configurable generic @'NamedSchema'@ creator.
690612--
691613-- Unlike 'genericDeclareNamedSchema' also works for mixed sum types.
692614-- 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)) =>
694− SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
615+genericDeclareNamedSchemaUnrestricted :: forall a proxy. (Generic a, GToSchema (Rep a)) =>
616+ SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
695617genericDeclareNamedSchemaUnrestricted opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
696618
697−-- | Derive a 'Generic'-based name for a datatype and assign it to a given 'Schema'.
698−genericNameSchema :: forall a d f.
699− (Generic a, Rep a ~ D1 d f, Datatype d)
700− => SchemaOptions -> Proxy a -> Schema -> NamedSchema
701−genericNameSchema opts _ = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d))
702−
703−gdatatypeSchemaName :: forall d. Datatype d => SchemaOptions -> Proxy d -> Maybe T.Text
704−gdatatypeSchemaName opts _ = case orig of
619+gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe T.Text
620+gdatatypeSchemaName opts _ = case name of
705621 (c:_) | isAlpha c && isUpper c -> Just (T.pack name)
706622 _ -> Nothing
707623 where
708− orig = datatypeName (Proxy3 :: Proxy3 d f a)
709− name = datatypeNameModifier opts orig
624+ name = datatypeNameModifier opts (datatypeName (Proxy3 :: Proxy3 d f a))
710625
711626-- | Lift a plain @'ParamSchema'@ into a model @'NamedSchema'@.
712−paramSchemaToNamedSchema :: (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d) =>
713− SchemaOptions -> Proxy a -> NamedSchema
714−paramSchemaToNamedSchema opts proxy = genericNameSchema opts proxy (paramSchemaToSchema proxy)
627+paramSchemaToNamedSchema :: forall a d f proxy.
628+ (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d)
629+ => SchemaOptions -> proxy a -> NamedSchema
630+paramSchemaToNamedSchema opts proxy = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d)) (paramSchemaToSchema proxy)
715631
716632-- | Lift a plain @'ParamSchema'@ into a model @'Schema'@.
717−paramSchemaToSchema :: ToParamSchema a => Proxy a -> Schema
718−paramSchemaToSchema proxy = mempty & paramSchema .~ toParamSchema proxy
633+paramSchemaToSchema :: forall a proxy. ToParamSchema a => proxy a -> Schema
634+paramSchemaToSchema _ = mempty & paramSchema .~ toParamSchema (Proxy :: Proxy a)
719635
720636nullarySchema :: Schema
721637nullarySchema = mempty
722− & type_ ?~ SwaggerArray
638+ & type_ .~ SwaggerArray
723639 & items ?~ SwaggerItemsArray []
724640
725−gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
641+gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
726642gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
727643
728−gdeclareSchema :: GToSchema f => SchemaOptions -> Proxy f -> Declare (Definitions Schema) Schema
644+gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare (Definitions Schema) Schema
729645gdeclareSchema opts proxy = _namedSchemaSchema <$> gdeclareNamedSchema opts proxy mempty
730646
731647instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
@@ -745,7 +661,7 @@ instance OVERLAPPING_ Constructor c => GToSchema (C1 c U1) where
745661 gdeclareNamedSchema = gdeclareNamedSumSchema
746662
747663-- | Single field constructor.
748−instance (Selector s, GToSchema f, GToSchema (S1 s f)) => GToSchema (C1 c (S1 s f)) where
664+instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
749665 gdeclareNamedSchema opts _ s
750666 | unwrapUnaryRecords opts = fieldSchema
751667 | otherwise =
@@ -759,7 +675,7 @@ instance (Selector s, GToSchema f, GToSchema (S1 s f)) => GToSchema (C1 c (S1 s
759675 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
760676 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
761677
762−gdeclareSchemaRef :: GToSchema a => SchemaOptions -> Proxy a -> Declare (Definitions Schema) (Referenced Schema)
678+gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare (Definitions Schema) (Referenced Schema)
763679gdeclareSchemaRef opts proxy = do
764680 case gtoNamedSchema opts proxy of
765681 NamedSchema (Just name) schema -> do
@@ -790,12 +706,12 @@ withFieldSchema opts _ isRequiredField schema = do
790706 return $
791707 if T.null fname
792708 then schema
793− & type_ ?~ SwaggerArray
709+ & type_ .~ SwaggerArray
794710 & items %~ appendItem ref
795711 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
796712 & minItems %~ Just . maybe 1 (+1) -- increment minItems
797713 else schema
798− & type_ ?~ SwaggerObject
714+ & type_ .~ SwaggerObject
799715 & properties . at fname ?~ ref
800716 & if isRequiredField
801717 then required %~ (++ [fname])
@@ -823,7 +739,7 @@ instance ( GSumToSchema f
823739 where
824740 gdeclareNamedSchema = gdeclareNamedSumSchema
825741
826−gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
742+gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
827743gdeclareNamedSumSchema opts proxy s
828744 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
829745 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
@@ -832,29 +748,29 @@ gdeclareNamedSumSchema opts proxy s
832748 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
833749
834750 toStringTag schema = mempty
835− & type_ ?~ SwaggerString
751+ & type_ .~ SwaggerString
836752 & enum_ ?~ map toJSON (schema ^.. properties.ifolded.asIndex)
837753
838754type AllNullary = All
839755
840756class GSumToSchema (f :: * -> *) where
841− gsumToSchema :: SchemaOptions -> Proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
757+ gsumToSchema :: SchemaOptions -> proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
842758
843759instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
844760 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) >=> gsumToSchema opts (Proxy :: Proxy g)
845761
846−gsumConToSchemaWith :: forall c f. (GToSchema (C1 c f), Constructor c) =>
847− Referenced Schema -> SchemaOptions -> Proxy (C1 c f) -> Schema -> Schema
762+gsumConToSchemaWith :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
763+ Referenced Schema -> SchemaOptions -> proxy (C1 c f) -> Schema -> Schema
848764gsumConToSchemaWith ref opts _ schema = schema
849− & type_ ?~ SwaggerObject
765+ & type_ .~ SwaggerObject
850766 & properties . at tag ?~ ref
851767 & maxProperties ?~ 1
852768 & minProperties ?~ 1
853769 where
854770 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
855771
856−gsumConToSchema :: (GToSchema (C1 c f), Constructor c) =>
857− SchemaOptions -> Proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
772+gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
773+ SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
858774gsumConToSchema opts proxy schema = do
859775 ref <- gdeclareSchemaRef opts proxy
860776 return $ gsumConToSchemaWith ref opts proxy schema
@@ -878,5 +794,3 @@ data Proxy3 a b c = Proxy3
878794
879795-- $setup
880796-- >>> import Data.Swagger
881−-- >>> import Data.Aeson (encode)
882−-- >>> import Data.Aeson.Types (toJSONKeyText)