git.iko.soy/typeable/swagger2
on master help sign in
Merge pull request #24 from GetShopTV/swagger-items
e1b45b1Nickolay Kudasov
src/Data/Swagger.hs+1−1
@@ -45,7 +45,7 @@ module Data.Swagger (
45 -- * Schemas
45 -- * Schemas
46 ParamSchema(..),
46 ParamSchema(..),
47 Schema(..),
47 Schema(..),
48− SchemaItems(..),
48+ SwaggerItems(..),
49 Xml(..),
49 Xml(..),
50
50
51 -- * Responses
51 -- * Responses
src/Data/Swagger/Internal.hs+53−27
@@ -10,6 +10,7 @@
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE StandaloneDeriving #-}
11{-# LANGUAGE StandaloneDeriving #-}
12{-# LANGUAGE TemplateHaskell #-}
12{-# LANGUAGE TemplateHaskell #-}
13+{-# LANGUAGE UndecidableInstances #-}
13module Data.Swagger.Internal where
14module Data.Swagger.Internal where
14
15
15import Control.Applicative
16import Control.Applicative
@@ -324,9 +325,33 @@ data ParamOtherSchema = ParamOtherSchema
324 -- Default value is csv.
325 -- Default value is csv.
325 , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
326 , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
326
327
327− , _paramOtherSchemaParamSchema :: ParamSchema ParamOtherSchema Items
328+ , _paramOtherSchemaParamSchema :: ParamSchema ParamOtherSchema
328 } deriving (Eq, Show, Generic, Data, Typeable)
329 } deriving (Eq, Show, Generic, Data, Typeable)
329
330
331+data SwaggerItems t where
332+ SwaggerItemsPrimitive :: Items -> SwaggerItems t
333+ SwaggerItemsObject :: Referenced Schema -> SwaggerItems Schema
334+ SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems Schema
335+
336+deriving instance Eq (SwaggerItems t)
337+deriving instance Show (SwaggerItems t)
338+deriving instance Typeable (SwaggerItems t)
339+
340+swaggerItemsPrimitiveConstr :: Constr
341+swaggerItemsPrimitiveConstr = mkConstr swaggerItemsDataType "SwaggerItemsPrimitive" [] Prefix
342+
343+swaggerItemsDataType :: DataType
344+swaggerItemsDataType = mkDataType "Data.Swagger.SwaggerItems" [swaggerItemsPrimitiveConstr]
345+
346+instance {-# OVERLAPPABLE #-} Typeable t => Data (SwaggerItems t) where
347+ gunfold k z c = case constrIndex c of
348+ 1 -> k (z SwaggerItemsPrimitive)
349+ _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type (SwaggerItems t)."
350+ toConstr _ = swaggerItemsPrimitiveConstr
351+ dataTypeOf _ = swaggerItemsDataType
352+
353+deriving instance Data (SwaggerItems Schema)
354+
330data SwaggerType t where
355data SwaggerType t where
331 SwaggerString :: SwaggerType t
356 SwaggerString :: SwaggerType t
332 SwaggerNumber :: SwaggerType t
357 SwaggerNumber :: SwaggerType t
@@ -453,15 +478,10 @@ data Schema = Schema
453 , _schemaMaxProperties :: Maybe Integer
478 , _schemaMaxProperties :: Maybe Integer
454 , _schemaMinProperties :: Maybe Integer
479 , _schemaMinProperties :: Maybe Integer
455
480
456− , _schemaParamSchema :: ParamSchema Schema SchemaItems
481+ , _schemaParamSchema :: ParamSchema Schema
457 } deriving (Eq, Show, Generic, Data, Typeable)
482 } deriving (Eq, Show, Generic, Data, Typeable)
458
483
459−data SchemaItems
460− = SchemaItemsObject (Referenced Schema)
461− | SchemaItemsArray [Referenced Schema]
462− deriving (Eq, Show, Generic, Data, Typeable)
463−
464−data ParamSchema t items = ParamSchema
484+data ParamSchema t = ParamSchema
465 { -- | Declares the value of the parameter that the server will use if none is provided,
485 { -- | Declares the value of the parameter that the server will use if none is provided,
466 -- for example a @"count"@ to control the number of results per page might default to @100@
486 -- for example a @"count"@ to control the number of results per page might default to @100@
467 -- if not supplied by the client in the request.
487 -- if not supplied by the client in the request.
@@ -471,7 +491,7 @@ data ParamSchema t items = ParamSchema
471
491
472 , _paramSchemaType :: SwaggerType t
492 , _paramSchemaType :: SwaggerType t
473 , _paramSchemaFormat :: Maybe Format
493 , _paramSchemaFormat :: Maybe Format
474− , _paramSchemaItems :: Maybe items
494+ , _paramSchemaItems :: Maybe (SwaggerItems t)
475 , _paramSchemaMaximum :: Maybe Scientific
495 , _paramSchemaMaximum :: Maybe Scientific
476 , _paramSchemaExclusiveMaximum :: Maybe Bool
496 , _paramSchemaExclusiveMaximum :: Maybe Bool
477 , _paramSchemaMinimum :: Maybe Scientific
497 , _paramSchemaMinimum :: Maybe Scientific
@@ -486,7 +506,7 @@ data ParamSchema t items = ParamSchema
486 , _paramSchemaMultipleOf :: Maybe Scientific
506 , _paramSchemaMultipleOf :: Maybe Scientific
487 } deriving (Eq, Show, Generic, Typeable)
507 } deriving (Eq, Show, Generic, Typeable)
488
508
489−deriving instance (Data t, Data (SwaggerType t), Data i) => Data (ParamSchema t i)
509+deriving instance (Data t, Data (SwaggerType t), Data (SwaggerItems t)) => Data (ParamSchema t)
490
510
491data Xml = Xml
511data Xml = Xml
492 { -- | Replaces the name of the element/attribute used for the described schema property.
512 { -- | Replaces the name of the element/attribute used for the described schema property.
@@ -521,7 +541,7 @@ data Items = Items
521 -- Default value is @'ItemsCollectionCSV'@.
541 -- Default value is @'ItemsCollectionCSV'@.
522 _itemsCollectionFormat :: Maybe (CollectionFormat Items)
542 _itemsCollectionFormat :: Maybe (CollectionFormat Items)
523
543
524− , _itemsParamSchema :: ParamSchema Items Items
544+ , _itemsParamSchema :: ParamSchema Items
525 } deriving (Eq, Show, Generic, Data, Typeable)
545 } deriving (Eq, Show, Generic, Data, Typeable)
526
546
527-- | A container for the expected responses of an operation.
547-- | A container for the expected responses of an operation.
@@ -571,7 +591,7 @@ data Header = Header
571 -- Default value is @'ItemsCollectionCSV'@.
591 -- Default value is @'ItemsCollectionCSV'@.
572 , _headerCollectionFormat :: Maybe (CollectionFormat Items)
592 , _headerCollectionFormat :: Maybe (CollectionFormat Items)
573
593
574− , _headerParamSchema :: ParamSchema Header Items
594+ , _headerParamSchema :: ParamSchema Header
575 } deriving (Eq, Show, Generic, Data, Typeable)
595 } deriving (Eq, Show, Generic, Data, Typeable)
576
596
577data Example = Example { getExample :: Map MediaType Value }
597data Example = Example { getExample :: Map MediaType Value }
@@ -706,7 +726,7 @@ instance Monoid Schema where
706 mempty = genericMempty
726 mempty = genericMempty
707 mappend = genericMappend
727 mappend = genericMappend
708
728
709−instance Monoid (ParamSchema t i) where
729+instance Monoid (ParamSchema t) where
710 mempty = genericMempty
730 mempty = genericMempty
711 mappend = genericMappend
731 mappend = genericMappend
712
732
@@ -742,7 +762,7 @@ instance SwaggerMonoid Info
742instance SwaggerMonoid Paths
762instance SwaggerMonoid Paths
743instance SwaggerMonoid PathItem
763instance SwaggerMonoid PathItem
744instance SwaggerMonoid Schema
764instance SwaggerMonoid Schema
745−instance SwaggerMonoid (ParamSchema t i)
765+instance SwaggerMonoid (ParamSchema t)
746instance SwaggerMonoid Param
766instance SwaggerMonoid Param
747instance SwaggerMonoid ParamOtherSchema
767instance SwaggerMonoid ParamOtherSchema
748instance SwaggerMonoid Responses
768instance SwaggerMonoid Responses
@@ -870,6 +890,11 @@ instance ToJSON Header where
870instance ToJSON Items where
890instance ToJSON Items where
871 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "items")
891 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "items")
872
892
893+instance ToJSON (SwaggerItems t) where
894+ toJSON (SwaggerItemsPrimitive x) = toJSON x
895+ toJSON (SwaggerItemsObject x) = toJSON x
896+ toJSON (SwaggerItemsArray x) = toJSON x
897+
873instance ToJSON Host where
898instance ToJSON Host where
874 toJSON (Host host mport) = toJSON $
899 toJSON (Host host mport) = toJSON $
875 case mport of
900 case mport of
@@ -892,10 +917,6 @@ instance ToJSON ParamAnySchema where
892instance ToJSON ParamOtherSchema where
917instance ToJSON ParamOtherSchema where
893 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "paramOtherSchema")
918 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "paramOtherSchema")
894
919
895−instance ToJSON SchemaItems where
896− toJSON (SchemaItemsObject x) = toJSON x
897− toJSON (SchemaItemsArray xs) = toJSON xs
898−
899instance ToJSON Responses where
920instance ToJSON Responses where
900 toJSON (Responses def rs) = omitEmpties $
921 toJSON (Responses def rs) = omitEmpties $
901 toJSON (hashMapMapKeys show rs) <+> object [ "default" .= def ]
922 toJSON (hashMapMapKeys show rs) <+> object [ "default" .= def ]
@@ -940,7 +961,7 @@ instance ToJSON (CollectionFormat t) where
940 toJSON CollectionPipes = "pipes"
961 toJSON CollectionPipes = "pipes"
941 toJSON CollectionMulti = "multi"
962 toJSON CollectionMulti = "multi"
942
963
943−instance ToJSON i => ToJSON (ParamSchema t i) where
964+instance ToJSON (ParamSchema t) where
944 toJSON = genericToJSON (jsonPrefix "paramSchema")
965 toJSON = genericToJSON (jsonPrefix "paramSchema")
945
966
946-- =======================================================================
967-- =======================================================================
@@ -1003,6 +1024,14 @@ instance FromJSON Header where
1003instance FromJSON Items where
1024instance FromJSON Items where
1004 parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "items")
1025 parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "items")
1005
1026
1027+instance {-# OVERLAPPABLE #-} FromJSON (SwaggerItems t) where
1028+ parseJSON js = SwaggerItemsPrimitive <$> parseJSON js
1029+
1030+instance {-# OVERLAPPING #-} FromJSON (SwaggerItems Schema) where
1031+ parseJSON js@(Object _) = SwaggerItemsObject <$> parseJSON js
1032+ parseJSON js@(Array _) = SwaggerItemsArray <$> parseJSON js
1033+ parseJSON _ = empty
1034+
1006instance FromJSON Host where
1035instance FromJSON Host where
1007 parseJSON (String s) =
1036 parseJSON (String s) =
1008 case fromInteger <$> readMaybe portStr of
1037 case fromInteger <$> readMaybe portStr of
@@ -1035,11 +1064,6 @@ instance FromJSON ParamAnySchema where
1035instance FromJSON ParamOtherSchema where
1064instance FromJSON ParamOtherSchema where
1036 parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "paramOtherSchema")
1065 parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "paramOtherSchema")
1037
1066
1038−instance FromJSON SchemaItems where
1039− parseJSON js@(Object _) = SchemaItemsObject <$> parseJSON js
1040− parseJSON js@(Array _) = SchemaItemsArray <$> parseJSON js
1041− parseJSON _ = empty
1042−
1043instance FromJSON Responses where
1067instance FromJSON Responses where
1044 parseJSON (Object o) = Responses
1068 parseJSON (Object o) = Responses
1045 <$> o .:? "default"
1069 <$> o .:? "default"
@@ -1101,8 +1125,10 @@ instance FromJSON (CollectionFormat Param) where
1101instance FromJSON (CollectionFormat Items) where
1125instance FromJSON (CollectionFormat Items) where
1102 parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
1126 parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
1103
1127
1104−-- NOTE: The constraint @FromJSON (SwaggerType t)@ is necessary here!
1128+-- NOTE: The constraints @FromJSON (SwaggerType t)@ and
1129+-- @FromJSON (SwaggerItems t)@ are necessary here!
1105-- Without the constraint the general instance will be used
1130-- Without the constraint the general instance will be used
1106−-- that only accepts common types (i.e. NOT object, null or file).
1131+-- that only accepts common types (i.e. NOT object, null or file)
1132+-- and primitive array items.
1107−instance (FromJSON (SwaggerType t), FromJSON i) => FromJSON (ParamSchema t i) where
1133+instance (FromJSON (SwaggerType t), FromJSON (SwaggerItems t)) => FromJSON (ParamSchema t) where
1108 parseJSON = genericParseJSON (jsonPrefix "ParamSchema")
1134 parseJSON = genericParseJSON (jsonPrefix "ParamSchema")
src/Data/Swagger/Internal/ParamSchema.hs+8−8
@@ -63,8 +63,8 @@ import Data.Swagger.SchemaOptions
63-- @
63-- @
64class ToParamSchema a where
64class ToParamSchema a where
65 -- | Convert a type into a plain parameter schema.
65 -- | Convert a type into a plain parameter schema.
66− toParamSchema :: proxy a -> ParamSchema t i
66+ toParamSchema :: proxy a -> ParamSchema t
67− default toParamSchema :: (Generic a, GToParamSchema (Rep a)) => proxy a -> ParamSchema t i
67+ default toParamSchema :: (Generic a, GToParamSchema (Rep a)) => proxy a -> ParamSchema t
68 toParamSchema = genericToParamSchema defaultSchemaOptions
68 toParamSchema = genericToParamSchema defaultSchemaOptions
69
69
70instance {-# OVERLAPPING #-} ToParamSchema String where
70instance {-# OVERLAPPING #-} ToParamSchema String where
@@ -89,7 +89,7 @@ instance ToParamSchema Word32 where toParamSchema = toParamSchemaBoundedIntegral
89instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
89instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
90
90
91-- | Default plain schema for @'Bounded'@, @'Integral'@ types.
91-- | Default plain schema for @'Bounded'@, @'Integral'@ types.
92−toParamSchemaBoundedIntegral :: forall proxy a t i. (Bounded a, Integral a) => proxy a -> ParamSchema t i
92+toParamSchemaBoundedIntegral :: forall proxy a t. (Bounded a, Integral a) => proxy a -> ParamSchema t
93toParamSchemaBoundedIntegral _ = mempty
93toParamSchemaBoundedIntegral _ = mempty
94 & schemaType .~ SwaggerInteger
94 & schemaType .~ SwaggerInteger
95 & schemaMinimum ?~ fromInteger (toInteger (minBound :: a))
95 & schemaMinimum ?~ fromInteger (toInteger (minBound :: a))
@@ -110,7 +110,7 @@ instance ToParamSchema Double where
110instance ToParamSchema Float where
110instance ToParamSchema Float where
111 toParamSchema _ = mempty & schemaType .~ SwaggerNumber
111 toParamSchema _ = mempty & schemaType .~ SwaggerNumber
112
112
113−timeParamSchema :: String -> ParamSchema t i
113+timeParamSchema :: String -> ParamSchema t
114timeParamSchema format = mempty
114timeParamSchema format = mempty
115 & schemaType .~ SwaggerString
115 & schemaType .~ SwaggerString
116 & schemaFormat ?~ T.pack format
116 & schemaFormat ?~ T.pack format
@@ -158,7 +158,7 @@ instance ToParamSchema a => ToParamSchema (Last a) where toParamSchema _ = to
158instance ToParamSchema a => ToParamSchema (Dual a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
158instance ToParamSchema a => ToParamSchema (Dual a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
159
159
160-- |
160-- |
161−-- >>> encode (toParamSchema (Proxy :: Proxy ()) :: ParamSchema t Items)
161+-- >>> encode $ toParamSchema (Proxy :: Proxy ())
162-- "{\"type\":\"string\",\"enum\":[\"_\"]}"
162-- "{\"type\":\"string\",\"enum\":[\"_\"]}"
163instance ToParamSchema () where
163instance ToParamSchema () where
164 toParamSchema _ = mempty
164 toParamSchema _ = mempty
@@ -166,11 +166,11 @@ instance ToParamSchema () where
166 & schemaEnum ?~ ["_"]
166 & schemaEnum ?~ ["_"]
167
167
168-- | A configurable generic @'ParamSchema'@ creator.
168-- | A configurable generic @'ParamSchema'@ creator.
169−genericToParamSchema :: forall proxy a t i. (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamSchema t i
169+genericToParamSchema :: forall proxy a t. (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamSchema t
170genericToParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy (Rep a)) mempty
170genericToParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy (Rep a)) mempty
171
171
172class GToParamSchema (f :: * -> *) where
172class GToParamSchema (f :: * -> *) where
173− gtoParamSchema :: SchemaOptions -> proxy f -> ParamSchema t i -> ParamSchema t i
173+ gtoParamSchema :: SchemaOptions -> proxy f -> ParamSchema t -> ParamSchema t
174
174
175instance GToParamSchema f => GToParamSchema (D1 d f) where
175instance GToParamSchema f => GToParamSchema (D1 d f) where
176 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
176 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
@@ -185,7 +185,7 @@ instance (GEnumParamSchema f, GEnumParamSchema g) => GToParamSchema (f :+: g) wh
185 gtoParamSchema opts _ = genumParamSchema opts (Proxy :: Proxy (f :+: g))
185 gtoParamSchema opts _ = genumParamSchema opts (Proxy :: Proxy (f :+: g))
186
186
187class GEnumParamSchema (f :: * -> *) where
187class GEnumParamSchema (f :: * -> *) where
188− genumParamSchema :: SchemaOptions -> proxy f -> ParamSchema t i -> ParamSchema t i
188+ genumParamSchema :: SchemaOptions -> proxy f -> ParamSchema t -> ParamSchema t
189
189
190instance (GEnumParamSchema f, GEnumParamSchema g) => GEnumParamSchema (f :+: g) where
190instance (GEnumParamSchema f, GEnumParamSchema g) => GEnumParamSchema (f :+: g) where
191 genumParamSchema opts _ = genumParamSchema opts (Proxy :: Proxy f) . genumParamSchema opts (Proxy :: Proxy g)
191 genumParamSchema opts _ = genumParamSchema opts (Proxy :: Proxy f) . genumParamSchema opts (Proxy :: Proxy g)
src/Data/Swagger/Internal/Schema.hs+6−6
@@ -266,7 +266,7 @@ instance {-# OVERLAPPABLE #-} ToSchema a => ToSchema [a] where
266 ref <- declareSchemaRef (Proxy :: Proxy a)
266 ref <- declareSchemaRef (Proxy :: Proxy a)
267 return $ unnamed $ mempty
267 return $ unnamed $ mempty
268 & schemaType .~ SwaggerArray
268 & schemaType .~ SwaggerArray
269− & schemaItems ?~ SchemaItemsObject ref
269+ & schemaItems ?~ SwaggerItemsObject ref
270
270
271instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
271instance {-# OVERLAPPING #-} ToSchema String where declareNamedSchema = plain . paramSchemaToSchema
272instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
272instance ToSchema Bool where declareNamedSchema = plain . paramSchemaToSchema
@@ -449,7 +449,7 @@ instance (Selector s, GToSchema f) => GToSchema (C1 c (S1 s f)) where
449 | otherwise = do
449 | otherwise = do
450 (_, schema) <- recordSchema
450 (_, schema) <- recordSchema
451 case schema ^. schemaItems of
451 case schema ^. schemaItems of
452− Just (SchemaItemsArray [_]) -> fieldSchema
452+ Just (SwaggerItemsArray [_]) -> fieldSchema
453 _ -> pure (unnamed schema)
453 _ -> pure (unnamed schema)
454 where
454 where
455 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
455 recordSchema = gdeclareNamedSchema opts (Proxy :: Proxy (S1 s f)) s
@@ -474,10 +474,10 @@ gdeclareSchemaRef opts proxy = do
474 return $ Ref (Reference name)
474 return $ Ref (Reference name)
475 _ -> Inline <$> gdeclareSchema opts proxy
475 _ -> Inline <$> gdeclareSchema opts proxy
476
476
477−appendItem :: Referenced Schema -> Maybe SchemaItems -> Maybe SchemaItems
477+appendItem :: Referenced Schema -> Maybe (SwaggerItems Schema) -> Maybe (SwaggerItems Schema)
478−appendItem x Nothing = Just (SchemaItemsArray [x])
478+appendItem x Nothing = Just (SwaggerItemsArray [x])
479−appendItem x (Just (SchemaItemsArray xs)) = Just (SchemaItemsArray (x:xs))
479+appendItem x (Just (SwaggerItemsArray xs)) = Just (SwaggerItemsArray (x:xs))
480−appendItem _ _ = error "GToSchema.appendItem: cannot append to SchemaItemsObject"
480+appendItem _ _ = error "GToSchema.appendItem: cannot append to SwaggerItemsObject"
481
481
482withFieldSchema :: forall proxy s f. (Selector s, GToSchema f) =>
482withFieldSchema :: forall proxy s f. (Selector s, GToSchema f) =>
483 SchemaOptions -> proxy s f -> Bool -> Schema -> Declare Definitions Schema
483 SchemaOptions -> proxy s f -> Bool -> Schema -> Declare Definitions Schema
src/Data/Swagger/Lens.hs+26−25
@@ -1,5 +1,6 @@
1{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FunctionalDependencies #-}
2{-# LANGUAGE FunctionalDependencies #-}
3+{-# LANGUAGE GADTs #-}
3{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE TemplateHaskell #-}
5{-# LANGUAGE TemplateHaskell #-}
5module Data.Swagger.Lens where
6module Data.Swagger.Lens where
@@ -43,8 +44,8 @@ makeLenses ''Items
43makeLenses ''Header
44makeLenses ''Header
44-- ** 'Schema' lenses
45-- ** 'Schema' lenses
45makeLenses ''Schema
46makeLenses ''Schema
46−-- ** 'SchemaItems' prisms
47+-- ** 'SwaggerItems' prisms
47−makePrisms ''SchemaItems
48+makePrisms ''SwaggerItems
48-- ** 'ParamSchema' lenses
49-- ** 'ParamSchema' lenses
49makeLenses ''ParamSchema
50makeLenses ''ParamSchema
50-- ** 'Xml' lenses
51-- ** 'Xml' lenses
@@ -80,60 +81,60 @@ instance HasDescription Schema (Maybe Text) where description = schemaDe
80instance HasDescription SecurityScheme (Maybe Text) where description = securitySchemeDescription
81instance HasDescription SecurityScheme (Maybe Text) where description = securitySchemeDescription
81instance HasDescription ExternalDocs (Maybe Text) where description = externalDocsDescription
82instance HasDescription ExternalDocs (Maybe Text) where description = externalDocsDescription
82
83
83−class HasParamSchema s t i | s -> t i where
84+class HasParamSchema s t | s -> t where
84− parameterSchema :: Lens' s (ParamSchema t i)
85+ parameterSchema :: Lens' s (ParamSchema t)
85
86
86−instance HasParamSchema Schema Schema SchemaItems where parameterSchema = schemaParamSchema
87+instance HasParamSchema Schema Schema where parameterSchema = schemaParamSchema
87−instance HasParamSchema ParamOtherSchema ParamOtherSchema Items where parameterSchema = paramOtherSchemaParamSchema
88+instance HasParamSchema ParamOtherSchema ParamOtherSchema where parameterSchema = paramOtherSchemaParamSchema
88−instance HasParamSchema Items Items Items where parameterSchema = itemsParamSchema
89+instance HasParamSchema Items Items where parameterSchema = itemsParamSchema
89−instance HasParamSchema Header Header Items where parameterSchema = headerParamSchema
90+instance HasParamSchema Header Header where parameterSchema = headerParamSchema
90−instance HasParamSchema (ParamSchema t i) t i where parameterSchema = id
91+instance HasParamSchema (ParamSchema t) t where parameterSchema = id
91
92
92−schemaType :: HasParamSchema s t i => Lens' s (SwaggerType t)
93+schemaType :: HasParamSchema s t => Lens' s (SwaggerType t)
93schemaType = parameterSchema.paramSchemaType
94schemaType = parameterSchema.paramSchemaType
94
95
95−schemaFormat :: HasParamSchema s t i => Lens' s (Maybe Format)
96+schemaFormat :: HasParamSchema s t => Lens' s (Maybe Format)
96schemaFormat = parameterSchema.paramSchemaFormat
97schemaFormat = parameterSchema.paramSchemaFormat
97
98
98−schemaItems :: HasParamSchema s t i => Lens' s (Maybe i)
99+schemaItems :: HasParamSchema s t => Lens' s (Maybe (SwaggerItems t))
99schemaItems = parameterSchema.paramSchemaItems
100schemaItems = parameterSchema.paramSchemaItems
100
101
101−schemaDefault :: HasParamSchema s t i => Lens' s (Maybe Value)
102+schemaDefault :: HasParamSchema s t => Lens' s (Maybe Value)
102schemaDefault = parameterSchema.paramSchemaDefault
103schemaDefault = parameterSchema.paramSchemaDefault
103
104
104−schemaMaximum :: HasParamSchema s t i => Lens' s (Maybe Scientific)
105+schemaMaximum :: HasParamSchema s t => Lens' s (Maybe Scientific)
105schemaMaximum = parameterSchema.paramSchemaMaximum
106schemaMaximum = parameterSchema.paramSchemaMaximum
106
107
107−schemaExclusiveMaximum :: HasParamSchema s t i => Lens' s (Maybe Bool)
108+schemaExclusiveMaximum :: HasParamSchema s t => Lens' s (Maybe Bool)
108schemaExclusiveMaximum = parameterSchema.paramSchemaExclusiveMaximum
109schemaExclusiveMaximum = parameterSchema.paramSchemaExclusiveMaximum
109
110
110−schemaMinimum :: HasParamSchema s t i => Lens' s (Maybe Scientific)
111+schemaMinimum :: HasParamSchema s t => Lens' s (Maybe Scientific)
111schemaMinimum = parameterSchema.paramSchemaMinimum
112schemaMinimum = parameterSchema.paramSchemaMinimum
112
113
113−schemaExclusiveMinimum :: HasParamSchema s t i => Lens' s (Maybe Bool)
114+schemaExclusiveMinimum :: HasParamSchema s t => Lens' s (Maybe Bool)
114schemaExclusiveMinimum = parameterSchema.paramSchemaExclusiveMinimum
115schemaExclusiveMinimum = parameterSchema.paramSchemaExclusiveMinimum
115
116
116−schemaMaxLength :: HasParamSchema s t i => Lens' s (Maybe Integer)
117+schemaMaxLength :: HasParamSchema s t => Lens' s (Maybe Integer)
117schemaMaxLength = parameterSchema.paramSchemaMaxLength
118schemaMaxLength = parameterSchema.paramSchemaMaxLength
118
119
119−schemaMinLength :: HasParamSchema s t i => Lens' s (Maybe Integer)
120+schemaMinLength :: HasParamSchema s t => Lens' s (Maybe Integer)
120schemaMinLength = parameterSchema.paramSchemaMinLength
121schemaMinLength = parameterSchema.paramSchemaMinLength
121
122
122−schemaPattern :: HasParamSchema s t i => Lens' s (Maybe Text)
123+schemaPattern :: HasParamSchema s t => Lens' s (Maybe Text)
123schemaPattern = parameterSchema.paramSchemaPattern
124schemaPattern = parameterSchema.paramSchemaPattern
124
125
125−schemaMaxItems :: HasParamSchema s t i => Lens' s (Maybe Integer)
126+schemaMaxItems :: HasParamSchema s t => Lens' s (Maybe Integer)
126schemaMaxItems = parameterSchema.paramSchemaMaxItems
127schemaMaxItems = parameterSchema.paramSchemaMaxItems
127
128
128−schemaMinItems :: HasParamSchema s t i => Lens' s (Maybe Integer)
129+schemaMinItems :: HasParamSchema s t => Lens' s (Maybe Integer)
129schemaMinItems = parameterSchema.paramSchemaMinItems
130schemaMinItems = parameterSchema.paramSchemaMinItems
130
131
131−schemaUniqueItems :: HasParamSchema s t i => Lens' s (Maybe Bool)
132+schemaUniqueItems :: HasParamSchema s t => Lens' s (Maybe Bool)
132schemaUniqueItems = parameterSchema.paramSchemaUniqueItems
133schemaUniqueItems = parameterSchema.paramSchemaUniqueItems
133
134
134−schemaEnum :: HasParamSchema s t i => Lens' s (Maybe [Value])
135+schemaEnum :: HasParamSchema s t => Lens' s (Maybe [Value])
135schemaEnum = parameterSchema.paramSchemaEnum
136schemaEnum = parameterSchema.paramSchemaEnum
136
137
137−schemaMultipleOf :: HasParamSchema s t i => Lens' s (Maybe Scientific)
138+schemaMultipleOf :: HasParamSchema s t => Lens' s (Maybe Scientific)
138schemaMultipleOf = parameterSchema.paramSchemaMultipleOf
139schemaMultipleOf = parameterSchema.paramSchemaMultipleOf
139
140
test/Data/Swagger/ParamSchemaSpec.hs+1−1
@@ -18,7 +18,7 @@ import SpecCommon
18import Test.Hspec
18import Test.Hspec
19
19
20checkToParamSchema :: ToParamSchema a => Proxy a -> Value -> Spec
20checkToParamSchema :: ToParamSchema a => Proxy a -> Value -> Spec
21−checkToParamSchema proxy js = (toParamSchema proxy :: ParamSchema Param Items) <=> js
21+checkToParamSchema proxy js = (toParamSchema proxy :: ParamSchema Param) <=> js
22
22
23spec :: Spec
23spec :: Spec
24spec = do
24spec = do