Skip to content

Commit

Permalink
Fix nullarySchema and nullary constructor schema
Browse files Browse the repository at this point in the history
  • Loading branch information
fizruk committed Jan 23, 2016
1 parent 59aa9f9 commit ab65c4a
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/Data/Swagger/Internal/Schema.hs
Expand Up @@ -416,7 +416,6 @@ paramSchemaToSchema _ = mempty & paramSchema .~ toParamSchema (Proxy :: Proxy a)
nullarySchema :: Schema
nullarySchema = mempty
& type_ .~ SwaggerArray
& enum_ ?~ [ toJSON () ]
& items ?~ SwaggerItemsArray []

gtoNamedSchema :: GToSchema f => SchemaOptions -> proxy f -> NamedSchema
Expand Down Expand Up @@ -535,18 +534,22 @@ class GSumToSchema f where
instance (GSumToSchema f, GSumToSchema g) => GSumToSchema (f :+: g) where
gsumToSchema opts _ = gsumToSchema opts (Proxy :: Proxy f) <=< gsumToSchema opts (Proxy :: Proxy g)

gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
gsumConToSchema opts _ schema = do
ref <- gdeclareSchemaRef opts (Proxy :: Proxy (C1 c f))
return $ schema
& type_ .~ SwaggerObject
& properties . at tag ?~ ref
& maxProperties ?~ 1
& minProperties ?~ 1
gsumConToSchemaWith :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
Referenced Schema -> SchemaOptions -> proxy (C1 c f) -> Schema -> Schema
gsumConToSchemaWith ref opts _ schema = schema
& type_ .~ SwaggerObject
& properties . at tag ?~ ref
& maxProperties ?~ 1
& minProperties ?~ 1
where
tag = T.pack (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))

gsumConToSchema :: forall c f proxy. (GToSchema (C1 c f), Constructor c) =>
SchemaOptions -> proxy (C1 c f) -> Schema -> Declare (Definitions Schema) Schema
gsumConToSchema opts proxy schema = do
ref <- gdeclareSchemaRef opts proxy
return $ gsumConToSchemaWith ref opts proxy schema

instance {-# OVERLAPPABLE #-} (Constructor c, GToSchema f) => GSumToSchema (C1 c f) where
gsumToSchema opts proxy schema = do
tell (All False)
Expand All @@ -558,7 +561,7 @@ instance (Constructor c, Selector s, GToSchema f) => GSumToSchema (C1 c (S1 s f)
lift $ gsumConToSchema opts proxy schema

instance Constructor c => GSumToSchema (C1 c U1) where
gsumToSchema opts proxy = lift . gsumConToSchema opts proxy
gsumToSchema opts proxy = pure . gsumConToSchemaWith (Inline nullarySchema) opts proxy

data Proxy2 a b = Proxy2

Expand Down

0 comments on commit ab65c4a

Please sign in to comment.