git.iko.soy/typeable/openapi3
on master help sign in
Fix nullarySchema and nullary constructor schema
ab65c4aNickolay Kudasov
src/Data/Swagger/Internal/Schema.hs+14−11
@@ -416,7 +416,6 @@ paramSchemaToSchema _ = mempty & paramSchema .~ toParamSchema (Proxy :: Proxy a)
416nullarySchema :: Schema
416nullarySchema :: Schema
417nullarySchema = mempty
417nullarySchema = mempty
418 & type_ .~ SwaggerArray
418 & type_ .~ SwaggerArray
419− & enum_ ?~ [ toJSON () ]
420 & items ?~ SwaggerItemsArray []
419 & items ?~ SwaggerItemsArray []
421
420
422gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
421gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
@@ -535,18 +534,22 @@ class GSumToSchema f where
535instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
534instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
536 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) <=< gsumToSchema opts (Proxy :: Proxy g)
535 gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) <=< gsumToSchema opts (Proxy :: Proxy g)
537
536
538−gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
537+gsumConToSchemaWith :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
539− SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
538+ Referenced Schema -> SchemaOptions -> proxy (C1 c f) -> Schema -> Schema
540−gsumConToSchema opts _ schema = do
539+gsumConToSchemaWith ref opts _ schema = schema
541− ref <- gdeclareSchemaRef opts (Proxy :: Proxy (C1 c f))
542− return $ schema
543− & type_ .~ SwaggerObject
540+ & type_ .~ SwaggerObject
544− & properties . at tag ?~ ref
541+ & properties . at tag ?~ ref
545− & maxProperties ?~ 1
542+ & maxProperties ?~ 1
546− & minProperties ?~ 1
543+ & minProperties ?~ 1
547 where
544 where
548 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
545 tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
549
546
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+
550instance {-# OVERLAPPABLE #-} (Constructor c, GToSchema f) => GSumToSchema (C1 c f) where
553instance {-# OVERLAPPABLE #-} (Constructor c, GToSchema f) => GSumToSchema (C1 c f) where
551 gsumToSchema opts proxy schema = do
554 gsumToSchema opts proxy schema = do
552 tell (All False)
555 tell (All False)
@@ -558,7 +561,7 @@ instance (Constructor c, Selector s, GToSchema f) => GSumToSchema (C1 c (S1 s f)
558 lift $ gsumConToSchema opts proxy schema
561 lift $ gsumConToSchema opts proxy schema
559
562
560instance Constructor c => GSumToSchema (C1 c U1) where
563instance 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
562
565
563data Proxy2 a b = Proxy2
566data Proxy2 a b = Proxy2
564
567