@@ -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,7 +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 (NonEmpty)
47+import Data.List.NonEmpty.Compat (NonEmpty)
4848import Data.Map (Map)
4949import Data.Proxy
5050import Data.Scientific (Scientific)
@@ -58,7 +58,7 @@ import qualified Data.Vector.Primitive as VP
5858import qualified Data.Vector.Storable as VS
5959import qualified Data.Vector.Unboxed as VU
6060import Data.Version (Version)
61−import Numeric.Natural
61+import Numeric.Natural.Compat (Natural)
6262import Data.Word
6363import GHC.Generics
6464import qualified Data.UUID.Types as UUID
@@ -111,7 +111,7 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
111111-- declareNamedSchema _ = do
112112-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
113113-- return $ NamedSchema (Just \"Coord\") $ mempty
114−-- & type_ .~ SwaggerObject
114+-- & type_ ?~ SwaggerObject
115115-- & properties .~
116116-- [ (\"x\", doubleSchema)
117117-- , (\"y\", doubleSchema)
@@ -142,13 +142,17 @@ class ToSchema a where
142142 -- together with all used definitions.
143143 -- Note that the schema itself is included in definitions
144144 -- only if it is recursive (and thus needs its definition in scope).
145− declareNamedSchema :: proxy a -> Declare (Definitions Schema) NamedSchema
145+ declareNamedSchema :: Proxy a -> Declare (Definitions Schema) NamedSchema
146146 default declareNamedSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
147− proxy a -> Declare (Definitions Schema) NamedSchema
147+ Proxy a -> Declare (Definitions Schema) NamedSchema
148148 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
149149
150+instance ToSchema TimeOfDay where
151+ declareNamedSchema _ = pure $ named "TimeOfDay" $ timeSchema "hh:MM:ss"
152+ & example ?~ toJSON (TimeOfDay 12 33 15)
153+
150154-- | Convert a type into a schema and declare all used schema definitions.
151−declareSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) Schema
155+declareSchema :: ToSchema a => Proxy a -> Declare (Definitions Schema) Schema
152156declareSchema = fmap _namedSchemaSchema . declareNamedSchema
153157
154158-- | Convert a type into an optionally named schema.
@@ -162,7 +166,7 @@ declareSchema = fmap _namedSchemaSchema . declareNamedSchema
162166-- Just "Day"
163167-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
164168-- "{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}"
165−toNamedSchema :: ToSchema a => proxy a -> NamedSchema
169+toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
166170toNamedSchema = undeclare . declareNamedSchema
167171
168172-- | Get type's schema name according to its @'ToSchema'@ instance.
@@ -172,7 +176,7 @@ toNamedSchema = undeclare . declareNamedSchema
172176--
173177-- >>> schemaName (Proxy :: Proxy UTCTime)
174178-- Just "UTCTime"
175−schemaName :: ToSchema a => proxy a -> Maybe T.Text
179+schemaName :: ToSchema a => Proxy a -> Maybe T.Text
176180schemaName = _namedSchemaName . toNamedSchema
177181
178182-- | Convert a type into a schema.
@@ -182,7 +186,7 @@ schemaName = _namedSchemaName . toNamedSchema
182186--
183187-- >>> encode $ toSchema (Proxy :: Proxy [Day])
184188-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
185−toSchema :: ToSchema a => proxy a -> Schema
189+toSchema :: ToSchema a => Proxy a -> Schema
186190toSchema = _namedSchemaSchema . toNamedSchema
187191
188192-- | Convert a type into a referenced schema if possible.
@@ -193,7 +197,7 @@ toSchema = _namedSchemaSchema . toNamedSchema
193197--
194198-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
195199-- "{\"$ref\":\"#/definitions/Day\"}"
196−toSchemaRef :: ToSchema a => proxy a -> Referenced Schema
200+toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
197201toSchemaRef = undeclare . declareSchemaRef
198202
199203-- | Convert a type into a referenced schema if possible
@@ -203,7 +207,7 @@ toSchemaRef = undeclare . declareSchemaRef
203207-- Schema definitions are typically declared for every referenced schema.
204208-- If @'declareSchemaRef'@ returns a reference, a corresponding schema
205209-- will be declared (regardless of whether it is recusive or not).
206−declareSchemaRef :: ToSchema a => proxy a -> Declare (Definitions Schema) (Referenced Schema)
210+declareSchemaRef :: ToSchema a => Proxy a -> Declare (Definitions Schema) (Referenced Schema)
207211declareSchemaRef proxy = do
208212 case toNamedSchema proxy of
209213 NamedSchema (Just name) schema -> do
@@ -265,7 +269,7 @@ inlineAllSchemas = inlineSchemasWhen (const True)
265269--
266270-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
267271-- when inlining recursive schemas.
268−toInlinedSchema :: ToSchema a => proxy a -> Schema
272+toInlinedSchema :: ToSchema a => Proxy a -> Schema
269273toInlinedSchema proxy = inlineAllSchemas defs schema
270274 where
271275 (defs, schema) = runDeclare (declareSchema proxy) mempty
@@ -294,20 +298,20 @@ inlineNonRecursiveSchemas defs = inlineSchemasWhen nonRecursive defs
294298-- | Default schema for binary data (any sequence of octets).
295299binarySchema :: Schema
296300binarySchema = mempty
297− & type_ .~ SwaggerString
301+ & type_ ?~ SwaggerString
298302 & format ?~ "binary"
299303
300304-- | Default schema for binary data (base64 encoded).
301305byteSchema :: Schema
302306byteSchema = mempty
303− & type_ .~ SwaggerString
307+ & type_ ?~ SwaggerString
304308 & format ?~ "byte"
305309
306310-- | Default schema for password string.
307311-- @"password"@ format is used to hint UIs the input needs to be obscured.
308312passwordSchema :: Schema
309313passwordSchema = mempty
310− & type_ .~ SwaggerString
314+ & type_ ?~ SwaggerString
311315 & format ?~ "password"
312316
313317-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
@@ -333,12 +337,12 @@ sketchSchema = sketch . toJSON
333337 sketch js@(Bool _) = go js
334338 sketch js = go js & example ?~ js
335339
336− go Null = mempty & type_ .~ SwaggerNull
337− go (Bool _) = mempty & type_ .~ SwaggerBoolean
338− go (String _) = mempty & type_ .~ SwaggerString
339− 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
340344 go (Array xs) = mempty
341− & type_ .~ SwaggerArray
345+ & type_ ?~ SwaggerArray
342346 & items ?~ case ischema of
343347 Just s -> SwaggerItemsObject (Inline s)
344348 _ -> SwaggerItemsArray (map Inline ys)
@@ -350,7 +354,7 @@ sketchSchema = sketch . toJSON
350354 (z:_) | allSame -> Just z
351355 _ -> Nothing
352356 go (Object o) = mempty
353− & type_ .~ SwaggerObject
357+ & type_ ?~ SwaggerObject
354358 & required .~ HashMap.keys o
355359 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
356360
@@ -373,24 +377,24 @@ sketchSchema = sketch . toJSON
373377sketchStrictSchema :: ToJSON a => a -> Schema
374378sketchStrictSchema = go . toJSON
375379 where
376− go Null = mempty & type_ .~ SwaggerNull
380+ go Null = mempty & type_ ?~ SwaggerNull
377381 go js@(Bool _) = mempty
378− & type_ .~ SwaggerBoolean
382+ & type_ ?~ SwaggerBoolean
379383 & enum_ ?~ [js]
380384 go js@(String s) = mempty
381− & type_ .~ SwaggerString
385+ & type_ ?~ SwaggerString
382386 & maxLength ?~ fromIntegral (T.length s)
383387 & minLength ?~ fromIntegral (T.length s)
384388 & pattern ?~ s
385389 & enum_ ?~ [js]
386390 go js@(Number n) = mempty
387− & type_ .~ SwaggerNumber
391+ & type_ ?~ SwaggerNumber
388392 & maximum_ ?~ n
389393 & minimum_ ?~ n
390394 & multipleOf ?~ n
391395 & enum_ ?~ [js]
392396 go js@(Array xs) = mempty
393− & type_ .~ SwaggerArray
397+ & type_ ?~ SwaggerArray
394398 & maxItems ?~ fromIntegral sz
395399 & minItems ?~ fromIntegral sz
396400 & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
@@ -400,7 +404,7 @@ sketchStrictSchema = go . toJSON
400404 sz = length xs
401405 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
402406 go js@(Object o) = mempty
403− & type_ .~ SwaggerObject
407+ & type_ ?~ SwaggerObject
404408 & required .~ names
405409 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
406410 & maxProperties ?~ fromIntegral (length names)
@@ -410,13 +414,13 @@ sketchStrictSchema = go . toJSON
410414 names = HashMap.keys o
411415
412416class GToSchema (f :: * -> *) where
413− gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
417+ gdeclareNamedSchema :: SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
414418
415419instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
416420 declareNamedSchema _ = do
417421 ref <- declareSchemaRef (Proxy :: Proxy a)
418422 return $ unnamed $ mempty
419− & type_ .~ SwaggerArray
423+ & type_ ?~ SwaggerArray
420424 & items ?~ SwaggerItemsObject ref
421425
422426instance OVERLAPPING_ ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
@@ -466,7 +470,7 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f
466470
467471timeSchema :: T.Text -> Schema
468472timeSchema fmt = mempty
469− & type_ .~ SwaggerString
473+ & type_ ?~ SwaggerString
470474 & format ?~ fmt
471475
472476-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -528,8 +532,8 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
528532 declareObjectMapSchema = do
529533 schema <- declareSchemaRef (Proxy :: Proxy v)
530534 return $ unnamed $ mempty
531− & type_ .~ SwaggerObject
532− & additionalProperties ?~ schema
535+ & type_ ?~ SwaggerObject
536+ & additionalProperties ?~ AdditionalPropertiesSchema schema
533537
534538instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
535539 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
@@ -540,7 +544,7 @@ instance ToSchema a => ToSchema (Map String a) where
540544 declareNamedSchema _ = do
541545 schema <- declareSchemaRef (Proxy :: Proxy a)
542546 return $ unnamed $ mempty
543− & type_ .~ SwaggerObject
547+ & type_ ?~ SwaggerObject
544548 & additionalProperties ?~ schema
545549
546550instance ToSchema a => ToSchema (Map T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
@@ -552,6 +556,12 @@ instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ =
552556
553557#endif
554558
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+
555565instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
556566instance ToSchema a => ToSchema (VU.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
557567instance ToSchema a => ToSchema (VS.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
@@ -587,26 +597,26 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
587597--
588598-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
589599-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
590−toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
600+toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
591601toSchemaBoundedIntegral _ = mempty
592− & type_ .~ SwaggerInteger
602+ & type_ ?~ SwaggerInteger
593603 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
594604 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
595605
596606-- | Default generic named schema for @'Bounded'@, @'Integral'@ types.
597−genericToNamedSchemaBoundedIntegral :: forall a d f proxy.
607+genericToNamedSchemaBoundedIntegral :: forall a d f.
598608 ( Bounded a, Integral a
599609 , Generic a, Rep a ~ D1 d f, Datatype d)
600− => SchemaOptions -> proxy a -> NamedSchema
610+ => SchemaOptions -> Proxy a -> NamedSchema
601611genericToNamedSchemaBoundedIntegral opts proxy
602612 = genericNameSchema opts proxy (toSchemaBoundedIntegral proxy)
603613
604614-- | Declare a named schema for a @newtype@ wrapper.
605−genericDeclareNamedSchemaNewtype :: forall proxy a d c s i inner.
615+genericDeclareNamedSchemaNewtype :: forall a d c s i inner.
606616 (Generic a, Datatype d, Rep a ~ D1 d (C1 c (S1 s (K1 i inner))))
607617 => SchemaOptions -- ^ How to derive the name.
608618 -> (Proxy inner -> Declare (Definitions Schema) Schema) -- ^ How to create a schema for the wrapped type.
609− -> proxy a
619+ -> Proxy a
610620 -> Declare (Definitions Schema) NamedSchema
611621genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$> f (Proxy :: Proxy inner)
612622
@@ -623,9 +633,9 @@ genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$>
623633--
624634-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
625635-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
626−declareSchemaBoundedEnumKeyMapping :: forall map key value proxy.
636+declareSchemaBoundedEnumKeyMapping :: forall map key value.
627637 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
628− => proxy (map key value) -> Declare (Definitions Schema) Schema
638+ => Proxy (map key value) -> Declare (Definitions Schema) Schema
629639declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key of
630640 ToJSONKeyText keyToText _ -> objectSchema keyToText
631641 ToJSONKeyValue _ _ -> declareSchema (Proxy :: Proxy [(key, value)])
@@ -635,7 +645,7 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
635645 let allKeys = [minBound..maxBound :: key]
636646 mkPair k = (keyToText k, valueRef)
637647 return $ mempty
638− & type_ .~ SwaggerObject
648+ & type_ ?~ SwaggerObject
639649 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
640650
641651-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
@@ -651,46 +661,46 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
651661--
652662-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
653663-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
654−toSchemaBoundedEnumKeyMapping :: forall map key value proxy.
664+toSchemaBoundedEnumKeyMapping :: forall map key value.
655665 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
656− => proxy (map key value) -> Schema
666+ => Proxy (map key value) -> Schema
657667toSchemaBoundedEnumKeyMapping = flip evalDeclare mempty . declareSchemaBoundedEnumKeyMapping
658668
659669-- | A configurable generic @'Schema'@ creator.
660670genericDeclareSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareSchemaUnrestricted") =>
661− SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
671+ SchemaOptions -> Proxy a -> Declare (Definitions Schema) Schema
662672genericDeclareSchema = genericDeclareSchemaUnrestricted
663673
664674-- | A configurable generic @'NamedSchema'@ creator.
665675-- This function applied to @'defaultSchemaOptions'@
666676-- is used as the default for @'declareNamedSchema'@
667677-- when the type is an instance of @'Generic'@.
668−genericDeclareNamedSchema :: forall a proxy. (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
669− 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
670680genericDeclareNamedSchema = genericDeclareNamedSchemaUnrestricted
671681
672682-- | A configurable generic @'Schema'@ creator.
673683--
674684-- Unlike 'genericDeclareSchema' also works for mixed sum types.
675685-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
676−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
677687genericDeclareSchemaUnrestricted opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchemaUnrestricted opts proxy
678688
679689-- | A configurable generic @'NamedSchema'@ creator.
680690--
681691-- Unlike 'genericDeclareNamedSchema' also works for mixed sum types.
682692-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
683−genericDeclareNamedSchemaUnrestricted :: forall a proxy. (Generic a, GToSchema (Rep a)) =>
684− SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
693+genericDeclareNamedSchemaUnrestricted :: forall a. (Generic a, GToSchema (Rep a)) =>
694+ SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
685695genericDeclareNamedSchemaUnrestricted opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
686696
687697-- | Derive a 'Generic'-based name for a datatype and assign it to a given 'Schema'.
688−genericNameSchema :: forall a d f proxy.
698+genericNameSchema :: forall a d f.
689699 (Generic a, Rep a ~ D1 d f, Datatype d)
690− => SchemaOptions -> proxy a -> Schema -> NamedSchema
700+ => SchemaOptions -> Proxy a -> Schema -> NamedSchema
691701genericNameSchema opts _ = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d))
692702
693−gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe T.Text
703+gdatatypeSchemaName :: forall d. Datatype d => SchemaOptions -> Proxy d -> Maybe T.Text
694704gdatatypeSchemaName opts _ = case orig of
695705 (c:_) | isAlpha c && isUpper c -> Just (T.pack name)
696706 _ -> Nothing
@@ -699,24 +709,23 @@ gdatatypeSchemaName opts _ = case orig of
699709 name = datatypeNameModifier opts orig
700710
701711-- | Lift a plain @'ParamSchema'@ into a model @'NamedSchema'@.
702−paramSchemaToNamedSchema :: forall a d f proxy.
703− (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d)
704− => SchemaOptions -> proxy a -> NamedSchema
712+paramSchemaToNamedSchema :: (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d) =>
713+ SchemaOptions -> Proxy a -> NamedSchema
705714paramSchemaToNamedSchema opts proxy = genericNameSchema opts proxy (paramSchemaToSchema proxy)
706715
707716-- | Lift a plain @'ParamSchema'@ into a model @'Schema'@.
708−paramSchemaToSchema :: forall a proxy. ToParamSchema a => proxy a -> Schema
709−paramSchemaToSchema _ = mempty & paramSchema .~ toParamSchema (Proxy :: Proxy a)
717+paramSchemaToSchema :: ToParamSchema a => Proxy a -> Schema
718+paramSchemaToSchema proxy = mempty & paramSchema .~ toParamSchema proxy
710719
711720nullarySchema :: Schema
712721nullarySchema = mempty
713− & type_ .~ SwaggerArray
722+ & type_ ?~ SwaggerArray
714723 & items ?~ SwaggerItemsArray []
715724
716−gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
725+gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
717726gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
718727
719−gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare (Definitions Schema) Schema
728+gdeclareSchema :: GToSchema f => SchemaOptions -> Proxy f -> Declare (Definitions Schema) Schema
720729gdeclareSchema opts proxy = _namedSchemaSchema <$> gdeclareNamedSchema opts proxy mempty
721730
722731instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
@@ -750,7 +759,7 @@ instance (Selector s, GToSchema f, GToSchema (S1 s f)) => GToSchema (C1 c (S1 s
750759 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
751760 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
752761
753−gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare (Definitions Schema) (Referenced Schema)
762+gdeclareSchemaRef :: GToSchema a => SchemaOptions -> Proxy a -> Declare (Definitions Schema) (Referenced Schema)
754763gdeclareSchemaRef opts proxy = do
755764 case gtoNamedSchema opts proxy of
756765 NamedSchema (Just name) schema -> do
@@ -781,12 +790,12 @@ withFieldSchema opts _ isRequiredField schema = do
781790 return $
782791 if T.null fname
783792 then schema
784− & type_ .~ SwaggerArray
793+ & type_ ?~ SwaggerArray
785794 & items %~ appendItem ref
786795 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
787796 & minItems %~ Just . maybe 1 (+1) -- increment minItems
788797 else schema
789− & type_ .~ SwaggerObject
798+ & type_ ?~ SwaggerObject
790799 & properties . at fname ?~ ref
791800 & if isRequiredField
792801 then required %~ (++ [fname])
@@ -814,7 +823,7 @@ instance ( GSumToSchema f
814823 where
815824 gdeclareNamedSchema = gdeclareNamedSumSchema
816825
817−gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
826+gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
818827gdeclareNamedSumSchema opts proxy s
819828 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
820829 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
@@ -823,29 +832,29 @@ gdeclareNamedSumSchema opts proxy s
823832 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
824833
825834 toStringTag schema = mempty
826− & type_ .~ SwaggerString
835+ & type_ ?~ SwaggerString
827836 & enum_ ?~ map toJSON (schema ^.. properties.ifolded.asIndex)
828837
829838type AllNullary = All
830839
831840class GSumToSchema (f :: * -> *) where
832− gsumToSchema :: SchemaOptions -> proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
841+ gsumToSchema :: SchemaOptions -> Proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
833842
834843instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
835844 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) >=> gsumToSchema opts (Proxy :: Proxy g)
836845
837−gsumConToSchemaWith :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
838− 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
839848gsumConToSchemaWith ref opts _ schema = schema
840− & type_ .~ SwaggerObject
849+ & type_ ?~ SwaggerObject
841850 & properties . at tag ?~ ref
842851 & maxProperties ?~ 1
843852 & minProperties ?~ 1
844853 where
845854 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
846855
847−gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
848− 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
849858gsumConToSchema opts proxy schema = do
850859 ref <- gdeclareSchemaRef opts proxy
851860 return $ gsumConToSchemaWith ref opts proxy schema