@@ -0,0 +1,60 @@
2+{-# LANGUAGE KindSignatures #-}
3+{-# LANGUAGE DataKinds #-}
4+{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeOperators #-}
6+{-# LANGUAGE UndecidableInstances #-}
9+module Data.Swagger.Internal.TypeShape where
16+data TypeShape = EnumShape
21+type family ProdCombine (a :: TypeShape ) (b :: TypeShape) :: TypeShape where
23+ ProdCombine IlegalShape b = IlegalShape
24+ ProdCombine a IlegalShape = IlegalShape
25+ ProdCombine a b = NestedShape
28+type family SumCombine (a :: TypeShape ) (b :: TypeShape) :: TypeShape where
30+ SumCombine EnumShape EnumShape = EnumShape
31+ SumCombine NestedShape NestedShape = NestedShape
32+ SumCombine a b = IlegalShape
37+class LegalShape (a :: TypeShape) where
39+instance LegalShape EnumShape
40+instance LegalShape NestedShape
43+ ( Text "Cannot auto derive swagger class, for that to be possible, make sure that any constructor "
44+ :$$: Text "for this type, only holds 0 arguments if there are no other contructors with more than 0 arguments,"
45+ :$$: Text "otherwise, every constructor have to hold at least 1 argument"
46+ ) => LegalShape IlegalShape
50+type family GenericShape ( g :: * -> * ) :: TypeShape
53+type instance GenericShape (f :*: g) = ProdCombine (GenericShape f) (GenericShape g)
54+type instance GenericShape (f :+: g) = SumCombine (GenericShape f) (GenericShape g)
55+type instance GenericShape (D1 d f) = GenericShape f
56+type instance GenericShape (C1 c U1) = EnumShape
57+type instance GenericShape (C1 c (S1 s f)) = NestedShape
58+type instance GenericShape (C1 c (f :*: g)) = NestedShape