git.iko.soy/typeable/swagger2
on master help sign in
Cleanup SwaggerType a bit
commit7a5df24088b9151dd21ccc06ff5f663d32a2b03b authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateWed 9 Dec 2015, 13:25 (11 years ago) parente1fc9e6
2 files changed+10−7
src/Data/Swagger/Internal.hs+8−5 src/Data/Swagger/Lens.hs+2−2
src/Data/Swagger/Internal.hs+8−5
@@ -295,7 +295,7 @@ data ParamOtherSchema = ParamOtherSchema
295295 -- Default value is csv.
296296 , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
297297
298− , _paramOtherSchemaCommon :: SchemaCommon Param Items
298+ , _paramOtherSchemaCommon :: SchemaCommon ParamOtherSchema Items
299299 } deriving (Eq, Show, Generic)
300300
301301data SwaggerType t where
@@ -304,7 +304,7 @@ data SwaggerType t where
304304 SwaggerInteger :: SwaggerType t
305305 SwaggerBoolean :: SwaggerType t
306306 SwaggerArray :: SwaggerType t
307− SwaggerFile :: SwaggerType Param
307+ SwaggerFile :: SwaggerType ParamOtherSchema
308308 SwaggerNull :: SwaggerType Schema
309309 SwaggerObject :: SwaggerType Schema
310310
@@ -487,7 +487,7 @@ data Header = Header
487487 -- Default value is @'ItemsCollectionCSV'@.
488488 , _headerCollectionFormat :: Maybe (CollectionFormat Items)
489489
490− , _headerCommon :: SchemaCommon Items Items
490+ , _headerCommon :: SchemaCommon Header Items
491491 } deriving (Eq, Show, Generic)
492492
493493data Example = Example { getExample :: Map MediaType Value }
@@ -968,10 +968,10 @@ instance FromJSON Xml where
968968instance FromJSON (SwaggerType Schema) where
969969 parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray, SwaggerNull, SwaggerObject]
970970
971−instance FromJSON (SwaggerType Param) where
971+instance FromJSON (SwaggerType ParamOtherSchema) where
972972 parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray, SwaggerFile]
973973
974−instance FromJSON (SwaggerType Items) where
974+instance {-# OVERLAPPABLE #-} FromJSON (SwaggerType t) where
975975 parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray]
976976
977977instance FromJSON (CollectionFormat Param) where
@@ -980,5 +980,8 @@ instance FromJSON (CollectionFormat Param) where
980980instance FromJSON (CollectionFormat Items) where
981981 parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
982982
983+-- NOTE: The constraint @FromJSON (SwaggerType t)@ is necessary here!
984+-- Without the constraint the general instance will be used
985+-- that only accepts common types (i.e. NOT object, null or file).
983986instance (FromJSON (SwaggerType t), FromJSON i) => FromJSON (SchemaCommon t i) where
984987 parseJSON = genericParseJSON (jsonPrefix "SchemaCommon")
src/Data/Swagger/Lens.hs+2−2
@@ -61,9 +61,9 @@ class HasSchemaCommon s t i | s -> t i where
6161 schemaCommon :: Lens' s (SchemaCommon t i)
6262
6363instance HasSchemaCommon Schema Schema SchemaItems where schemaCommon = schemaSchemaCommon
64−instance HasSchemaCommon ParamOtherSchema Param Items where schemaCommon = paramOtherSchemaCommon
64+instance HasSchemaCommon ParamOtherSchema ParamOtherSchema Items where schemaCommon = paramOtherSchemaCommon
6565instance HasSchemaCommon Items Items Items where schemaCommon = itemsCommon
66−instance HasSchemaCommon Header Items Items where schemaCommon = headerCommon
66+instance HasSchemaCommon Header Header Items where schemaCommon = headerCommon
6767instance HasSchemaCommon (SchemaCommon t i) t i where schemaCommon = id
6868
6969schemaType :: HasSchemaCommon s t i => Lens' s (SwaggerType t)