git.iko.soy/typeable/openapi3
on master help sign in
Use ParamSchema for ToParamSchema, rename module
7034d20Nickolay Kudasov
src/Data/Swagger/Internal/Param.hs → src/Data/Swagger/Internal/ParamSchema.hsrenamed+30−46
@@ -6,7 +6,7 @@
6{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE TypeOperators #-}
7{-# LANGUAGE TypeOperators #-}
8{-# LANGUAGE TypeSynonymInstances #-}
8{-# LANGUAGE TypeSynonymInstances #-}
9−module Data.Swagger.Internal.Param where
9+module Data.Swagger.Internal.ParamSchema where
10
10
11import Control.Lens
11import Control.Lens
12import Data.Aeson
12import Data.Aeson
@@ -27,24 +27,18 @@ import Data.Swagger.Lens
27
27
28class ToParamSchema a where
28class ToParamSchema a where
29 -- | Convert a type into a non-body parameter schema.
29 -- | Convert a type into a non-body parameter schema.
30− toParamSchema :: proxy a -> ParamLocation -> ParamOtherSchema
30+ toParamSchema :: proxy a -> ParamSchema t Items
31− default toParamSchema :: (Generic a, GToParamSchema (Rep a)) => proxy a -> ParamLocation -> ParamOtherSchema
31+ default toParamSchema :: (Generic a, GToParamSchema (Rep a)) => proxy a -> ParamSchema t Items
32 toParamSchema = genericToParamSchema defaultSchemaOptions
32 toParamSchema = genericToParamSchema defaultSchemaOptions
33
33
34instance {-# OVERLAPPING #-} ToParamSchema String where
34instance {-# OVERLAPPING #-} ToParamSchema String where
35− toParamSchema _ loc = mempty
36− & paramOtherSchemaIn .~ loc
37− & schemaType .~ SwaggerString
35+ toParamSchema _ = mempty & schemaType .~ SwaggerString
38
36
39instance ToParamSchema Bool where
37instance ToParamSchema Bool where
40− toParamSchema _ loc = mempty
41− & paramOtherSchemaIn .~ loc
42− & schemaType .~ SwaggerBoolean
38+ toParamSchema _ = mempty & schemaType .~ SwaggerBoolean
43
39
44instance ToParamSchema Integer where
40instance ToParamSchema Integer where
45− toParamSchema _ loc = mempty
46− & paramOtherSchemaIn .~ loc
47− & schemaType .~ SwaggerInteger
41+ toParamSchema _ = mempty & schemaType .~ SwaggerInteger
48
42
49instance ToParamSchema Int where toParamSchema = toParamSchemaBoundedIntegral
43instance ToParamSchema Int where toParamSchema = toParamSchemaBoundedIntegral
50instance ToParamSchema Int8 where toParamSchema = toParamSchemaBoundedIntegral
44instance ToParamSchema Int8 where toParamSchema = toParamSchemaBoundedIntegral
@@ -58,62 +52,53 @@ instance ToParamSchema Word16 where toParamSchema = toParamSchemaBoundedIntegral
58instance ToParamSchema Word32 where toParamSchema = toParamSchemaBoundedIntegral
52instance ToParamSchema Word32 where toParamSchema = toParamSchemaBoundedIntegral
59instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
53instance ToParamSchema Word64 where toParamSchema = toParamSchemaBoundedIntegral
60
54
61−toParamSchemaBoundedIntegral :: forall proxy a. (Bounded a, Integral a) => proxy a -> ParamLocation -> ParamOtherSchema
55+toParamSchemaBoundedIntegral :: forall proxy a t. (Bounded a, Integral a) => proxy a -> ParamSchema t Items
62−toParamSchemaBoundedIntegral _ loc = mempty
56+toParamSchemaBoundedIntegral _ = mempty
63− & paramOtherSchemaIn .~ loc
64 & schemaType .~ SwaggerInteger
57 & schemaType .~ SwaggerInteger
65 & schemaMinimum ?~ fromInteger (toInteger (minBound :: a))
58 & schemaMinimum ?~ fromInteger (toInteger (minBound :: a))
66 & schemaMaximum ?~ fromInteger (toInteger (maxBound :: a))
59 & schemaMaximum ?~ fromInteger (toInteger (maxBound :: a))
67
60
68instance ToParamSchema Char where
61instance ToParamSchema Char where
69− toParamSchema _ loc = mempty
62+ toParamSchema _ = mempty
70− & paramOtherSchemaIn .~ loc
71 & schemaType .~ SwaggerString
63 & schemaType .~ SwaggerString
72 & schemaMaxLength ?~ 1
64 & schemaMaxLength ?~ 1
73 & schemaMinLength ?~ 1
65 & schemaMinLength ?~ 1
74
66
75instance ToParamSchema Scientific where
67instance ToParamSchema Scientific where
76− toParamSchema _ loc = mempty
77− & paramOtherSchemaIn .~ loc
78− & schemaType .~ SwaggerNumber
68+ toParamSchema _ = mempty & schemaType .~ SwaggerNumber
79
69
80instance ToParamSchema Double where
70instance ToParamSchema Double where
81− toParamSchema _ loc = mempty
82− & paramOtherSchemaIn .~ loc
83− & schemaType .~ SwaggerNumber
71+ toParamSchema _ = mempty & schemaType .~ SwaggerNumber
84
72
85instance ToParamSchema Float where
73instance ToParamSchema Float where
86− toParamSchema _ loc = mempty
87− & paramOtherSchemaIn .~ loc
88− & schemaType .~ SwaggerNumber
74+ toParamSchema _ = mempty & schemaType .~ SwaggerNumber
89
75
90−timeParamSchema :: String -> ParamLocation -> ParamOtherSchema
76+timeParamSchema :: String -> ParamSchema t Items
91−timeParamSchema format loc = mempty
77+timeParamSchema format = mempty
92− & paramOtherSchemaIn .~ loc
93− & schemaType .~ SwaggerString
78+ & schemaType .~ SwaggerString
94− & schemaFormat ?~ T.pack format
79+ & schemaFormat ?~ T.pack format
95− & schemaMinLength ?~ toInteger (length format)
80+ & schemaMinLength ?~ toInteger (length format)
96
81
97-- |
82-- |
98−-- >>> toParamSchema (Proxy :: Proxy Day) ParamQuery ^. schemaFormat
83+-- >>> toParamSchema (Proxy :: Proxy Day) ^. schemaFormat
99-- Just "yyyy-mm-dd"
84-- Just "yyyy-mm-dd"
100instance ToParamSchema Day where
85instance ToParamSchema Day where
101 toParamSchema _ = timeParamSchema "yyyy-mm-dd"
86 toParamSchema _ = timeParamSchema "yyyy-mm-dd"
102
87
103-- |
88-- |
104−-- >>> toParamSchema (Proxy :: Proxy LocalTime) ParamQuery ^. schemaFormat
89+-- >>> toParamSchema (Proxy :: Proxy LocalTime) ^. schemaFormat
105-- Just "yyyy-mm-ddThh:MM:ss"
90-- Just "yyyy-mm-ddThh:MM:ss"
106instance ToParamSchema LocalTime where
91instance ToParamSchema LocalTime where
107 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss"
92 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss"
108
93
109-- |
94-- |
110−-- >>> toParamSchema (Proxy :: Proxy ZonedTime) ParamQuery ^. schemaFormat
95+-- >>> toParamSchema (Proxy :: Proxy ZonedTime) ^. schemaFormat
111-- Just "yyyy-mm-ddThh:MM:ss+hhMM"
96-- Just "yyyy-mm-ddThh:MM:ss+hhMM"
112instance ToParamSchema ZonedTime where
97instance ToParamSchema ZonedTime where
113 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss+hhMM"
98 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ss+hhMM"
114
99
115-- |
100-- |
116−-- >>> toParamSchema (Proxy :: Proxy UTCTime) ParamQuery ^. schemaFormat
101+-- >>> toParamSchema (Proxy :: Proxy UTCTime) ^. schemaFormat
117-- Just "yyyy-mm-ddThh:MM:ssZ"
102-- Just "yyyy-mm-ddThh:MM:ssZ"
118instance ToParamSchema UTCTime where
103instance ToParamSchema UTCTime where
119 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"
104 toParamSchema _ = timeParamSchema "yyyy-mm-ddThh:MM:ssZ"
@@ -135,11 +120,11 @@ instance ToParamSchema a => ToParamSchema (First a) where toParamSchema _ = to
135instance ToParamSchema a => ToParamSchema (Last a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
120instance ToParamSchema a => ToParamSchema (Last a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
136instance ToParamSchema a => ToParamSchema (Dual a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
121instance ToParamSchema a => ToParamSchema (Dual a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
137
122
138−genericToParamSchema :: forall proxy a. (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamLocation -> ParamOtherSchema
123+genericToParamSchema :: forall proxy a t. (Generic a, GToParamSchema (Rep a)) => SchemaOptions -> proxy a -> ParamSchema t Items
139−genericToParamSchema opts _ loc = gtoParamSchema opts (Proxy :: Proxy (Rep a)) loc mempty
124+genericToParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy (Rep a)) mempty
140
125
141class GToParamSchema (f :: * -> *) where
126class GToParamSchema (f :: * -> *) where
142− gtoParamSchema :: SchemaOptions -> proxy f -> ParamLocation -> ParamOtherSchema -> ParamOtherSchema
127+ gtoParamSchema :: SchemaOptions -> proxy f -> ParamSchema t Items -> ParamSchema t Items
143
128
144instance GToParamSchema f => GToParamSchema (D1 d f) where
129instance GToParamSchema f => GToParamSchema (D1 d f) where
145 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
130 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
@@ -148,22 +133,21 @@ instance GToParamSchema f => GToParamSchema (C1 c (S1 s f)) where
148 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
133 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
149
134
150instance ToParamSchema c => GToParamSchema (K1 i c) where
135instance ToParamSchema c => GToParamSchema (K1 i c) where
151− gtoParamSchema _ _ loc _ = toParamSchema (Proxy :: Proxy c) loc
136+ gtoParamSchema _ _ _ = toParamSchema (Proxy :: Proxy c)
152
137
153instance (GEnumParamSchema f, GEnumParamSchema g) => GToParamSchema (f :+: g) where
138instance (GEnumParamSchema f, GEnumParamSchema g) => GToParamSchema (f :+: g) where
154 gtoParamSchema opts _ = genumParamSchema opts (Proxy :: Proxy (f :+: g))
139 gtoParamSchema opts _ = genumParamSchema opts (Proxy :: Proxy (f :+: g))
155
140
156class GEnumParamSchema (f :: * -> *) where
141class GEnumParamSchema (f :: * -> *) where
157− genumParamSchema :: SchemaOptions -> proxy f -> ParamLocation -> ParamOtherSchema -> ParamOtherSchema
142+ genumParamSchema :: SchemaOptions -> proxy f -> ParamSchema t Items -> ParamSchema t Items
158
143
159instance (GEnumParamSchema f, GEnumParamSchema g) => GEnumParamSchema (f :+: g) where
144instance (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)
161
146
162instance Constructor c => GEnumParamSchema (C1 c U1) where
147instance Constructor c => GEnumParamSchema (C1 c U1) where
163− genumParamSchema opts _ loc s = s
148+ genumParamSchema opts _ s = s
164− & paramOtherSchemaIn .~ loc
165− & schemaType .~ SwaggerString
149+ & schemaType .~ SwaggerString
166− & schemaEnum %~ addEnumValue tag
150+ & schemaEnum %~ addEnumValue tag
167 where
151 where
168 tag = toJSON (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
152 tag = toJSON (constructorTagModifier opts (conName (Proxy3 :: Proxy3 c f p)))
169
153
swagger2.cabal+1−1
@@ -25,8 +25,8 @@ library
25
25
26 -- internal modules
26 -- internal modules
27 Data.Swagger.Internal
27 Data.Swagger.Internal
28− Data.Swagger.Internal.Param
29 Data.Swagger.Internal.Schema
28 Data.Swagger.Internal.Schema
29+ Data.Swagger.Internal.ParamSchema
30 Data.Swagger.Internal.Utils
30 Data.Swagger.Internal.Utils
31 build-depends: base == 4.*
31 build-depends: base == 4.*
32 , aeson < 0.10
32 , aeson < 0.10