@@ -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)
@@ -57,7 +57,8 @@ import qualified Data.Vector as V
5757import qualified Data.Vector.Primitive as VP
5858import qualified Data.Vector.Storable as VS
5959import qualified Data.Vector.Unboxed as VU
60−import Numeric.Natural
60+import Data.Version (Version)
61+import Numeric.Natural.Compat (Natural)
6162import Data.Word
6263import GHC.Generics
6364import qualified Data.UUID.Types as UUID
@@ -110,7 +111,7 @@ rename name (NamedSchema _ schema) = NamedSchema name schema
110111-- declareNamedSchema _ = do
111112-- doubleSchema <- declareSchemaRef (Proxy :: Proxy Double)
112113-- return $ NamedSchema (Just \"Coord\") $ mempty
113−-- & type_ .~ SwaggerObject
114+-- & type_ ?~ SwaggerObject
114115-- & properties .~
115116-- [ (\"x\", doubleSchema)
116117-- , (\"y\", doubleSchema)
@@ -141,13 +142,17 @@ class ToSchema a where
141142 -- together with all used definitions.
142143 -- Note that the schema itself is included in definitions
143144 -- only if it is recursive (and thus needs its definition in scope).
144− declareNamedSchema :: proxy a -> Declare (Definitions Schema) NamedSchema
145+ declareNamedSchema :: Proxy a -> Declare (Definitions Schema) NamedSchema
145146 default declareNamedSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
146− proxy a -> Declare (Definitions Schema) NamedSchema
147+ Proxy a -> Declare (Definitions Schema) NamedSchema
147148 declareNamedSchema = genericDeclareNamedSchema defaultSchemaOptions
148149
150+instance ToSchema TimeOfDay where
151+ declareNamedSchema _ = pure $ named "TimeOfDay" $ timeSchema "hh:MM:ss"
152+ & example ?~ toJSON (TimeOfDay 12 33 15)
153+
149154-- | Convert a type into a schema and declare all used schema definitions.
150−declareSchema :: ToSchema a => proxy a -> Declare (Definitions Schema) Schema
155+declareSchema :: ToSchema a => Proxy a -> Declare (Definitions Schema) Schema
151156declareSchema = fmap _namedSchemaSchema . declareNamedSchema
152157
153158-- | Convert a type into an optionally named schema.
@@ -161,7 +166,7 @@ declareSchema = fmap _namedSchemaSchema . declareNamedSchema
161166-- Just "Day"
162167-- >>> encode (toNamedSchema (Proxy :: Proxy Day) ^. schema)
163168-- "{\"example\":\"2016-07-22\",\"format\":\"date\",\"type\":\"string\"}"
164−toNamedSchema :: ToSchema a => proxy a -> NamedSchema
169+toNamedSchema :: ToSchema a => Proxy a -> NamedSchema
165170toNamedSchema = undeclare . declareNamedSchema
166171
167172-- | Get type's schema name according to its @'ToSchema'@ instance.
@@ -171,7 +176,7 @@ toNamedSchema = undeclare . declareNamedSchema
171176--
172177-- >>> schemaName (Proxy :: Proxy UTCTime)
173178-- Just "UTCTime"
174−schemaName :: ToSchema a => proxy a -> Maybe T.Text
179+schemaName :: ToSchema a => Proxy a -> Maybe T.Text
175180schemaName = _namedSchemaName . toNamedSchema
176181
177182-- | Convert a type into a schema.
@@ -181,7 +186,7 @@ schemaName = _namedSchemaName . toNamedSchema
181186--
182187-- >>> encode $ toSchema (Proxy :: Proxy [Day])
183188-- "{\"items\":{\"$ref\":\"#/definitions/Day\"},\"type\":\"array\"}"
184−toSchema :: ToSchema a => proxy a -> Schema
189+toSchema :: ToSchema a => Proxy a -> Schema
185190toSchema = _namedSchemaSchema . toNamedSchema
186191
187192-- | Convert a type into a referenced schema if possible.
@@ -192,7 +197,7 @@ toSchema = _namedSchemaSchema . toNamedSchema
192197--
193198-- >>> encode $ toSchemaRef (Proxy :: Proxy Day)
194199-- "{\"$ref\":\"#/definitions/Day\"}"
195−toSchemaRef :: ToSchema a => proxy a -> Referenced Schema
200+toSchemaRef :: ToSchema a => Proxy a -> Referenced Schema
196201toSchemaRef = undeclare . declareSchemaRef
197202
198203-- | Convert a type into a referenced schema if possible
@@ -202,7 +207,7 @@ toSchemaRef = undeclare . declareSchemaRef
202207-- Schema definitions are typically declared for every referenced schema.
203208-- If @'declareSchemaRef'@ returns a reference, a corresponding schema
204209-- will be declared (regardless of whether it is recusive or not).
205−declareSchemaRef :: ToSchema a => proxy a -> Declare (Definitions Schema) (Referenced Schema)
210+declareSchemaRef :: ToSchema a => Proxy a -> Declare (Definitions Schema) (Referenced Schema)
206211declareSchemaRef proxy = do
207212 case toNamedSchema proxy of
208213 NamedSchema (Just name) schema -> do
@@ -264,7 +269,7 @@ inlineAllSchemas = inlineSchemasWhen (const True)
264269--
265270-- __WARNING:__ @'toInlinedSchema'@ will produce infinite schema
266271-- when inlining recursive schemas.
267−toInlinedSchema :: ToSchema a => proxy a -> Schema
272+toInlinedSchema :: ToSchema a => Proxy a -> Schema
268273toInlinedSchema proxy = inlineAllSchemas defs schema
269274 where
270275 (defs, schema) = runDeclare (declareSchema proxy) mempty
@@ -293,20 +298,20 @@ inlineNonRecursiveSchemas defs = inlineSchemasWhen nonRecursive defs
293298-- | Default schema for binary data (any sequence of octets).
294299binarySchema :: Schema
295300binarySchema = mempty
296− & type_ .~ SwaggerString
301+ & type_ ?~ SwaggerString
297302 & format ?~ "binary"
298303
299304-- | Default schema for binary data (base64 encoded).
300305byteSchema :: Schema
301306byteSchema = mempty
302− & type_ .~ SwaggerString
307+ & type_ ?~ SwaggerString
303308 & format ?~ "byte"
304309
305310-- | Default schema for password string.
306311-- @"password"@ format is used to hint UIs the input needs to be obscured.
307312passwordSchema :: Schema
308313passwordSchema = mempty
309− & type_ .~ SwaggerString
314+ & type_ ?~ SwaggerString
310315 & format ?~ "password"
311316
312317-- | Make an unrestrictive sketch of a @'Schema'@ based on a @'ToJSON'@ instance.
@@ -332,12 +337,12 @@ sketchSchema = sketch . toJSON
332337 sketch js@(Bool _) = go js
333338 sketch js = go js & example ?~ js
334339
335− go Null = mempty & type_ .~ SwaggerNull
336− go (Bool _) = mempty & type_ .~ SwaggerBoolean
337− go (String _) = mempty & type_ .~ SwaggerString
338− 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
339344 go (Array xs) = mempty
340− & type_ .~ SwaggerArray
345+ & type_ ?~ SwaggerArray
341346 & items ?~ case ischema of
342347 Just s -> SwaggerItemsObject (Inline s)
343348 _ -> SwaggerItemsArray (map Inline ys)
@@ -349,7 +354,7 @@ sketchSchema = sketch . toJSON
349354 (z:_) | allSame -> Just z
350355 _ -> Nothing
351356 go (Object o) = mempty
352− & type_ .~ SwaggerObject
357+ & type_ ?~ SwaggerObject
353358 & required .~ HashMap.keys o
354359 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
355360
@@ -372,24 +377,24 @@ sketchSchema = sketch . toJSON
372377sketchStrictSchema :: ToJSON a => a -> Schema
373378sketchStrictSchema = go . toJSON
374379 where
375− go Null = mempty & type_ .~ SwaggerNull
380+ go Null = mempty & type_ ?~ SwaggerNull
376381 go js@(Bool _) = mempty
377− & type_ .~ SwaggerBoolean
382+ & type_ ?~ SwaggerBoolean
378383 & enum_ ?~ [js]
379384 go js@(String s) = mempty
380− & type_ .~ SwaggerString
385+ & type_ ?~ SwaggerString
381386 & maxLength ?~ fromIntegral (T.length s)
382387 & minLength ?~ fromIntegral (T.length s)
383388 & pattern ?~ s
384389 & enum_ ?~ [js]
385390 go js@(Number n) = mempty
386− & type_ .~ SwaggerNumber
391+ & type_ ?~ SwaggerNumber
387392 & maximum_ ?~ n
388393 & minimum_ ?~ n
389394 & multipleOf ?~ n
390395 & enum_ ?~ [js]
391396 go js@(Array xs) = mempty
392− & type_ .~ SwaggerArray
397+ & type_ ?~ SwaggerArray
393398 & maxItems ?~ fromIntegral sz
394399 & minItems ?~ fromIntegral sz
395400 & items ?~ SwaggerItemsArray (map (Inline . go) (V.toList xs))
@@ -399,7 +404,7 @@ sketchStrictSchema = go . toJSON
399404 sz = length xs
400405 allUnique = sz == HashSet.size (HashSet.fromList (V.toList xs))
401406 go js@(Object o) = mempty
402− & type_ .~ SwaggerObject
407+ & type_ ?~ SwaggerObject
403408 & required .~ names
404409 & properties .~ fmap (Inline . go) (InsOrdHashMap.fromHashMap o)
405410 & maxProperties ?~ fromIntegral (length names)
@@ -409,13 +414,13 @@ sketchStrictSchema = go . toJSON
409414 names = HashMap.keys o
410415
411416class GToSchema (f :: * -> *) where
412− gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
417+ gdeclareNamedSchema :: SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
413418
414419instance OVERLAPPABLE_ ToSchema a => ToSchema [a] where
415420 declareNamedSchema _ = do
416421 ref <- declareSchemaRef (Proxy :: Proxy a)
417422 return $ unnamed $ mempty
418− & type_ .~ SwaggerArray
423+ & type_ ?~ SwaggerArray
419424 & items ?~ SwaggerItemsObject ref
420425
421426instance OVERLAPPING_ ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
@@ -465,7 +470,7 @@ instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d, ToSchema e, ToSchema f
465470
466471timeSchema :: T.Text -> Schema
467472timeSchema fmt = mempty
468− & type_ .~ SwaggerString
473+ & type_ ?~ SwaggerString
469474 & format ?~ fmt
470475
471476-- | Format @"date"@ corresponds to @yyyy-mm-dd@ format.
@@ -498,6 +503,8 @@ instance ToSchema UTCTime where
498503instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
499504instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
500505
506+instance ToSchema Version where declareNamedSchema = plain . paramSchemaToSchema
507+
501508#if __GLASGOW_HASKELL__ < 800
502509#else
503510type family ToSchemaByteStringError bs where
@@ -525,8 +532,8 @@ instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
525532 declareObjectMapSchema = do
526533 schema <- declareSchemaRef (Proxy :: Proxy v)
527534 return $ unnamed $ mempty
528− & type_ .~ SwaggerObject
529− & additionalProperties ?~ schema
535+ & type_ ?~ SwaggerObject
536+ & additionalProperties ?~ AdditionalPropertiesSchema schema
530537
531538instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
532539 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
@@ -537,7 +544,7 @@ instance ToSchema a => ToSchema (Map String a) where
537544 declareNamedSchema _ = do
538545 schema <- declareSchemaRef (Proxy :: Proxy a)
539546 return $ unnamed $ mempty
540− & type_ .~ SwaggerObject
547+ & type_ ?~ SwaggerObject
541548 & additionalProperties ?~ schema
542549
543550instance ToSchema a => ToSchema (Map T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
@@ -549,6 +556,12 @@ instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ =
549556
550557#endif
551558
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+
552565instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
553566instance ToSchema a => ToSchema (VU.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
554567instance ToSchema a => ToSchema (VS.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
@@ -584,26 +597,26 @@ instance ToSchema a => ToSchema (Identity a) where declareNamedSchema _ = declar
584597--
585598-- >>> encode $ toSchemaBoundedIntegral (Proxy :: Proxy Int16)
586599-- "{\"maximum\":32767,\"minimum\":-32768,\"type\":\"integer\"}"
587−toSchemaBoundedIntegral :: forall a proxy. (Bounded a, Integral a) => proxy a -> Schema
600+toSchemaBoundedIntegral :: forall a. (Bounded a, Integral a) => Proxy a -> Schema
588601toSchemaBoundedIntegral _ = mempty
589− & type_ .~ SwaggerInteger
602+ & type_ ?~ SwaggerInteger
590603 & minimum_ ?~ fromInteger (toInteger (minBound :: a))
591604 & maximum_ ?~ fromInteger (toInteger (maxBound :: a))
592605
593606-- | Default generic named schema for @'Bounded'@, @'Integral'@ types.
594−genericToNamedSchemaBoundedIntegral :: forall a d f proxy.
607+genericToNamedSchemaBoundedIntegral :: forall a d f.
595608 ( Bounded a, Integral a
596609 , Generic a, Rep a ~ D1 d f, Datatype d)
597− => SchemaOptions -> proxy a -> NamedSchema
610+ => SchemaOptions -> Proxy a -> NamedSchema
598611genericToNamedSchemaBoundedIntegral opts proxy
599612 = genericNameSchema opts proxy (toSchemaBoundedIntegral proxy)
600613
601614-- | Declare a named schema for a @newtype@ wrapper.
602−genericDeclareNamedSchemaNewtype :: forall proxy a d c s i inner.
615+genericDeclareNamedSchemaNewtype :: forall a d c s i inner.
603616 (Generic a, Datatype d, Rep a ~ D1 d (C1 c (S1 s (K1 i inner))))
604617 => SchemaOptions -- ^ How to derive the name.
605618 -> (Proxy inner -> Declare (Definitions Schema) Schema) -- ^ How to create a schema for the wrapped type.
606− -> proxy a
619+ -> Proxy a
607620 -> Declare (Definitions Schema) NamedSchema
608621genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$> f (Proxy :: Proxy inner)
609622
@@ -620,9 +633,9 @@ genericDeclareNamedSchemaNewtype opts f proxy = genericNameSchema opts proxy <$>
620633--
621634-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
622635-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
623−declareSchemaBoundedEnumKeyMapping :: forall map key value proxy.
636+declareSchemaBoundedEnumKeyMapping :: forall map key value.
624637 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
625− => proxy (map key value) -> Declare (Definitions Schema) Schema
638+ => Proxy (map key value) -> Declare (Definitions Schema) Schema
626639declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key of
627640 ToJSONKeyText keyToText _ -> objectSchema keyToText
628641 ToJSONKeyValue _ _ -> declareSchema (Proxy :: Proxy [(key, value)])
@@ -632,7 +645,7 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
632645 let allKeys = [minBound..maxBound :: key]
633646 mkPair k = (keyToText k, valueRef)
634647 return $ mempty
635− & type_ .~ SwaggerObject
648+ & type_ ?~ SwaggerObject
636649 & properties .~ InsOrdHashMap.fromList (map mkPair allKeys)
637650
638651-- | A 'Schema' for a mapping with 'Bounded' 'Enum' keys.
@@ -648,46 +661,46 @@ declareSchemaBoundedEnumKeyMapping _ = case toJSONKey :: ToJSONKeyFunction key o
648661--
649662-- Note: this is only useful when @key@ is encoded with 'ToJSONKeyText'.
650663-- If it is encoded with 'ToJSONKeyValue' then a regular schema for @[(key, value)]@ is used.
651−toSchemaBoundedEnumKeyMapping :: forall map key value proxy.
664+toSchemaBoundedEnumKeyMapping :: forall map key value.
652665 (Bounded key, Enum key, ToJSONKey key, ToSchema key, ToSchema value)
653− => proxy (map key value) -> Schema
666+ => Proxy (map key value) -> Schema
654667toSchemaBoundedEnumKeyMapping = flip evalDeclare mempty . declareSchemaBoundedEnumKeyMapping
655668
656669-- | A configurable generic @'Schema'@ creator.
657670genericDeclareSchema :: (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareSchemaUnrestricted") =>
658− SchemaOptions -> proxy a -> Declare (Definitions Schema) Schema
671+ SchemaOptions -> Proxy a -> Declare (Definitions Schema) Schema
659672genericDeclareSchema = genericDeclareSchemaUnrestricted
660673
661674-- | A configurable generic @'NamedSchema'@ creator.
662675-- This function applied to @'defaultSchemaOptions'@
663676-- is used as the default for @'declareNamedSchema'@
664677-- when the type is an instance of @'Generic'@.
665−genericDeclareNamedSchema :: forall a proxy. (Generic a, GToSchema (Rep a), TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
666− 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
667680genericDeclareNamedSchema = genericDeclareNamedSchemaUnrestricted
668681
669682-- | A configurable generic @'Schema'@ creator.
670683--
671684-- Unlike 'genericDeclareSchema' also works for mixed sum types.
672685-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
673−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
674687genericDeclareSchemaUnrestricted opts proxy = _namedSchemaSchema <$> genericDeclareNamedSchemaUnrestricted opts proxy
675688
676689-- | A configurable generic @'NamedSchema'@ creator.
677690--
678691-- Unlike 'genericDeclareNamedSchema' also works for mixed sum types.
679692-- Use with care since some Swagger tools do not support well schemas for mixed sum types.
680−genericDeclareNamedSchemaUnrestricted :: forall a proxy. (Generic a, GToSchema (Rep a)) =>
681− SchemaOptions -> proxy a -> Declare (Definitions Schema) NamedSchema
693+genericDeclareNamedSchemaUnrestricted :: forall a. (Generic a, GToSchema (Rep a)) =>
694+ SchemaOptions -> Proxy a -> Declare (Definitions Schema) NamedSchema
682695genericDeclareNamedSchemaUnrestricted opts _ = gdeclareNamedSchema opts (Proxy :: Proxy (Rep a)) mempty
683696
684697-- | Derive a 'Generic'-based name for a datatype and assign it to a given 'Schema'.
685−genericNameSchema :: forall a d f proxy.
698+genericNameSchema :: forall a d f.
686699 (Generic a, Rep a ~ D1 d f, Datatype d)
687− => SchemaOptions -> proxy a -> Schema -> NamedSchema
700+ => SchemaOptions -> Proxy a -> Schema -> NamedSchema
688701genericNameSchema opts _ = NamedSchema (gdatatypeSchemaName opts (Proxy :: Proxy d))
689702
690−gdatatypeSchemaName :: forall proxy d. Datatype d => SchemaOptions -> proxy d -> Maybe T.Text
703+gdatatypeSchemaName :: forall d. Datatype d => SchemaOptions -> Proxy d -> Maybe T.Text
691704gdatatypeSchemaName opts _ = case orig of
692705 (c:_) | isAlpha c && isUpper c -> Just (T.pack name)
693706 _ -> Nothing
@@ -696,24 +709,23 @@ gdatatypeSchemaName opts _ = case orig of
696709 name = datatypeNameModifier opts orig
697710
698711-- | Lift a plain @'ParamSchema'@ into a model @'NamedSchema'@.
699−paramSchemaToNamedSchema :: forall a d f proxy.
700− (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d)
701− => SchemaOptions -> proxy a -> NamedSchema
712+paramSchemaToNamedSchema :: (ToParamSchema a, Generic a, Rep a ~ D1 d f, Datatype d) =>
713+ SchemaOptions -> Proxy a -> NamedSchema
702714paramSchemaToNamedSchema opts proxy = genericNameSchema opts proxy (paramSchemaToSchema proxy)
703715
704716-- | Lift a plain @'ParamSchema'@ into a model @'Schema'@.
705−paramSchemaToSchema :: forall a proxy. ToParamSchema a => proxy a -> Schema
706−paramSchemaToSchema _ = mempty & paramSchema .~ toParamSchema (Proxy :: Proxy a)
717+paramSchemaToSchema :: ToParamSchema a => Proxy a -> Schema
718+paramSchemaToSchema proxy = mempty & paramSchema .~ toParamSchema proxy
707719
708720nullarySchema :: Schema
709721nullarySchema = mempty
710− & type_ .~ SwaggerArray
722+ & type_ ?~ SwaggerArray
711723 & items ?~ SwaggerItemsArray []
712724
713−gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
725+gtoNamedSchema :: GToSchema f => SchemaOptions -> Proxy f -> NamedSchema
714726gtoNamedSchema opts proxy = undeclare $ gdeclareNamedSchema opts proxy mempty
715727
716−gdeclareSchema :: GToSchema f => SchemaOptions -> proxy f -> Declare (Definitions Schema) Schema
728+gdeclareSchema :: GToSchema f => SchemaOptions -> Proxy f -> Declare (Definitions Schema) Schema
717729gdeclareSchema opts proxy = _namedSchemaSchema <$> gdeclareNamedSchema opts proxy mempty
718730
719731instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
@@ -747,7 +759,7 @@ instance (Selector s, GToSchema f, GToSchema (S1 s f)) => GToSchema (C1 c (S1 s
747759 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
748760 fieldSchema = gdeclareNamedSchema opts (Proxy :: Proxy f) s
749761
750−gdeclareSchemaRef :: GToSchema a => SchemaOptions -> proxy a -> Declare (Definitions Schema) (Referenced Schema)
762+gdeclareSchemaRef :: GToSchema a => SchemaOptions -> Proxy a -> Declare (Definitions Schema) (Referenced Schema)
751763gdeclareSchemaRef opts proxy = do
752764 case gtoNamedSchema opts proxy of
753765 NamedSchema (Just name) schema -> do
@@ -778,12 +790,12 @@ withFieldSchema opts _ isRequiredField schema = do
778790 return $
779791 if T.null fname
780792 then schema
781− & type_ .~ SwaggerArray
793+ & type_ ?~ SwaggerArray
782794 & items %~ appendItem ref
783795 & maxItems %~ Just . maybe 1 (+1) -- increment maxItems
784796 & minItems %~ Just . maybe 1 (+1) -- increment minItems
785797 else schema
786− & type_ .~ SwaggerObject
798+ & type_ ?~ SwaggerObject
787799 & properties . at fname ?~ ref
788800 & if isRequiredField
789801 then required %~ (++ [fname])
@@ -811,7 +823,7 @@ instance ( GSumToSchema f
811823 where
812824 gdeclareNamedSchema = gdeclareNamedSumSchema
813825
814−gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
826+gdeclareNamedSumSchema :: GSumToSchema f => SchemaOptions -> Proxy f -> Schema -> Declare (Definitions Schema) NamedSchema
815827gdeclareNamedSumSchema opts proxy s
816828 | allNullaryToStringTag opts && allNullary = pure $ unnamed (toStringTag sumSchema)
817829 | otherwise = (unnamed . fst) <$> runWriterT declareSumSchema
@@ -820,29 +832,29 @@ gdeclareNamedSumSchema opts proxy s
820832 (sumSchema, All allNullary) = undeclare (runWriterT declareSumSchema)
821833
822834 toStringTag schema = mempty
823− & type_ .~ SwaggerString
835+ & type_ ?~ SwaggerString
824836 & enum_ ?~ map toJSON (schema ^.. properties.ifolded.asIndex)
825837
826838type AllNullary = All
827839
828840class GSumToSchema (f :: * -> *) where
829− gsumToSchema :: SchemaOptions -> proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
841+ gsumToSchema :: SchemaOptions -> Proxy f -> Schema -> WriterT AllNullary (Declare (Definitions Schema)) Schema
830842
831843instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
832844 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) >=> gsumToSchema opts (Proxy :: Proxy g)
833845
834−gsumConToSchemaWith :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
835− 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
836848gsumConToSchemaWith ref opts _ schema = schema
837− & type_ .~ SwaggerObject
849+ & type_ ?~ SwaggerObject
838850 & properties . at tag ?~ ref
839851 & maxProperties ?~ 1
840852 & minProperties ?~ 1
841853 where
842854 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
843855
844−gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
845− 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
846858gsumConToSchema opts proxy schema = do
847859 ref <- gdeclareSchemaRef opts proxy
848860 return $ gsumConToSchemaWith ref opts proxy schema