@@ -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 (..))
35+import Data.Aeson (ToJSON (..), ToJSONKey (..), ToJSONKeyFunction (..), Value (..), Object(..))
3636import Data.Char
3737import Data.Data (Data)
3838import Data.Foldable (traverse_)
@@ -44,6 +44,7 @@ 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)
4748import Data.Map (Map)
4849import Data.Proxy
4950import Data.Scientific (Scientific)
@@ -56,7 +57,8 @@ import qualified Data.Vector as V
5657import qualified Data.Vector.Primitive as VP
5758import qualified Data.Vector.Storable as VS
5859import qualified Data.Vector.Unboxed as VU
59−import Numeric.Natural
60+import Data.Version (Version)
61+import Numeric.Natural.Compat (Natural)
6062import Data.Word
6163import GHC.Generics
6264import qualified Data.UUID.Types as UUID
@@ -109,7 +111,7 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
109111-- declareNamedSchema _ = do
110112-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
111113-- return $ NamedSchema (Just \"Coord\") $ mempty
112−-- & type_ .~ SwaggerObject
114+-- & type_ ?~ SwaggerObject
113115-- & properties .~
114116-- [ (\"x\", doubleSchema)
115117-- , (\"y\", doubleSchema)
@@ -140,13 +142,17 @@ class ToSchema a where
140142 -- together with all used definitions.
141143 -- Note that the schema itself is included in definitions
142144 -- only if it is recursive (and thus needs its definition in scope).
143− declareNamedSchema :: proxy a -> Declare (Definitions Schema) NamedSchema
145+ declareNamedSchema :: Proxy a -> Declare (Definitions Schema) NamedSchema
144146 default declareNamedSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
145− proxy a -> Declare (Definitions Schema) NamedSchema
147+ Proxy a -> Declare (Definitions Schema) NamedSchema
146148 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
147149
150+instance ToSchema TimeOfDay where
151+ declareNamedSchema _ = pure $ named "TimeOfDay" $ timeSchema "hh:MM:ss"
152+ & example ?~ toJSON (TimeOfDay 12 33 15)
153+
148154-- | Convert a type into a schema and declare all used schema definitions.
149−declareSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) Schema
155+declareSchema :: ToSchema a => Proxy a -> Declare (Definitions Schema) Schema
150156declareSchema = fmap _namedSchemaSchema . declareNamedSchema
151157
152158-- | Convert a type into an optionally named schema.
@@ -160,7 +166,7 @@ declareSchema = fmap _namedSchemaSchema . declareNamedSchema
160166-- Just "Day"
161167-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
162168-- "{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}"
163−toNamedSchema :: ToSchema a => proxy a -> NamedSchema
169+toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
164170toNamedSchema = undeclare . declareNamedSchema
165171
166172-- | Get type's schema name according to its @'ToSchema'@ instance.
@@ -170,7 +176,7 @@ toNamedSchema = undeclare . declareNamedSchema
170176--
171177-- >>> schemaName (Proxy :: Proxy UTCTime)
172178-- Just "UTCTime"
173−schemaName :: ToSchema a => proxy a -> Maybe T.Text
179+schemaName :: ToSchema a => Proxy a -> Maybe T.Text
174180schemaName = _namedSchemaName . toNamedSchema
175181
176182-- | Convert a type into a schema.
@@ -180,7 +186,7 @@ schemaName = _namedSchemaName . toNamedSchema
180186--
181187-- >>> encode $ toSchema (Proxy :: Proxy [Day])
182188-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
183−toSchema :: ToSchema a => proxy a -> Schema
189+toSchema :: ToSchema a => Proxy a -> Schema
184190toSchema = _namedSchemaSchema . toNamedSchema
185191
186192-- | Convert a type into a referenced schema if possible.
@@ -191,7 +197,7 @@ toSchema = _namedSchemaSchema . toNamedSchema
191197--
192198-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
193199-- "{\"$ref\":\"#/definitions/Day\"}"
194−toSchemaRef :: ToSchema a => proxy a -> Referenced Schema
200+toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
195201toSchemaRef = undeclare . declareSchemaRef
196202
197203-- | Convert a type into a referenced schema if possible
@@ -201,7 +207,7 @@ toSchemaRef = undeclare . declareSchemaRef
201207-- Schema definitions are typically declared for every referenced schema.
202208-- If @'declareSchemaRef'@ returns a reference, a corresponding schema
203209-- will be declared (regardless of whether it is recusive or not).
204−declareSchemaRef :: ToSchema a => proxy a -> Declare (Definitions Schema) (Referenced Schema)
210+declareSchemaRef :: ToSchema a => Proxy a -> Declare (Definitions Schema) (Referenced Schema)
205211declareSchemaRef proxy = do
206212 case toNamedSchema proxy of
207213 NamedSchema (Just name) schema -> do
@@ -263,7 +269,7 @@ inlineAllSchemas = inlineSchemasWhen (const True)
263269--
264270-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
265271-- when inlining recursive schemas.
266−toInlinedSchema :: ToSchema a => proxy a -> Schema
272+toInlinedSchema :: ToSchema a => Proxy a -> Schema
267273toInlinedSchema proxy = inlineAllSchemas defs schema
268274 where
269275 (defs, schema) = runDeclare (declareSchema proxy) mempty
@@ -292,20 +298,20 @@ inlineNonRecursiveSchemas defs = inlineSchemasWhen nonRecursive defs
292298-- | Default schema for binary data (any sequence of octets).
293299binarySchema :: Schema
294300binarySchema = mempty
295− & type_ .~ SwaggerString
301+ & type_ ?~ SwaggerString
296302 & format ?~ "binary"
297303
298304-- | Default schema for binary data (base64 encoded).
299305byteSchema :: Schema
300306byteSchema = mempty
301− & type_ .~ SwaggerString
307+ & type_ ?~ SwaggerString
302308 & format ?~ "byte"
303309
304310-- | Default schema for password string.
305311-- @"password"@ format is used to hint UIs the input needs to be obscured.
306312passwordSchema :: Schema
307313passwordSchema = mempty
308− & type_ .~ SwaggerString
314+ & type_ ?~ SwaggerString
309315 & format ?~ "password"
310316
311317-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
@@ -331,12 +337,12 @@ sketchSchema = sketch . toJSON
331337 sketch js@(Bool _) = go js
332338 sketch js = go js & example ?~ js
333339
334− go Null = mempty & type_ .~ SwaggerNull
335− go (Bool _) = mempty & type_ .~ SwaggerBoolean
336− go (String _) = mempty & type_ .~ SwaggerString
337− go (Number _) = mempty & type_ .~ SwaggerNumber
340+ go Null = mempty & type_ ?~ SwaggerNull
341+ go (Bool _) = mempty & type_ ?~ SwaggerBoolean
342+ go (String _) = mempty & type_ ?~ SwaggerString
343+ go (Number _) = mempty & type_ ?~ SwaggerNumber
338344 go (Array xs) = mempty
339− & type_ .~ SwaggerArray
345+ & type_ ?~ SwaggerArray
340346 & items ?~ case ischema of
341347 Just s -> SwaggerItemsObject (Inline s)
342348 _ -> SwaggerItemsArray (map Inline ys)
@@ -348,7 +354,7 @@ sketchSchema = sketch . toJSON
348354 (z:_) | allSame -> Just z
349355 _ -> Nothing
350356 go (Object o) = mempty
351− & type_ .~ SwaggerObject
357+ & type_ ?~ SwaggerObject
352358 & required .~ HashMap.keys o
353359 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
354360
@@ -371,24 +377,24 @@ sketchSchema = sketch . toJSON
371377sketchStrictSchema :: ToJSON a => a -> Schema
372378sketchStrictSchema = go . toJSON
373379 where
374− go Null = mempty & type_ .~ SwaggerNull
380+ go Null = mempty & type_ ?~ SwaggerNull
375381 go js@(Bool _) = mempty
376− & type_ .~ SwaggerBoolean
382+ & type_ ?~ SwaggerBoolean
377383 & enum_ ?~ [js]
378384 go js@(String s) = mempty
379− & type_ .~ SwaggerString
385+ & type_ ?~ SwaggerString
380386 & maxLength ?~ fromIntegral (T.length s)
381387 & minLength ?~ fromIntegral (T.length s)
382388 & pattern ?~ s
383389 & enum_ ?~ [js]
384390 go js@(Number n) = mempty
385− & type_ .~ SwaggerNumber
391+ & type_ ?~ SwaggerNumber
386392 & maximum_ ?~ n
387393 & minimum_ ?~ n
388394 & multipleOf ?~ n
389395 & enum_ ?~ [js]
390396 go js@(Array xs) = mempty
391− & type_ .~ SwaggerArray
397+ & type_ ?~ SwaggerArray
392398 & maxItems ?~ fromIntegral sz
393399 & minItems ?~ fromIntegral sz
394400 & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
@@ -398,7 +404,7 @@ sketchStrictSchema = go . toJSON
398404 sz = length xs
399405 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
400406 go js@(Object o) = mempty
401− & type_ .~ SwaggerObject
407+ & type_ ?~ SwaggerObject
402408 & required .~ names
403409 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
404410 & maxProperties ?~ fromIntegral (length names)
@@ -408,13 +414,13 @@ sketchStrictSchema = go . toJSON
408414 names = HashMap.keys o
409415
410416class GToSchema (f :: * -> *) where
411− gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
417+ gdeclareNamedSchema :: SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
412418
413419instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
414420 declareNamedSchema _ = do
415421 ref <- declareSchemaRef (Proxy :: Proxy a)
416422 return $ unnamed $ mempty
417− & type_ .~ SwaggerArray
423+ & type_ ?~ SwaggerArray
418424 & items ?~ SwaggerItemsObject ref
419425
420426instance OVERLAPPING_ ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
@@ -464,7 +470,7 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f
464470
465471timeSchema :: T.Text -> Schema
466472timeSchema fmt = mempty
467− & type_ .~ SwaggerString
473+ & type_ ?~ SwaggerString
468474 & format ?~ fmt
469475
470476-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -497,6 +503,8 @@ instance ToSchema UTCTime where
497503instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
498504instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
499505
506+instance ToSchema Version where declareNamedSchema = plain . paramSchemaToSchema
507+
500508#if __GLASGOW_HASKELL__ < 800
501509#else
502510type family ToSchemaByteStringError bs where
@@ -524,8 +532,8 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
524532 declareObjectMapSchema = do
525533 schema <- declareSchemaRef (Proxy :: Proxy v)
526534 return $ unnamed $ mempty
527− & type_ .~ SwaggerObject
528− & additionalProperties ?~ schema
535+ & type_ ?~ SwaggerObject
536+ & additionalProperties ?~ AdditionalPropertiesSchema schema
529537
530538instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
531539 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
@@ -536,7 +544,7 @@ instance ToSchema a => ToSchema (Map String a) where
536544 declareNamedSchema _ = do
537545 schema <- declareSchemaRef (Proxy :: Proxy a)
538546 return $ unnamed $ mempty
539− & type_ .~ SwaggerObject
547+ & type_ ?~ SwaggerObject
540548 & additionalProperties ?~ schema
541549
542550instance ToSchema a => ToSchema (Map T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
@@ -548,6 +556,12 @@ instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ =
548556
549557#endif
550558
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+
551565instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
552566instance ToSchema a => ToSchema (VU.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
553567instance ToSchema a => ToSchema (VS.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
@@ -561,6 +575,13 @@ instance ToSchema a => ToSchema (Set a) where
561575
562576instance ToSchema a => ToSchema (HashSet a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set a))
563577
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+
564585instance ToSchema All where declareNamedSchema = plain . paramSchemaToSchema
565586instance ToSchema Any where declareNamedSchema = plain . paramSchemaToSchema
566587
@@ -576,26 +597,26 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
576597--
577598-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
578599-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
579−toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
600+toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
580601toSchemaBoundedIntegral _ = mempty
581− & type_ .~ SwaggerInteger
602+ & type_ ?~ SwaggerInteger
582603 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
583604 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
584605
585606-- | Default generic named schema for @'Bounded'@, @'Integral'@ types.
586−genericToNamedSchemaBoundedIntegral :: forall a d f proxy.
607+genericToNamedSchemaBoundedIntegral :: forall a d f.
587608 ( Bounded a, Integral a
588609 , Generic a, Rep a ~ D1 d f, Datatype d)
589− => SchemaOptions -> proxy a -> NamedSchema
610+ => SchemaOptions -> Proxy a -> NamedSchema
590611genericToNamedSchemaBoundedIntegral opts proxy
591612 = genericNameSchema opts proxy (toSchemaBoundedIntegral proxy)
592613
593614-- | Declare a named schema for a @newtype@ wrapper.
594−genericDeclareNamedSchemaNewtype :: forall proxy a d c s i inner.
615+genericDeclareNamedSchemaNewtype :: forall a d c s i inner.
595616 (Generic a, Datatype d, Rep a ~ D1 d (C1 c (S1 s (K1 i inner))))
596617 => SchemaOptions -- ^ How to derive the name.
597618 -> (Proxy inner -> Declare (Definitions Schema) Schema) -- ^ How to create a schema for the wrapped type.
598− -> proxy a
619+ -> Proxy a
599620 -> Declare (Definitions Schema) NamedSchema
600621genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$> f (Proxy :: Proxy inner)
601622
@@ -612,9 +633,9 @@ genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$>
612633--
613634-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
614635-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
615−declareSchemaBoundedEnumKeyMapping :: forall map key value proxy.
636+declareSchemaBoundedEnumKeyMapping :: forall map key value.
616637 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
617− => proxy (map key value) -> Declare (Definitions Schema) Schema
638+ => Proxy (map key value) -> Declare (Definitions Schema) Schema
618639declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key of
619640 ToJSONKeyText keyToText _ -> objectSchema keyToText
620641 ToJSONKeyValue _ _ -> declareSchema (Proxy :: Proxy [(key, value)])
@@ -624,7 +645,7 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
624645 let allKeys = [minBound..maxBound :: key]
625646 mkPair k = (keyToText k, valueRef)
626647 return $ mempty
627− & type_ .~ SwaggerObject
648+ & type_ ?~ SwaggerObject
628649 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
629650
630651-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
@@ -640,46 +661,46 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
640661--
641662-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
642663-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
643−toSchemaBoundedEnumKeyMapping :: forall map key value proxy.
664+toSchemaBoundedEnumKeyMapping :: forall map key value.
644665 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
645− => proxy (map key value) -> Schema
666+ => Proxy (map key value) -> Schema
646667toSchemaBoundedEnumKeyMapping = flip evalDeclare mempty . declareSchemaBoundedEnumKeyMapping
647668
648669-- | A configurable generic @'Schema'@ creator.
649670genericDeclareSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareSchemaUnrestricted") =>
650− SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
671+ SchemaOptions -> Proxy a -> Declare (Definitions Schema) Schema
651672genericDeclareSchema = genericDeclareSchemaUnrestricted
652673
653674-- | A configurable generic @'NamedSchema'@ creator.
654675-- This function applied to @'defaultSchemaOptions'@
655676-- is used as the default for @'declareNamedSchema'@
656677-- when the type is an instance of @'Generic'@.
657−genericDeclareNamedSchema :: forall a proxy. (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
658− SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
678+genericDeclareNamedSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
679+ SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
659680genericDeclareNamedSchema = genericDeclareNamedSchemaUnrestricted
660681
661682-- | A configurable generic @'Schema'@ creator.
662683--
663684-- Unlike 'genericDeclareSchema' also works for mixed sum types.
664685-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
665−genericDeclareSchemaUnrestricted :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
686+genericDeclareSchemaUnrestricted :: (Generic a, GToSchema (Rep a)) => SchemaOptions -> Proxy a -> Declare (Definitions Schema) Schema
666687genericDeclareSchemaUnrestricted opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchemaUnrestricted opts proxy
667688
668689-- | A configurable generic @'NamedSchema'@ creator.
669690--
670691-- Unlike 'genericDeclareNamedSchema' also works for mixed sum types.
671692-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
672−genericDeclareNamedSchemaUnrestricted :: forall a proxy. (Generic a, GToSchema (Rep a)) =>
673− SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
693+genericDeclareNamedSchemaUnrestricted :: forall a. (Generic a, GToSchema (Rep a)) =>
694+ SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
674695genericDeclareNamedSchemaUnrestricted opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
675696
676697-- | Derive a 'Generic'-based name for a datatype and assign it to a given 'Schema'.
677−genericNameSchema :: forall a d f proxy.
698+genericNameSchema :: forall a d f.
678699 (Generic a, Rep a ~ D1 d f, Datatype d)
679− => SchemaOptions -> proxy a -> Schema -> NamedSchema
700+ => SchemaOptions -> Proxy a -> Schema -> NamedSchema
680701genericNameSchema opts _ = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d))
681702
682−gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe T.Text
703+gdatatypeSchemaName :: forall d. Datatype d => SchemaOptions -> Proxy d -> Maybe T.Text
683704gdatatypeSchemaName opts _ = case orig of
684705 (c:_) | isAlpha c && isUpper c -> Just (T.pack name)
685706 _ -> Nothing
@@ -688,24 +709,23 @@ gdatatypeSchemaName opts _ = case orig of
688709 name = datatypeNameModifier opts orig
689710
690711-- | Lift a plain @'ParamSchema'@ into a model @'NamedSchema'@.
691−paramSchemaToNamedSchema :: forall a d f proxy.
692− (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d)
693− => SchemaOptions -> proxy a -> NamedSchema
712+paramSchemaToNamedSchema :: (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d) =>
713+ SchemaOptions -> Proxy a -> NamedSchema
694714paramSchemaToNamedSchema opts proxy = genericNameSchema opts proxy (paramSchemaToSchema proxy)
695715
696716-- | Lift a plain @'ParamSchema'@ into a model @'Schema'@.
697−paramSchemaToSchema :: forall a proxy. ToParamSchema a => proxy a -> Schema
698−paramSchemaToSchema _ = mempty & paramSchema .~ toParamSchema (Proxy :: Proxy a)
717+paramSchemaToSchema :: ToParamSchema a => Proxy a -> Schema
718+paramSchemaToSchema proxy = mempty & paramSchema .~ toParamSchema proxy
699719
700720nullarySchema :: Schema
701721nullarySchema = mempty
702− & type_ .~ SwaggerArray
722+ & type_ ?~ SwaggerArray
703723 & items ?~ SwaggerItemsArray []
704724
705−gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
725+gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
706726gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
707727
708−gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare (Definitions Schema) Schema
728+gdeclareSchema :: GToSchema f => SchemaOptions -> Proxy f -> Declare (Definitions Schema) Schema
709729gdeclareSchema opts proxy = _namedSchemaSchema <$> gdeclareNamedSchema opts proxy mempty
710730
711731instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
@@ -739,7 +759,7 @@ instance (Selector s, GToSchema f, GToSchema (S1 s f)) => GToSchema (C1 c (S1 s
739759 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
740760 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
741761
742−gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare (Definitions Schema) (Referenced Schema)
762+gdeclareSchemaRef :: GToSchema a => SchemaOptions -> Proxy a -> Declare (Definitions Schema) (Referenced Schema)
743763gdeclareSchemaRef opts proxy = do
744764 case gtoNamedSchema opts proxy of
745765 NamedSchema (Just name) schema -> do
@@ -770,12 +790,12 @@ withFieldSchema opts _ isRequiredField schema = do
770790 return $
771791 if T.null fname
772792 then schema
773− & type_ .~ SwaggerArray
793+ & type_ ?~ SwaggerArray
774794 & items %~ appendItem ref
775795 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
776796 & minItems %~ Just . maybe 1 (+1) -- increment minItems
777797 else schema
778− & type_ .~ SwaggerObject
798+ & type_ ?~ SwaggerObject
779799 & properties . at fname ?~ ref
780800 & if isRequiredField
781801 then required %~ (++ [fname])
@@ -803,7 +823,7 @@ instance ( GSumToSchema f
803823 where
804824 gdeclareNamedSchema = gdeclareNamedSumSchema
805825
806−gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
826+gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
807827gdeclareNamedSumSchema opts proxy s
808828 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
809829 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
@@ -812,29 +832,29 @@ gdeclareNamedSumSchema opts proxy s
812832 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
813833
814834 toStringTag schema = mempty
815− & type_ .~ SwaggerString
835+ & type_ ?~ SwaggerString
816836 & enum_ ?~ map toJSON (schema ^.. properties.ifolded.asIndex)
817837
818838type AllNullary = All
819839
820840class GSumToSchema (f :: * -> *) where
821− gsumToSchema :: SchemaOptions -> proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
841+ gsumToSchema :: SchemaOptions -> Proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
822842
823843instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
824844 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) >=> gsumToSchema opts (Proxy :: Proxy g)
825845
826−gsumConToSchemaWith :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
827− Referenced Schema -> SchemaOptions -> proxy (C1 c f) -> Schema -> Schema
846+gsumConToSchemaWith :: forall c f. (GToSchema (C1 c f), Constructor c) =>
847+ Referenced Schema -> SchemaOptions -> Proxy (C1 c f) -> Schema -> Schema
828848gsumConToSchemaWith ref opts _ schema = schema
829− & type_ .~ SwaggerObject
849+ & type_ ?~ SwaggerObject
830850 & properties . at tag ?~ ref
831851 & maxProperties ?~ 1
832852 & minProperties ?~ 1
833853 where
834854 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
835855
836−gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
837− SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
856+gsumConToSchema :: (GToSchema (C1 c f), Constructor c) =>
857+ SchemaOptions -> Proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
838858gsumConToSchema opts proxy schema = do
839859 ref <- gdeclareSchemaRef opts proxy
840860 return $ gsumConToSchemaWith ref opts proxy schema