@@ -6,7 +6,7 @@
66{-# LANGUAGE ScopedTypeVariables #-}
77{-# LANGUAGE TypeOperators #-}
88{-# LANGUAGE TypeSynonymInstances #-}
9−module Data.Swagger.Internal.Param where
9+module Data.Swagger.Internal.ParamSchema where
1010
1111import Control.Lens
1212import Data.Aeson
@@ -27,24 +27,18 @@ import Data.Swagger.Lens
2727
2828class ToParamSchema a where
2929 -- | Convert a type into a non-body parameter schema.
30− toParamSchema :: proxy a -> ParamLocation -> ParamOtherSchema
31− default toParamSchema :: (Generic a, GToParamSchema (Rep a)) => proxy a -> ParamLocation -> ParamOtherSchema
30+ toParamSchema :: proxy a -> ParamSchema t Items
31+ default toParamSchema :: (Generic a, GToParamSchema (Rep a)) => proxy a -> ParamSchema t Items
3232 toParamSchema = genericToParamSchema defaultSchemaOptions
3333
3434instance {-# OVERLAPPING #-} ToParamSchema String where
35− toParamSchema _ loc = mempty
36− & paramOtherSchemaIn .~ loc
37− & schemaType .~ SwaggerString
35+ toParamSchema _ = mempty & schemaType .~ SwaggerString
3836
3937instance ToParamSchema Bool where
40− toParamSchema _ loc = mempty
41− & paramOtherSchemaIn .~ loc
42− & schemaType .~ SwaggerBoolean
38+ toParamSchema _ = mempty & schemaType .~ SwaggerBoolean
4339
4440instance ToParamSchema Integer where
45− toParamSchema _ loc = mempty
46− & paramOtherSchemaIn .~ loc
47− & schemaType .~ SwaggerInteger
41+ toParamSchema _ = mempty & schemaType .~ SwaggerInteger
4842
4943instance ToParamSchema Int where toParamSchema = toParamSchemaBoundedIntegral
5044instance ToParamSchema Int8 where toParamSchema = toParamSchemaBoundedIntegral
@@ -58,62 +52,53 @@ instance ToParamSchema Word16 where toParamSchema = toParamSchemaBoundedIntegral
5852instance ToParamSchema Word32 where toParamSchema = toParamSchemaBoundedIntegral
5953instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
6054
61−toParamSchemaBoundedIntegral :: forall proxy a. (Bounded a, Integral a) => proxy a -> ParamLocation -> ParamOtherSchema
62−toParamSchemaBoundedIntegral _ loc = mempty
63− & paramOtherSchemaIn .~ loc
55+toParamSchemaBoundedIntegral :: forall proxy a t. (Bounded a, Integral a) => proxy a -> ParamSchema t Items
56+toParamSchemaBoundedIntegral _ = mempty
6457 & schemaType .~ SwaggerInteger
6558 & schemaMinimum ?~ fromInteger (toInteger (minBound :: a))
6659 & schemaMaximum ?~ fromInteger (toInteger (maxBound :: a))
6760
6861instance ToParamSchema Char where
69− toParamSchema _ loc = mempty
70− & paramOtherSchemaIn .~ loc
62+ toParamSchema _ = mempty
7163 & schemaType .~ SwaggerString
7264 & schemaMaxLength ?~ 1
7365 & schemaMinLength ?~ 1
7466
7567instance ToParamSchema Scientific where
76− toParamSchema _ loc = mempty
77− & paramOtherSchemaIn .~ loc
78− & schemaType .~ SwaggerNumber
68+ toParamSchema _ = mempty & schemaType .~ SwaggerNumber
7969
8070instance ToParamSchema Double where
81− toParamSchema _ loc = mempty
82− & paramOtherSchemaIn .~ loc
83− & schemaType .~ SwaggerNumber
71+ toParamSchema _ = mempty & schemaType .~ SwaggerNumber
8472
8573instance ToParamSchema Float where
86− toParamSchema _ loc = mempty
87− & paramOtherSchemaIn .~ loc
88− & schemaType .~ SwaggerNumber
74+ toParamSchema _ = mempty & schemaType .~ SwaggerNumber
8975
90−timeParamSchema :: String -> ParamLocation -> ParamOtherSchema
91−timeParamSchema format loc = mempty
92− & paramOtherSchemaIn .~ loc
93− & schemaType .~ SwaggerString
94− & schemaFormat ?~ T.pack format
95− & schemaMinLength ?~ toInteger (length format)
76+timeParamSchema :: String -> ParamSchema t Items
77+timeParamSchema format = mempty
78+ & schemaType .~ SwaggerString
79+ & schemaFormat ?~ T.pack format
80+ & schemaMinLength ?~ toInteger (length format)
9681
9782-- |
98−-- >>> toParamSchema (Proxy :: Proxy Day) ParamQuery ^. schemaFormat
83+-- >>> toParamSchema (Proxy :: Proxy Day) ^. schemaFormat
9984-- Just "yyyy-mm-dd"
10085instance ToParamSchema Day where
10186 toParamSchema _ = timeParamSchema "yyyy-mm-dd"
10287
10388-- |
104−-- >>> toParamSchema (Proxy :: Proxy LocalTime) ParamQuery ^. schemaFormat
89+-- >>> toParamSchema (Proxy :: Proxy LocalTime) ^. schemaFormat
10590-- Just "yyyy-mm-ddThh:MM:ss"
10691instance ToParamSchema LocalTime where
10792 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss"
10893
10994-- |
110−-- >>> toParamSchema (Proxy :: Proxy ZonedTime) ParamQuery ^. schemaFormat
95+-- >>> toParamSchema (Proxy :: Proxy ZonedTime) ^. schemaFormat
11196-- Just "yyyy-mm-ddThh:MM:ss+hhMM"
11297instance ToParamSchema ZonedTime where
11398 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss+hhMM"
11499
115100-- |
116−-- >>> toParamSchema (Proxy :: Proxy UTCTime) ParamQuery ^. schemaFormat
101+-- >>> toParamSchema (Proxy :: Proxy UTCTime) ^. schemaFormat
117102-- Just "yyyy-mm-ddThh:MM:ssZ"
118103instance ToParamSchema UTCTime where
119104 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"
@@ -135,11 +120,11 @@ instance ToParamSchema a => ToParamSchema (First a) where toParamSchema _ = to
135120instance ToParamSchema a => ToParamSchema (Last a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
136121instance ToParamSchema a => ToParamSchema (Dual a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
137122
138−genericToParamSchema :: forall proxy a. (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamLocation -> ParamOtherSchema
139−genericToParamSchema opts _ loc = gtoParamSchema opts (Proxy :: Proxy (Rep a)) loc mempty
123+genericToParamSchema :: forall proxy a t. (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamSchema t Items
124+genericToParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy (Rep a)) mempty
140125
141126class GToParamSchema (f :: * -> *) where
142− gtoParamSchema :: SchemaOptions -> proxy f -> ParamLocation -> ParamOtherSchema -> ParamOtherSchema
127+ gtoParamSchema :: SchemaOptions -> proxy f -> ParamSchema t Items -> ParamSchema t Items
143128
144129instance GToParamSchema f => GToParamSchema (D1 d f) where
145130 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
@@ -148,22 +133,21 @@ instance GToParamSchema f => GToParamSchema (C1 c (S1 s f)) where
148133 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
149134
150135instance ToParamSchema c => GToParamSchema (K1 i c) where
151− gtoParamSchema _ _ loc _ = toParamSchema (Proxy :: Proxy c) loc
136+ gtoParamSchema _ _ _ = toParamSchema (Proxy :: Proxy c)
152137
153138instance (GEnumParamSchema f, GEnumParamSchema g) => GToParamSchema (f :+: g) where
154139 gtoParamSchema opts _ = genumParamSchema opts (Proxy :: Proxy (f :+: g))
155140
156141class GEnumParamSchema (f :: * -> *) where
157− genumParamSchema :: SchemaOptions -> proxy f -> ParamLocation -> ParamOtherSchema -> ParamOtherSchema
142+ genumParamSchema :: SchemaOptions -> proxy f -> ParamSchema t Items -> ParamSchema t Items
158143
159144instance (GEnumParamSchema f, GEnumParamSchema g) => GEnumParamSchema (f :+: g) where
160− genumParamSchema opts _ loc = genumParamSchema opts (Proxy :: Proxy f) loc . genumParamSchema opts (Proxy :: Proxy g) loc
145+ genumParamSchema opts _ = genumParamSchema opts (Proxy :: Proxy f) . genumParamSchema opts (Proxy :: Proxy g)
161146
162147instance Constructor c => GEnumParamSchema (C1 c U1) where
163− genumParamSchema opts _ loc s = s
164− & paramOtherSchemaIn .~ loc
165− & schemaType .~ SwaggerString
166− & schemaEnum %~ addEnumValue tag
148+ genumParamSchema opts _ s = s
149+ & schemaType .~ SwaggerString
150+ & schemaEnum %~ addEnumValue tag
167151 where
168152 tag = toJSON (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
169153