git.iko.soy/typeable/openapi3
on master help sign in
Remove old types, migrate Param
commit0bf745e6cc53aaa6eda8e34d1874d36e618b3c3e authorMaxim Koltsov <kolmax94@gmail.com> dateFri 26 Jun 2020, 15:21 (6 years ago) parentfec285b
4 files changed+26−219
src/Data/Swagger.hs−4 src/Data/Swagger/Internal.hs+25−107 src/Data/Swagger/Lens.hs+1−7 src/Data/Swagger/Optics.hs−101
src/Data/Swagger.hs−4
@@ -38,8 +38,6 @@ module Data.Swagger (
3838
3939 -- * Swagger specification
4040 Swagger(..),
41− Host(..),
42− Scheme(..),
4341 Server(..),
4442 ServerVariable(..),
4543 Components(..),
@@ -65,8 +63,6 @@ module Data.Swagger (
6563
6664 -- ** Parameters
6765 Param(..),
68− ParamAnySchema(..),
69− ParamOtherSchema(..),
7066 ParamLocation(..),
7167 ParamName,
7268 Header(..),
src/Data/Swagger/Internal.hs+25−107
@@ -179,6 +179,9 @@ data ServerVariable = ServerVariable
179179 , _serverVariableDescription :: Maybe Text
180180 } deriving (Eq, Show, Generic, Data, Typeable)
181181
182+instance IsString Server where
183+ fromString s = Server (fromString s) Nothing mempty
184+
182185-- | Holds a set of reusable objects for different aspects of the OAS.
183186-- All objects defined within the components object will have no effect on the API
184187-- unless they are explicitly referenced from properties outside the components object.
@@ -194,36 +197,6 @@ data Components = Components
194197-- , _componentsCallbacks
195198 } deriving (Eq, Show, Generic, Data, Typeable)
196199
197−-- | The host (name or ip) serving the API. It MAY include a port.
198−data Host = Host
199− { _hostName :: HostName -- ^ Host name.
200− , _hostPort :: Maybe PortNumber -- ^ Optional port.
201− } deriving (Eq, Show, Generic, Typeable)
202−
203−instance IsString Host where
204− fromString s = Host s Nothing
205−
206−hostConstr :: Constr
207−hostConstr = mkConstr hostDataType "Host" [] Prefix
208−
209−hostDataType :: DataType
210−hostDataType = mkDataType "Data.Swagger.Host" [hostConstr]
211−
212−instance Data Host where
213− gunfold k z c = case constrIndex c of
214− 1 -> k (k (z (\name mport -> Host name (fromInteger <$> mport))))
215− _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type Host."
216− toConstr (Host _ _) = hostConstr
217− dataTypeOf _ = hostDataType
218−
219−-- | The transfer protocol of the API.
220−data Scheme
221− = Http
222− | Https
223− | Ws
224− | Wss
225− deriving (Eq, Show, Generic, Data, Typeable)
226−
227200-- | Describes the operations available on a single path.
228201-- A @'PathItem'@ may be empty, due to ACL constraints.
229202-- The path itself is still exposed to the documentation viewer
@@ -421,6 +394,9 @@ instance Data MimeList where
421394 toConstr (MimeList _) = mimeListConstr
422395 dataTypeOf _ = mimeListDataType
423396
397+-- TODO style
398+-- TODO example
399+
424400-- | Describes a single operation parameter.
425401-- A unique parameter is defined by a combination of a name and location.
426402data Param = Param
@@ -438,27 +414,21 @@ data Param = Param
438414 -- Otherwise, the property MAY be included and its default value is @False@.
439415 , _paramRequired :: Maybe Bool
440416
441− -- | Parameter schema.
442− , _paramSchema :: ParamAnySchema
443− } deriving (Eq, Show, Generic, Data, Typeable)
444−
445−data ParamAnySchema
446− = ParamBody (Referenced Schema)
447− | ParamOther ParamOtherSchema
448− deriving (Eq, Show, Generic, Data, Typeable)
417+ -- | Specifies that a parameter is deprecated and SHOULD be transitioned out of usage.
418+ -- Default value is @false@.
419+ , _paramDeprecated :: Maybe Bool
449420
450−data ParamOtherSchema = ParamOtherSchema
451− { -- | The location of the parameter.
452− _paramOtherSchemaIn :: ParamLocation
421+ -- | The location of the parameter.
422+ , _paramIn :: ParamLocation
453423
454424 -- | Sets the ability to pass empty-valued parameters.
455− -- This is valid only for either @'ParamQuery'@ or @'ParamFormData'@
456− -- and allows you to send a parameter with a name only or an empty value.
457− -- Default value is @False@.
425+ -- This is valid only for 'ParamQuery' parameters and allows sending
426+ -- a parameter with an empty value. Default value is @false@.
458427 , _paramOtherSchemaAllowEmptyValue :: Maybe Bool
459428
460− , _paramOtherSchemaParamSchema :: ParamSchema 'SwaggerKindParamOtherSchema
461− } deriving (Eq, Show, Generic, Typeable, Data)
429+ -- | Parameter schema.
430+ , _paramSchema :: Maybe (Referenced Schema)
431+ } deriving (Eq, Show, Generic, Data, Typeable)
462432
463433data Example = Example
464434 { -- | Short description for the example.
@@ -561,10 +531,11 @@ deriving instance Typeable 'SwaggerKindNormal
561531deriving instance Typeable 'SwaggerKindParamOtherSchema
562532deriving instance Typeable 'SwaggerKindSchema
563533
534+-- TODO remove
564535type family SwaggerKindType (k :: SwaggerKind *) :: *
565536type instance SwaggerKindType ('SwaggerKindNormal t) = t
566537type instance SwaggerKindType 'SwaggerKindSchema = Schema
567−type instance SwaggerKindType 'SwaggerKindParamOtherSchema = ParamOtherSchema
538+--type instance SwaggerKindType 'SwaggerKindParamOtherSchema = ParamOtherSchema
568539
569540data SwaggerType t where
570541 SwaggerString :: SwaggerType t
@@ -967,7 +938,6 @@ deriveGeneric ''OAuth2Flow
967938deriveGeneric ''OAuth2Flows
968939deriveGeneric ''Operation
969940deriveGeneric ''Param
970−deriveGeneric ''ParamOtherSchema
971941deriveGeneric ''PathItem
972942deriveGeneric ''Response
973943deriveGeneric ''RequestBody
@@ -1032,12 +1002,6 @@ instance Monoid Param where
10321002 mempty = genericMempty
10331003 mappend = (<>)
10341004
1035−instance Semigroup ParamOtherSchema where
1036− (<>) = genericMappend
1037−instance Monoid ParamOtherSchema where
1038− mempty = genericMempty
1039− mappend = (<>)
1040−
10411005instance Semigroup Header where
10421006 (<>) = genericMappend
10431007instance Monoid Header where
@@ -1086,6 +1050,12 @@ instance Monoid OAuth2Flows where
10861050 mempty = genericMempty
10871051 mappend = (<>)
10881052
1053+instance Semigroup RequestBody where
1054+ (<>) = genericMappend
1055+instance Monoid RequestBody where
1056+ mempty = genericMempty
1057+ mappend = (<>)
1058+
10891059-- =======================================================================
10901060-- SwaggerMonoid helper instances
10911061-- =======================================================================
@@ -1096,7 +1066,6 @@ instance SwaggerMonoid PathItem
10961066instance SwaggerMonoid Schema
10971067instance SwaggerMonoid (ParamSchema t)
10981068instance SwaggerMonoid Param
1099−instance SwaggerMonoid ParamOtherSchema
11001069instance SwaggerMonoid Responses
11011070instance SwaggerMonoid Response
11021071instance SwaggerMonoid ExternalDocs
@@ -1123,12 +1092,6 @@ instance Monoid a => SwaggerMonoid (Referenced a) where
11231092 swaggerMappend (Inline x) (Inline y) = Inline (mappend x y)
11241093 swaggerMappend _ y = y
11251094
1126−instance SwaggerMonoid ParamAnySchema where
1127− swaggerMempty = ParamOther swaggerMempty
1128− swaggerMappend (ParamBody x) (ParamBody y) = ParamBody (swaggerMappend x y)
1129− swaggerMappend (ParamOther x) (ParamOther y) = ParamOther (swaggerMappend x y)
1130− swaggerMappend _ y = y
1131−
11321095-- =======================================================================
11331096-- Simple Generic-based ToJSON instances
11341097-- =======================================================================
@@ -1157,9 +1120,6 @@ instance ToJSON ApiKeyLocation where
11571120instance ToJSON ApiKeyParams where
11581121 toJSON = genericToJSON (jsonPrefix "apiKey")
11591122
1160−instance ToJSON Scheme where
1161− toJSON = genericToJSON (jsonPrefix "")
1162−
11631123instance ToJSON Tag where
11641124 toJSON = genericToJSON (jsonPrefix "Tag")
11651125
@@ -1212,9 +1172,6 @@ instance FromJSON ApiKeyLocation where
12121172instance FromJSON ApiKeyParams where
12131173 parseJSON = genericParseJSON (jsonPrefix "apiKey")
12141174
1215−instance FromJSON Scheme where
1216− parseJSON = genericParseJSON (jsonPrefix "")
1217−
12181175instance FromJSON Tag where
12191176 parseJSON = genericParseJSON (jsonPrefix "Tag")
12201177
@@ -1303,12 +1260,6 @@ instance ToJSON Components where
13031260 toJSON = sopSwaggerGenericToJSON
13041261 toEncoding = sopSwaggerGenericToEncoding
13051262
1306−instance ToJSON Host where
1307− toJSON (Host host mport) = toJSON $
1308− case mport of
1309− Nothing -> host
1310− Just port -> host ++ ":" ++ show port
1311−
13121263instance ToJSON MimeList where
13131264 toJSON (MimeList xs) = toJSON (map show xs)
13141265
@@ -1316,14 +1267,6 @@ instance ToJSON Param where
13161267 toJSON = sopSwaggerGenericToJSON
13171268 toEncoding = sopSwaggerGenericToEncoding
13181269
1319−instance ToJSON ParamAnySchema where
1320− toJSON (ParamBody s) = object [ "in" .= ("body" :: Text), "schema" .= s ]
1321− toJSON (ParamOther s) = toJSON s
1322−
1323−instance ToJSON ParamOtherSchema where
1324− toJSON = sopSwaggerGenericToJSON
1325− toEncoding = sopSwaggerGenericToEncoding
1326−
13271270instance ToJSON Responses where
13281271 toJSON = sopSwaggerGenericToJSON
13291272 toEncoding = sopSwaggerGenericToEncoding
@@ -1466,34 +1409,12 @@ instance FromJSON (SwaggerItems 'SwaggerKindSchema) where
14661409instance FromJSON Components where
14671410 parseJSON = sopSwaggerGenericParseJSON
14681411
1469−instance FromJSON Host where
1470− parseJSON (String s) = case map Text.unpack $ Text.split (== ':') s of
1471− [host] -> return $ Host host Nothing
1472− [host, port] -> case readMaybe port of
1473− Nothing -> fail $ "Invalid port `" ++ port ++ "'"
1474− Just p -> return $ Host host (Just (fromInteger p))
1475− _ -> fail $ "Invalid host `" ++ Text.unpack s ++ "'"
1476− parseJSON _ = empty
1477−
14781412instance FromJSON MimeList where
14791413 parseJSON js = (MimeList . map fromString) <$> parseJSON js
14801414
14811415instance FromJSON Param where
14821416 parseJSON = sopSwaggerGenericParseJSON
14831417
1484−instance FromJSON ParamAnySchema where
1485− parseJSON js@(Object o) = do
1486− (i :: Text) <- o .: "in"
1487− case i of
1488− "body" -> do
1489− schema <- o .: "schema"
1490− ParamBody <$> parseJSON schema
1491− _ -> ParamOther <$> parseJSON js
1492− parseJSON _ = empty
1493−
1494−instance FromJSON ParamOtherSchema where
1495− parseJSON = sopSwaggerGenericParseJSON
1496−
14971418instance FromJSON Responses where
14981419 parseJSON (Object o) = Responses
14991420 <$> o .:? "default"
@@ -1589,9 +1510,7 @@ instance HasSwaggerAesonOptions OAuth2Flows where
15891510instance HasSwaggerAesonOptions Operation where
15901511 swaggerAesonOptions _ = mkSwaggerAesonOptions "operation"
15911512instance HasSwaggerAesonOptions Param where
1592− swaggerAesonOptions _ = mkSwaggerAesonOptions "param" & saoSubObject ?~ "schema"
1593−instance HasSwaggerAesonOptions ParamOtherSchema where
1594− swaggerAesonOptions _ = mkSwaggerAesonOptions "paramOtherSchema" & saoSubObject ?~ "paramSchema"
1513+ swaggerAesonOptions _ = mkSwaggerAesonOptions "param"
15951514instance HasSwaggerAesonOptions PathItem where
15961515 swaggerAesonOptions _ = mkSwaggerAesonOptions "pathItem"
15971516instance HasSwaggerAesonOptions Response where
@@ -1629,7 +1548,6 @@ instance AesonDefaultValue OAuth2ClientCredentialsFlow
16291548instance AesonDefaultValue OAuth2AuthorizationCodeFlow
16301549instance AesonDefaultValue p => AesonDefaultValue (OAuth2Flow p)
16311550instance AesonDefaultValue Responses
1632−instance AesonDefaultValue ParamAnySchema
16331551instance AesonDefaultValue SecuritySchemeType
16341552instance AesonDefaultValue (SwaggerType a)
16351553instance AesonDefaultValue MimeList where defaultValue = Just mempty
src/Data/Swagger/Lens.hs+1−7
@@ -33,15 +33,13 @@ makeFields ''Server
3333--makeLensesWith swaggerFieldRules ''ServerVariable
3434makeFields ''RequestBody
3535makeFields ''MediaTypeObject
36−makeFields ''Host
3736makeFields ''Info
3837makeFields ''Contact
3938makeFields ''License
4039makeLensesWith swaggerFieldRules ''PathItem
4140makeFields ''Tag
4241makeFields ''Operation
43−makeFields ''Param
44−makeLensesWith swaggerFieldRules ''ParamOtherSchema
42+makeLensesWith swaggerFieldRules ''Param
4543makeFields ''Header
4644makeLensesWith swaggerFieldRules ''Schema
4745makeFields ''NamedSchema
@@ -63,8 +61,6 @@ makeFields ''Example
6361makeFields ''Discriminator
6462
6563-- * Prisms
66−-- ** 'ParamAnySchema' prisms
67−makePrisms ''ParamAnySchema
6864-- ** 'SecuritySchemeType' prisms
6965makePrisms ''SecuritySchemeType
7066-- ** 'Referenced' prisms
@@ -114,12 +110,10 @@ instance HasParamSchema NamedSchema (ParamSchema 'SwaggerKindSchema) where param
114110instance HasType Header (Maybe (SwaggerType ('SwaggerKindNormal Header))) where type_ = paramSchema.type_
115111instance HasType Schema (Maybe (SwaggerType 'SwaggerKindSchema)) where type_ = paramSchema.type_
116112instance HasType NamedSchema (Maybe (SwaggerType 'SwaggerKindSchema)) where type_ = paramSchema.type_
117−instance HasType ParamOtherSchema (Maybe (SwaggerType 'SwaggerKindParamOtherSchema)) where type_ = paramSchema.type_
118113
119114-- HasDefault instances
120115instance HasDefault Header (Maybe Value) where default_ = paramSchema.default_
121116instance HasDefault Schema (Maybe Value) where default_ = paramSchema.default_
122−instance HasDefault ParamOtherSchema (Maybe Value) where default_ = paramSchema.default_
123117
124118-- OVERLAPPABLE instances
125119
src/Data/Swagger/Optics.hs−101
@@ -80,7 +80,6 @@ makeFieldLabels ''Server
8080makeFieldLabels ''ServerVariable
8181makeFieldLabels ''RequestBody
8282makeFieldLabels ''MediaTypeObject
83−makeFieldLabels ''Host
8483makeFieldLabels ''Info
8584makeFieldLabels ''Contact
8685makeFieldLabels ''License
@@ -88,7 +87,6 @@ makeFieldLabels ''PathItem
8887makeFieldLabels ''Tag
8988makeFieldLabels ''Operation
9089makeFieldLabels ''Param
91−makeFieldLabels ''ParamOtherSchema
9290makeFieldLabels ''Header
9391makeFieldLabels ''Schema
9492makeFieldLabels ''NamedSchema
@@ -111,7 +109,6 @@ makeFieldLabels ''Discriminator
111109
112110-- Prisms
113111
114−makePrismLabels ''ParamAnySchema
115112makePrismLabels ''SecuritySchemeType
116113makePrismLabels ''Referenced
117114
@@ -208,13 +205,6 @@ instance
208205 labelOptic = #paramSchema % #type
209206 {-# INLINE labelOptic #-}
210207
211−instance
212− ( a ~ Maybe (SwaggerType 'SwaggerKindParamOtherSchema)
213− , b ~ Maybe (SwaggerType 'SwaggerKindParamOtherSchema)
214− ) => LabelOptic "type" A_Lens ParamOtherSchema ParamOtherSchema a b where
215− labelOptic = #paramSchema % #type
216− {-# INLINE labelOptic #-}
217−
218208-- #default
219209
220210instance
@@ -235,12 +225,6 @@ instance
235225 labelOptic = #paramSchema % #default
236226 {-# INLINE labelOptic #-}
237227
238−instance
239− ( a ~ Maybe Value, b ~ Maybe Value
240− ) => LabelOptic "default" A_Lens ParamOtherSchema ParamOtherSchema a b where
241− labelOptic = #paramSchema % #default
242− {-# INLINE labelOptic #-}
243−
244228-- #format
245229
246230instance
@@ -261,12 +245,6 @@ instance
261245 labelOptic = #paramSchema % #format
262246 {-# INLINE labelOptic #-}
263247
264−instance
265− ( a ~ Maybe Format, b ~ Maybe Format
266− ) => LabelOptic "format" A_Lens ParamOtherSchema ParamOtherSchema a b where
267− labelOptic = #paramSchema % #format
268− {-# INLINE labelOptic #-}
269−
270248-- #items
271249
272250instance
@@ -290,13 +268,6 @@ instance
290268 labelOptic = #paramSchema % #items
291269 {-# INLINE labelOptic #-}
292270
293−instance
294− ( a ~ Maybe (SwaggerItems 'SwaggerKindParamOtherSchema)
295− , b ~ Maybe (SwaggerItems 'SwaggerKindParamOtherSchema)
296− ) => LabelOptic "items" A_Lens ParamOtherSchema ParamOtherSchema a b where
297− labelOptic = #paramSchema % #items
298− {-# INLINE labelOptic #-}
299−
300271-- #maximum
301272
302273instance
@@ -317,12 +288,6 @@ instance
317288 labelOptic = #paramSchema % #maximum
318289 {-# INLINE labelOptic #-}
319290
320−instance
321− ( a ~ Maybe Scientific, b ~ Maybe Scientific
322− ) => LabelOptic "maximum" A_Lens ParamOtherSchema ParamOtherSchema a b where
323− labelOptic = #paramSchema % #maximum
324− {-# INLINE labelOptic #-}
325−
326291-- #exclusiveMaximum
327292
328293instance
@@ -343,12 +308,6 @@ instance
343308 labelOptic = #paramSchema % #exclusiveMaximum
344309 {-# INLINE labelOptic #-}
345310
346−instance
347− ( a ~ Maybe Bool, b ~ Maybe Bool
348− ) => LabelOptic "exclusiveMaximum" A_Lens ParamOtherSchema ParamOtherSchema a b where
349− labelOptic = #paramSchema % #exclusiveMaximum
350− {-# INLINE labelOptic #-}
351−
352311-- #minimum
353312
354313instance
@@ -369,12 +328,6 @@ instance
369328 labelOptic = #paramSchema % #minimum
370329 {-# INLINE labelOptic #-}
371330
372−instance
373− ( a ~ Maybe Scientific, b ~ Maybe Scientific
374− ) => LabelOptic "minimum" A_Lens ParamOtherSchema ParamOtherSchema a b where
375− labelOptic = #paramSchema % #minimum
376− {-# INLINE labelOptic #-}
377−
378331-- #exclusiveMinimum
379332
380333instance
@@ -395,12 +348,6 @@ instance
395348 labelOptic = #paramSchema % #exclusiveMinimum
396349 {-# INLINE labelOptic #-}
397350
398−instance
399− ( a ~ Maybe Bool, b ~ Maybe Bool
400− ) => LabelOptic "exclusiveMinimum" A_Lens ParamOtherSchema ParamOtherSchema a b where
401− labelOptic = #paramSchema % #exclusiveMinimum
402− {-# INLINE labelOptic #-}
403−
404351-- #maxLength
405352
406353instance
@@ -421,12 +368,6 @@ instance
421368 labelOptic = #paramSchema % #maxLength
422369 {-# INLINE labelOptic #-}
423370
424−instance
425− ( a ~ Maybe Integer, b ~ Maybe Integer
426− ) => LabelOptic "maxLength" A_Lens ParamOtherSchema ParamOtherSchema a b where
427− labelOptic = #paramSchema % #maxLength
428− {-# INLINE labelOptic #-}
429−
430371-- #minLength
431372
432373instance
@@ -447,12 +388,6 @@ instance
447388 labelOptic = #paramSchema % #minLength
448389 {-# INLINE labelOptic #-}
449390
450−instance
451− ( a ~ Maybe Integer, b ~ Maybe Integer
452− ) => LabelOptic "minLength" A_Lens ParamOtherSchema ParamOtherSchema a b where
453− labelOptic = #paramSchema % #minLength
454− {-# INLINE labelOptic #-}
455−
456391-- #pattern
457392
458393instance
@@ -473,12 +408,6 @@ instance
473408 labelOptic = #paramSchema % #pattern
474409 {-# INLINE labelOptic #-}
475410
476−instance
477− ( a ~ Maybe Text, b ~ Maybe Text
478− ) => LabelOptic "pattern" A_Lens ParamOtherSchema ParamOtherSchema a b where
479− labelOptic = #paramSchema % #pattern
480− {-# INLINE labelOptic #-}
481−
482411-- #maxItems
483412
484413instance
@@ -499,12 +428,6 @@ instance
499428 labelOptic = #paramSchema % #maxItems
500429 {-# INLINE labelOptic #-}
501430
502−instance
503− ( a ~ Maybe Integer, b ~ Maybe Integer
504− ) => LabelOptic "maxItems" A_Lens ParamOtherSchema ParamOtherSchema a b where
505− labelOptic = #paramSchema % #maxItems
506− {-# INLINE labelOptic #-}
507−
508431-- #minItems
509432
510433instance
@@ -525,12 +448,6 @@ instance
525448 labelOptic = #paramSchema % #minItems
526449 {-# INLINE labelOptic #-}
527450
528−instance
529− ( a ~ Maybe Integer, b ~ Maybe Integer
530− ) => LabelOptic "minItems" A_Lens ParamOtherSchema ParamOtherSchema a b where
531− labelOptic = #paramSchema % #minItems
532− {-# INLINE labelOptic #-}
533−
534451-- #uniqueItems
535452
536453instance
@@ -551,12 +468,6 @@ instance
551468 labelOptic = #paramSchema % #uniqueItems
552469 {-# INLINE labelOptic #-}
553470
554−instance
555− ( a ~ Maybe Bool, b ~ Maybe Bool
556− ) => LabelOptic "uniqueItems" A_Lens ParamOtherSchema ParamOtherSchema a b where
557− labelOptic = #paramSchema % #uniqueItems
558− {-# INLINE labelOptic #-}
559−
560471-- #enum
561472
562473instance
@@ -577,12 +488,6 @@ instance
577488 labelOptic = #paramSchema % #enum
578489 {-# INLINE labelOptic #-}
579490
580−instance
581− ( a ~ Maybe [Value], b ~ Maybe [Value]
582− ) => LabelOptic "enum" A_Lens ParamOtherSchema ParamOtherSchema a b where
583− labelOptic = #paramSchema % #enum
584− {-# INLINE labelOptic #-}
585−
586491-- #multipleOf
587492
588493instance
@@ -602,9 +507,3 @@ instance
602507 ) => LabelOptic "multipleOf" A_Lens NamedSchema NamedSchema a b where
603508 labelOptic = #paramSchema % #multipleOf
604509 {-# INLINE labelOptic #-}
605−
606−instance
607− ( a ~ Maybe Scientific, b ~ Maybe Scientific
608− ) => LabelOptic "multipleOf" A_Lens ParamOtherSchema ParamOtherSchema a b where
609− labelOptic = #paramSchema % #multipleOf
610− {-# INLINE labelOptic #-}