git.iko.soy/typeable/swagger2
on master help sign in
Simplify SchemaCommon a tiny bit

schemaCommonType now is of type (SwaggerType t)

commite1fc9e67392af6a1cdde78a77a74c4d0d6425102 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateWed 9 Dec 2015, 10:49 (11 years ago) parenta9cdd0f
2 files changed+17−14
src/Data/Swagger/Internal.hs+12−9 src/Data/Swagger/Lens.hs+5−5
src/Data/Swagger/Internal.hs+12−9
@@ -1,5 +1,6 @@
11{-# LANGUAGE DeriveGeneric #-}
22{-# LANGUAGE DeriveTraversable #-}
3+{-# LANGUAGE FlexibleContexts #-}
34{-# LANGUAGE FlexibleInstances #-}
45{-# LANGUAGE GADTs #-}
56{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -294,7 +295,7 @@ data ParamOtherSchema = ParamOtherSchema
294295 -- Default value is csv.
295296 , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
296297
297− , _paramOtherSchemaCommon :: SchemaCommon (SwaggerType Param) Items
298+ , _paramOtherSchemaCommon :: SchemaCommon Param Items
298299 } deriving (Eq, Show, Generic)
299300
300301data SwaggerType t where
@@ -370,7 +371,7 @@ data Schema = Schema
370371 , _schemaMaxProperties :: Maybe Integer
371372 , _schemaMinProperties :: Maybe Integer
372373
373− , _schemaSchemaCommon :: SchemaCommon (SwaggerType Schema) SchemaItems
374+ , _schemaSchemaCommon :: SchemaCommon Schema SchemaItems
374375 } deriving (Eq, Show, Generic)
375376
376377data SchemaItems
@@ -378,7 +379,7 @@ data SchemaItems
378379 | SchemaItemsArray [Referenced Schema]
379380 deriving (Eq, Show)
380381
381−data SchemaCommon typeDomain items = SchemaCommon
382+data SchemaCommon t items = SchemaCommon
382383 { -- | Declares the value of the parameter that the server will use if none is provided,
383384 -- for example a @"count"@ to control the number of results per page might default to @100@
384385 -- if not supplied by the client in the request.
@@ -386,7 +387,7 @@ data SchemaCommon typeDomain items = SchemaCommon
386387 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
387388 _schemaCommonDefault :: Maybe Value
388389
389− , _schemaCommonType :: typeDomain
390+ , _schemaCommonType :: SwaggerType t
390391 , _schemaCommonFormat :: Maybe Format
391392 , _schemaCommonItems :: Maybe items
392393 , _schemaCommonMaximum :: Maybe Scientific
@@ -436,7 +437,7 @@ data Items = Items
436437 -- Default value is @'ItemsCollectionCSV'@.
437438 _itemsCollectionFormat :: Maybe (CollectionFormat Items)
438439
439− , _itemsCommon :: SchemaCommon (SwaggerType Items) Items
440+ , _itemsCommon :: SchemaCommon Items Items
440441 } deriving (Eq, Show, Generic)
441442
442443-- | A container for the expected responses of an operation.
@@ -486,7 +487,7 @@ data Header = Header
486487 -- Default value is @'ItemsCollectionCSV'@.
487488 , _headerCollectionFormat :: Maybe (CollectionFormat Items)
488489
489− , _headerCommon :: SchemaCommon (SwaggerType Items) Items
490+ , _headerCommon :: SchemaCommon Items Items
490491 } deriving (Eq, Show, Generic)
491492
492493data Example = Example { getExample :: Map MediaType Value }
@@ -608,7 +609,7 @@ instance Monoid Schema where
608609 mempty = genericMempty
609610 mappend = genericMappend
610611
611−instance SwaggerMonoid t => Monoid (SchemaCommon t i) where
612+instance Monoid (SchemaCommon t i) where
612613 mempty = genericMempty
613614 mappend = genericMappend
614615
@@ -644,7 +645,7 @@ instance SwaggerMonoid Info
644645instance SwaggerMonoid Paths
645646instance SwaggerMonoid PathItem
646647instance SwaggerMonoid Schema
647−instance SwaggerMonoid t => SwaggerMonoid (SchemaCommon t i)
648+instance SwaggerMonoid (SchemaCommon t i)
648649instance SwaggerMonoid Param
649650instance SwaggerMonoid ParamOtherSchema
650651instance SwaggerMonoid Responses
@@ -716,11 +717,11 @@ deriveJSON' ''Contact
716717deriveJSON' ''License
717718deriveJSON (jsonPrefix "ApiKey") ''ApiKeyLocation
718719deriveJSON (jsonPrefix "apiKey") ''ApiKeyParams
719−deriveJSON' ''SchemaCommon
720720deriveJSONDefault ''Scheme
721721deriveJSON' ''Tag
722722deriveJSON' ''ExternalDocs
723723
724+deriveToJSON' ''SchemaCommon
724725deriveToJSON' ''Operation
725726deriveToJSON' ''Response
726727deriveToJSON' ''PathItem
@@ -979,3 +980,5 @@ instance FromJSON (CollectionFormat Param) where
979980instance FromJSON (CollectionFormat Items) where
980981 parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
981982
983+instance (FromJSON (SwaggerType t), FromJSON i) => FromJSON (SchemaCommon t i) where
984+ parseJSON = genericParseJSON (jsonPrefix "SchemaCommon")
src/Data/Swagger/Lens.hs+5−5
@@ -60,13 +60,13 @@ instance HasDescription ExternalDocs (Maybe Text) where description = external
6060class HasSchemaCommon s t i | s -> t i where
6161 schemaCommon :: Lens' s (SchemaCommon t i)
6262
63−instance HasSchemaCommon Schema (SwaggerType Schema) SchemaItems where schemaCommon = schemaSchemaCommon
64−instance HasSchemaCommon ParamOtherSchema (SwaggerType Param) Items where schemaCommon = paramOtherSchemaCommon
65−instance HasSchemaCommon Items (SwaggerType Items) Items where schemaCommon = itemsCommon
66−instance HasSchemaCommon Header (SwaggerType Items) Items where schemaCommon = headerCommon
63+instance HasSchemaCommon Schema Schema SchemaItems where schemaCommon = schemaSchemaCommon
64+instance HasSchemaCommon ParamOtherSchema Param Items where schemaCommon = paramOtherSchemaCommon
65+instance HasSchemaCommon Items Items Items where schemaCommon = itemsCommon
66+instance HasSchemaCommon Header Items Items where schemaCommon = headerCommon
6767instance HasSchemaCommon (SchemaCommon t i) t i where schemaCommon = id
6868
69−schemaType :: HasSchemaCommon s t i => Lens' s t
69+schemaType :: HasSchemaCommon s t i => Lens' s (SwaggerType t)
7070schemaType = schemaCommon.schemaCommonType
7171
7272schemaFormat :: HasSchemaCommon s t i => Lens' s (Maybe Format)