git.iko.soy/typeable/swagger2
on master help sign in
Fix nullarySchema and nullary constructor schema

(fixes haskell-servant/servant-swagger#19)

commitab65c4a48253c34f8a88221a53dc97bf5e6e8d29 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSat 23 Jan 2016, 04:13 (11 years ago) parent59aa9f9
1 file changed+14−11
src/Data/Swagger/Internal/Schema.hs+14−11
src/Data/Swagger/Internal/Schema.hs+14−11
@@ -416,7 +416,6 @@ paramSchemaToSchema _ = mempty & paramSchema .~ toParamSchema (Proxy :: Proxy a)
416416nullarySchema :: Schema
417417nullarySchema = mempty
418418 & type_ .~ SwaggerArray
419− & enum_ ?~ [ toJSON () ]
420419 & items ?~ SwaggerItemsArray []
421420
422421gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
@@ -535,18 +534,22 @@ class GSumToSchema f where
535534instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
536535 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) <=< gsumToSchema opts (Proxy :: Proxy g)
537536
538−gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
539− SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
540−gsumConToSchema opts _ schema = do
541− ref <- gdeclareSchemaRef opts (Proxy :: Proxy (C1 c f))
542− return $ schema
543− & type_ .~ SwaggerObject
544− & properties . at tag ?~ ref
545− & maxProperties ?~ 1
546− & minProperties ?~ 1
537+gsumConToSchemaWith :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
538+ Referenced Schema -> SchemaOptions -> proxy (C1 c f) -> Schema -> Schema
539+gsumConToSchemaWith ref opts _ schema = schema
540+ & type_ .~ SwaggerObject
541+ & properties . at tag ?~ ref
542+ & maxProperties ?~ 1
543+ & minProperties ?~ 1
547544 where
548545 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
549546
547+gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
548+ SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
549+gsumConToSchema opts proxy schema = do
550+ ref <- gdeclareSchemaRef opts proxy
551+ return $ gsumConToSchemaWith ref opts proxy schema
552+
550553instance {-# OVERLAPPABLE #-} (Constructor c, GToSchema f) => GSumToSchema (C1 c f) where
551554 gsumToSchema opts proxy schema = do
552555 tell (All False)
@@ -558,7 +561,7 @@ instance (Constructor c, Selector s, GToSchema f) => GSumToSchema (C1 c (S1 s f)
558561 lift $ gsumConToSchema opts proxy schema
559562
560563instance Constructor c => GSumToSchema (C1 c U1) where
561− gsumToSchema opts proxy = lift . gsumConToSchema opts proxy
564+ gsumToSchema opts proxy = pure . gsumConToSchemaWith (Inline nullarySchema) opts proxy
562565
563566data Proxy2 a b = Proxy2
564567