git.iko.soy/typeable/swagger2
on master help sign in
Use a single DataType for all Data SwaggerType instances
dd64c84Nickolay Kudasov
src/Data/Swagger/Internal.hs+14−11
@@ -344,8 +344,8 @@ deriving instance Typeable (SwaggerType t)
344swaggerTypeConstr :: Data (SwaggerType t) => SwaggerType t -> Constr
344swaggerTypeConstr :: Data (SwaggerType t) => SwaggerType t -> Constr
345swaggerTypeConstr t = mkConstr (dataTypeOf t) (show t) [] Prefix
345swaggerTypeConstr t = mkConstr (dataTypeOf t) (show t) [] Prefix
346
346
347−swaggerTypeDataType :: Data (SwaggerType t) => [SwaggerType t] -> SwaggerType t -> DataType
347+swaggerTypeDataType :: Data (SwaggerType t) => SwaggerType t -> DataType
348−swaggerTypeDataType cons _ = mkDataType "Data.Swagger.SwaggerType" $ map swaggerTypeConstr cons
348+swaggerTypeDataType _ = mkDataType "Data.Swagger.SwaggerType" swaggerTypeConstrs
349
349
350swaggerCommonTypes :: [SwaggerType t]
350swaggerCommonTypes :: [SwaggerType t]
351swaggerCommonTypes = [SwaggerString, SwaggerNumber, SwaggerInteger, SwaggerBoolean, SwaggerArray]
351swaggerCommonTypes = [SwaggerString, SwaggerNumber, SwaggerInteger, SwaggerBoolean, SwaggerArray]
@@ -354,23 +354,26 @@ swaggerParamTypes :: [SwaggerType ParamOtherSchema]
354swaggerParamTypes = swaggerCommonTypes ++ [SwaggerFile]
354swaggerParamTypes = swaggerCommonTypes ++ [SwaggerFile]
355
355
356swaggerSchemaTypes :: [SwaggerType Schema]
356swaggerSchemaTypes :: [SwaggerType Schema]
357−swaggerSchemaTypes = swaggerCommonTypes ++ [SwaggerNull, SwaggerObject]
357+swaggerSchemaTypes = swaggerCommonTypes ++ [error "SwaggerFile is invalid SwaggerType Schema", SwaggerNull, SwaggerObject]
358+
359+swaggerTypeConstrs :: [Constr]
360+swaggerTypeConstrs = map swaggerTypeConstr (swaggerCommonTypes :: [SwaggerType Schema])
361+ ++ [swaggerTypeConstr SwaggerFile, swaggerTypeConstr SwaggerNull, swaggerTypeConstr SwaggerObject]
358
362
359instance {-# OVERLAPPABLE #-} Typeable t => Data (SwaggerType t) where
363instance {-# OVERLAPPABLE #-} Typeable t => Data (SwaggerType t) where
360− gunfold = gunfoldEnum "SwaggerType" $ zip [1..] swaggerCommonTypes
364+ gunfold = gunfoldEnum "SwaggerType" swaggerCommonTypes
361 toConstr = swaggerTypeConstr
365 toConstr = swaggerTypeConstr
362− dataTypeOf = swaggerTypeDataType swaggerCommonTypes
366+ dataTypeOf = swaggerTypeDataType
363
367
364instance {-# OVERLAPPING #-} Data (SwaggerType ParamOtherSchema) where
368instance {-# OVERLAPPING #-} Data (SwaggerType ParamOtherSchema) where
365− gunfold = gunfoldEnum "SwaggerType ParamOtherSchema" $ zip [1..] swaggerParamTypes
369+ gunfold = gunfoldEnum "SwaggerType ParamOtherSchema" swaggerParamTypes
366 toConstr = swaggerTypeConstr
370 toConstr = swaggerTypeConstr
367− dataTypeOf = swaggerTypeDataType swaggerParamTypes
371+ dataTypeOf = swaggerTypeDataType
368
372
369instance {-# OVERLAPPING #-} Data (SwaggerType Schema) where
373instance {-# OVERLAPPING #-} Data (SwaggerType Schema) where
370− gunfold = gunfoldEnum "SwaggerType Schema" $ zip ns swaggerSchemaTypes
374+ gunfold = gunfoldEnum "SwaggerType Schema" swaggerSchemaTypes
371− where ns = [1, 2, 3, 4, 5, 7, 8] -- skipping constructor #6 here
372 toConstr = swaggerTypeConstr
375 toConstr = swaggerTypeConstr
373− dataTypeOf = swaggerTypeDataType swaggerSchemaTypes
376+ dataTypeOf = swaggerTypeDataType
374
377
375data ParamLocation
378data ParamLocation
376 = -- | Parameters that are appended to the URL.
379 = -- | Parameters that are appended to the URL.
@@ -424,7 +427,7 @@ collectionCommonFormats :: [CollectionFormat t]
424collectionCommonFormats = [ CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes ]
427collectionCommonFormats = [ CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes ]
425
428
426instance {-# OVERLAPPABLE #-} Data t => Data (CollectionFormat t) where
429instance {-# OVERLAPPABLE #-} Data t => Data (CollectionFormat t) where
427− gunfold = gunfoldEnum "CollectionFormat" $ zip [1..] collectionCommonFormats
430+ gunfold = gunfoldEnum "CollectionFormat" collectionCommonFormats
428 toConstr = collectionFormatConstr
431 toConstr = collectionFormatConstr
429 dataTypeOf _ = collectionFormatDataType
432 dataTypeOf _ = collectionFormatDataType
430
433
src/Data/Swagger/Internal/Utils.hs+2−2
@@ -21,8 +21,8 @@ import GHC.Generics
21import Language.Haskell.TH
21import Language.Haskell.TH
22import Text.Read (readMaybe)
22import Text.Read (readMaybe)
23
23
24−gunfoldEnum :: String -> [(ConIndex, a)] -> (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a
24+gunfoldEnum :: String -> [a] -> (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a
25−gunfoldEnum tname xs _k z c = case lookup (constrIndex c) xs of
25+gunfoldEnum tname xs _k z c = case lookup (constrIndex c) (zip [1..] xs) of
26 Just x -> z x
26 Just x -> z x
27 Nothing -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type " ++ tname ++ "."
27 Nothing -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type " ++ tname ++ "."
28
28