git.iko.soy/typeable/swagger2
on master help sign in
Fix sum encoding for unary ref alternative

In case of unary non-record alternative we retain field's name in case we need to $ref it when constructing schema for sum type. Note that this only affects sum types, e.g. -- some type with named schema to $ref data A = ... -- schema for B will reuse schema for A, not $ref to it data B = B A deriving (Generic, ToSchema) -- schema for C will $ref A for C1 constructor data C = C1 A | ... deriving (Generic, ToSchema)

commit01e66d80f5d1e8900f0204b6a765f6552afad0c5 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateWed 25 Nov 2015, 14:45 (11 years ago) parenta3f3747
1 file changed+4−4
src/Data/Swagger/Schema/Internal.hs+4−4
src/Data/Swagger/Schema/Internal.hs+4−4
@@ -201,14 +201,14 @@ instance {-# OVERLAPPABLE #-} GToSchema f => GToSchema (C1 c f) where
201201-- | Single field constructor.
202202instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
203203 gtoNamedSchema opts _ s
204− | unwrapUnaryRecords opts = unnamed fieldSchema
205− | otherwise = unnamed $
204+ | unwrapUnaryRecords opts = unnamed (snd fieldSchema)
205+ | otherwise =
206206 case schema ^. schemaItems of
207207 Just (SchemaItemsArray [_]) -> fieldSchema
208− _ -> schema
208+ _ -> unnamed schema
209209 where
210210 schema = gtoSchema opts (Proxy :: Proxy (S1 s f)) s
211− fieldSchema = gtoSchema opts (Proxy :: Proxy f) s
211+ fieldSchema = gtoNamedSchema opts (Proxy :: Proxy f) s
212212
213213gtoSchemaRef :: GToSchema f => SchemaOptions -> proxy f -> Referenced Schema
214214gtoSchemaRef opts proxy = case gtoNamedSchema opts proxy mempty of