git.iko.soy/typeable/openapi3
on master help sign in
Simplify SchemaCommon a tiny bit
e1fc9e6Nickolay Kudasov
src/Data/Swagger/Internal.hs+12−9
@@ -1,5 +1,6 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveTraversable #-}
2{-# LANGUAGE DeriveTraversable #-}
3+{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE GADTs #-}
5{-# LANGUAGE GADTs #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -294,7 +295,7 @@ data ParamOtherSchema = ParamOtherSchema
294 -- Default value is csv.
295 -- Default value is csv.
295 , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
296 , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
296
297
297− , _paramOtherSchemaCommon :: SchemaCommon (SwaggerType Param) Items
298+ , _paramOtherSchemaCommon :: SchemaCommon Param Items
298 } deriving (Eq, Show, Generic)
299 } deriving (Eq, Show, Generic)
299
300
300data SwaggerType t where
301data SwaggerType t where
@@ -370,7 +371,7 @@ data Schema = Schema
370 , _schemaMaxProperties :: Maybe Integer
371 , _schemaMaxProperties :: Maybe Integer
371 , _schemaMinProperties :: Maybe Integer
372 , _schemaMinProperties :: Maybe Integer
372
373
373− , _schemaSchemaCommon :: SchemaCommon (SwaggerType Schema) SchemaItems
374+ , _schemaSchemaCommon :: SchemaCommon Schema SchemaItems
374 } deriving (Eq, Show, Generic)
375 } deriving (Eq, Show, Generic)
375
376
376data SchemaItems
377data SchemaItems
@@ -378,7 +379,7 @@ data SchemaItems
378 | SchemaItemsArray [Referenced Schema]
379 | SchemaItemsArray [Referenced Schema]
379 deriving (Eq, Show)
380 deriving (Eq, Show)
380
381
381−data SchemaCommon typeDomain items = SchemaCommon
382+data SchemaCommon t items = SchemaCommon
382 { -- | Declares the value of the parameter that the server will use if none is provided,
383 { -- | Declares the value of the parameter that the server will use if none is provided,
383 -- for example a @"count"@ to control the number of results per page might default to @100@
384 -- for example a @"count"@ to control the number of results per page might default to @100@
384 -- if not supplied by the client in the request.
385 -- if not supplied by the client in the request.
@@ -386,7 +387,7 @@ data SchemaCommon typeDomain items = SchemaCommon
386 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
387 -- Unlike JSON Schema this value MUST conform to the defined type for this parameter.
387 _schemaCommonDefault :: Maybe Value
388 _schemaCommonDefault :: Maybe Value
388
389
389− , _schemaCommonType :: typeDomain
390+ , _schemaCommonType :: SwaggerType t
390 , _schemaCommonFormat :: Maybe Format
391 , _schemaCommonFormat :: Maybe Format
391 , _schemaCommonItems :: Maybe items
392 , _schemaCommonItems :: Maybe items
392 , _schemaCommonMaximum :: Maybe Scientific
393 , _schemaCommonMaximum :: Maybe Scientific
@@ -436,7 +437,7 @@ data Items = Items
436 -- Default value is @'ItemsCollectionCSV'@.
437 -- Default value is @'ItemsCollectionCSV'@.
437 _itemsCollectionFormat :: Maybe (CollectionFormat Items)
438 _itemsCollectionFormat :: Maybe (CollectionFormat Items)
438
439
439− , _itemsCommon :: SchemaCommon (SwaggerType Items) Items
440+ , _itemsCommon :: SchemaCommon Items Items
440 } deriving (Eq, Show, Generic)
441 } deriving (Eq, Show, Generic)
441
442
442-- | A container for the expected responses of an operation.
443-- | A container for the expected responses of an operation.
@@ -486,7 +487,7 @@ data Header = Header
486 -- Default value is @'ItemsCollectionCSV'@.
487 -- Default value is @'ItemsCollectionCSV'@.
487 , _headerCollectionFormat :: Maybe (CollectionFormat Items)
488 , _headerCollectionFormat :: Maybe (CollectionFormat Items)
488
489
489− , _headerCommon :: SchemaCommon (SwaggerType Items) Items
490+ , _headerCommon :: SchemaCommon Items Items
490 } deriving (Eq, Show, Generic)
491 } deriving (Eq, Show, Generic)
491
492
492data Example = Example { getExample :: Map MediaType Value }
493data Example = Example { getExample :: Map MediaType Value }
@@ -608,7 +609,7 @@ instance Monoid Schema where
608 mempty = genericMempty
609 mempty = genericMempty
609 mappend = genericMappend
610 mappend = genericMappend
610
611
611−instance SwaggerMonoid t => Monoid (SchemaCommon t i) where
612+instance Monoid (SchemaCommon t i) where
612 mempty = genericMempty
613 mempty = genericMempty
613 mappend = genericMappend
614 mappend = genericMappend
614
615
@@ -644,7 +645,7 @@ instance SwaggerMonoid Info
644instance SwaggerMonoid Paths
645instance SwaggerMonoid Paths
645instance SwaggerMonoid PathItem
646instance SwaggerMonoid PathItem
646instance SwaggerMonoid Schema
647instance SwaggerMonoid Schema
647−instance SwaggerMonoid t => SwaggerMonoid (SchemaCommon t i)
648+instance SwaggerMonoid (SchemaCommon t i)
648instance SwaggerMonoid Param
649instance SwaggerMonoid Param
649instance SwaggerMonoid ParamOtherSchema
650instance SwaggerMonoid ParamOtherSchema
650instance SwaggerMonoid Responses
651instance SwaggerMonoid Responses
@@ -716,11 +717,11 @@ deriveJSON' ''Contact
716deriveJSON' ''License
717deriveJSON' ''License
717deriveJSON (jsonPrefix "ApiKey") ''ApiKeyLocation
718deriveJSON (jsonPrefix "ApiKey") ''ApiKeyLocation
718deriveJSON (jsonPrefix "apiKey") ''ApiKeyParams
719deriveJSON (jsonPrefix "apiKey") ''ApiKeyParams
719−deriveJSON' ''SchemaCommon
720deriveJSONDefault ''Scheme
720deriveJSONDefault ''Scheme
721deriveJSON' ''Tag
721deriveJSON' ''Tag
722deriveJSON' ''ExternalDocs
722deriveJSON' ''ExternalDocs
723
723
724+deriveToJSON' ''SchemaCommon
724deriveToJSON' ''Operation
725deriveToJSON' ''Operation
725deriveToJSON' ''Response
726deriveToJSON' ''Response
726deriveToJSON' ''PathItem
727deriveToJSON' ''PathItem
@@ -979,3 +980,5 @@ instance FromJSON (CollectionFormat Param) where
979instance FromJSON (CollectionFormat Items) where
980instance FromJSON (CollectionFormat Items) where
980 parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
981 parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
981
982
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
60class HasSchemaCommon s t i | s -> t i where
60class HasSchemaCommon s t i | s -> t i where
61 schemaCommon :: Lens' s (SchemaCommon t i)
61 schemaCommon :: Lens' s (SchemaCommon t i)
62
62
63−instance HasSchemaCommon Schema (SwaggerType Schema) SchemaItems where schemaCommon = schemaSchemaCommon
63+instance HasSchemaCommon Schema Schema SchemaItems where schemaCommon = schemaSchemaCommon
64−instance HasSchemaCommon ParamOtherSchema (SwaggerType Param) Items where schemaCommon = paramOtherSchemaCommon
64+instance HasSchemaCommon ParamOtherSchema Param Items where schemaCommon = paramOtherSchemaCommon
65−instance HasSchemaCommon Items (SwaggerType Items) Items where schemaCommon = itemsCommon
65+instance HasSchemaCommon Items Items Items where schemaCommon = itemsCommon
66−instance HasSchemaCommon Header (SwaggerType Items) Items where schemaCommon = headerCommon
66+instance HasSchemaCommon Header Items Items where schemaCommon = headerCommon
67instance HasSchemaCommon (SchemaCommon t i) t i where schemaCommon = id
67instance HasSchemaCommon (SchemaCommon t i) t i where schemaCommon = id
68
68
69−schemaType :: HasSchemaCommon s t i => Lens' s t
69+schemaType :: HasSchemaCommon s t i => Lens' s (SwaggerType t)
70schemaType = schemaCommon.schemaCommonType
70schemaType = schemaCommon.schemaCommonType
71
71
72schemaFormat :: HasSchemaCommon s t i => Lens' s (Maybe Format)
72schemaFormat :: HasSchemaCommon s t i => Lens' s (Maybe Format)