git.iko.soy/typeable/openapi3
on master help sign in
Add Data and Typeable instances for Data.Swagger types
4f8ddeaNickolay Kudasov
src/Data/Swagger/Internal.hs+177−35
@@ -1,3 +1,4 @@
1+{-# LANGUAGE DeriveDataTypeable #-}
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveTraversable #-}
3{-# LANGUAGE DeriveTraversable #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleContexts #-}
@@ -16,6 +17,7 @@ import Control.Monad
16import Data.Aeson
17import Data.Aeson
17import Data.Aeson.TH (deriveJSON)
18import Data.Aeson.TH (deriveJSON)
18import qualified Data.Aeson.Types as JSON
19import qualified Data.Aeson.Types as JSON
20+import Data.Data (Data(..), Typeable, mkConstr, mkDataType, Fixity(..), Constr, DataType, constrIndex)
19import Data.HashMap.Strict (HashMap)
21import Data.HashMap.Strict (HashMap)
20import qualified Data.HashMap.Strict as HashMap
22import qualified Data.HashMap.Strict as HashMap
21import Data.Map (Map)
23import Data.Map (Map)
@@ -91,7 +93,7 @@ data Swagger = Swagger
91
93
92 -- | Additional external documentation.
94 -- | Additional external documentation.
93 , _externalDocs :: Maybe ExternalDocs
95 , _externalDocs :: Maybe ExternalDocs
94− } deriving (Eq, Show, Generic)
96+ } deriving (Eq, Show, Generic, Data, Typeable)
95
97
96-- | The object provides metadata about the API.
98-- | The object provides metadata about the API.
97-- The metadata can be used by the clients if needed,
99-- The metadata can be used by the clients if needed,
@@ -116,7 +118,7 @@ data Info = Info
116 -- | Provides the version of the application API
118 -- | Provides the version of the application API
117 -- (not to be confused with the specification version).
119 -- (not to be confused with the specification version).
118 , _infoVersion :: Text
120 , _infoVersion :: Text
119− } deriving (Eq, Show, Generic)
121+ } deriving (Eq, Show, Generic, Data, Typeable)
120
122
121-- | Contact information for the exposed API.
123-- | Contact information for the exposed API.
122data Contact = Contact
124data Contact = Contact
@@ -128,7 +130,7 @@ data Contact = Contact
128
130
129 -- | The email address of the contact person/organization.
131 -- | The email address of the contact person/organization.
130 , _contactEmail :: Maybe Text
132 , _contactEmail :: Maybe Text
131− } deriving (Eq, Show)
133+ } deriving (Eq, Show, Generic, Data, Typeable)
132
134
133-- | License information for the exposed API.
135-- | License information for the exposed API.
134data License = License
136data License = License
@@ -137,13 +139,26 @@ data License = License
137
139
138 -- | A URL to the license used for the API.
140 -- | A URL to the license used for the API.
139 , _licenseUrl :: Maybe URL
141 , _licenseUrl :: Maybe URL
140− } deriving (Eq, Show)
142+ } deriving (Eq, Show, Generic, Data, Typeable)
141
143
142-- | The host (name or ip) serving the API. It MAY include a port.
144-- | The host (name or ip) serving the API. It MAY include a port.
143data Host = Host
145data Host = Host
144 { _hostName :: HostName -- ^ Host name.
146 { _hostName :: HostName -- ^ Host name.
145 , _hostPort :: Maybe PortNumber -- ^ Optional port.
147 , _hostPort :: Maybe PortNumber -- ^ Optional port.
146− } deriving (Eq, Show)
148+ } deriving (Eq, Show, Generic, Typeable)
149+
150+hostConstr :: Constr
151+hostConstr = mkConstr hostDataType "Host" [] Prefix
152+
153+hostDataType :: DataType
154+hostDataType = mkDataType "Data.Swagger.Host" [hostConstr]
155+
156+instance Data Host where
157+ gunfold k z c = case constrIndex c of
158+ 1 -> k (k (z (\name mport -> Host name (fromInteger <$> mport))))
159+ _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type Host."
160+ toConstr (Host _ _) = hostConstr
161+ dataTypeOf _ = hostDataType
147
162
148-- | The transfer protocol of the API.
163-- | The transfer protocol of the API.
149data Scheme
164data Scheme
@@ -151,14 +166,14 @@ data Scheme
151 | Https
166 | Https
152 | Ws
167 | Ws
153 | Wss
168 | Wss
154− deriving (Eq, Show)
169+ deriving (Eq, Show, Generic, Data, Typeable)
155
170
156-- | The available paths and operations for the API.
171-- | The available paths and operations for the API.
157data Paths = Paths
172data Paths = Paths
158 { -- | Holds the relative paths to the individual endpoints.
173 { -- | Holds the relative paths to the individual endpoints.
159 -- The path is appended to the @'basePath'@ in order to construct the full URL.
174 -- The path is appended to the @'basePath'@ in order to construct the full URL.
160 _pathsMap :: HashMap FilePath PathItem
175 _pathsMap :: HashMap FilePath PathItem
161− } deriving (Eq, Show, Generic)
176+ } deriving (Eq, Show, Generic, Data, Typeable)
162
177
163-- | Describes the operations available on a single path.
178-- | Describes the operations available on a single path.
164-- A @'PathItem'@ may be empty, due to ACL constraints.
179-- A @'PathItem'@ may be empty, due to ACL constraints.
@@ -191,7 +206,7 @@ data PathItem = PathItem
191 -- The list MUST NOT include duplicated parameters.
206 -- The list MUST NOT include duplicated parameters.
192 -- A unique parameter is defined by a combination of a name and location.
207 -- A unique parameter is defined by a combination of a name and location.
193 , _pathItemParameters :: [Referenced Param]
208 , _pathItemParameters :: [Referenced Param]
194− } deriving (Eq, Show, Generic)
209+ } deriving (Eq, Show, Generic, Data, Typeable)
195
210
196-- | Describes a single API operation on a path.
211-- | Describes a single API operation on a path.
197data Operation = Operation
212data Operation = Operation
@@ -251,10 +266,23 @@ data Operation = Operation
251 -- This definition overrides any declared top-level security.
266 -- This definition overrides any declared top-level security.
252 -- To remove a top-level security declaration, @Just []@ can be used.
267 -- To remove a top-level security declaration, @Just []@ can be used.
253 , _operationSecurity :: [SecurityRequirement]
268 , _operationSecurity :: [SecurityRequirement]
254− } deriving (Eq, Show, Generic)
269+ } deriving (Eq, Show, Generic, Data, Typeable)
255
270
256newtype MimeList = MimeList { getMimeList :: [MediaType] }
271newtype MimeList = MimeList { getMimeList :: [MediaType] }
257− deriving (Eq, Show, Monoid)
272+ deriving (Eq, Show, Monoid, Typeable)
273+
274+mimeListConstr :: Constr
275+mimeListConstr = mkConstr mimeListDataType "MimeList" ["getMimeList"] Prefix
276+
277+mimeListDataType :: DataType
278+mimeListDataType = mkDataType "Data.Swagger.MimeList" [mimeListConstr]
279+
280+instance Data MimeList where
281+ gunfold k z c = case constrIndex c of
282+ 1 -> k (z (\xs -> MimeList (map fromString xs)))
283+ _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type MimeList."
284+ toConstr (MimeList _) = mimeListConstr
285+ dataTypeOf _ = mimeListDataType
258
286
259-- | Describes a single operation parameter.
287-- | Describes a single operation parameter.
260-- A unique parameter is defined by a combination of a name and location.
288-- A unique parameter is defined by a combination of a name and location.
@@ -275,12 +303,12 @@ data Param = Param
275
303
276 -- | Parameter schema.
304 -- | Parameter schema.
277 , _paramSchema :: ParamAnySchema
305 , _paramSchema :: ParamAnySchema
278− } deriving (Eq, Show, Generic)
306+ } deriving (Eq, Show, Generic, Data, Typeable)
279
307
280data ParamAnySchema
308data ParamAnySchema
281 = ParamBody (Referenced Schema)
309 = ParamBody (Referenced Schema)
282 | ParamOther ParamOtherSchema
310 | ParamOther ParamOtherSchema
283− deriving (Eq, Show)
311+ deriving (Eq, Show, Generic, Data, Typeable)
284
312
285data ParamOtherSchema = ParamOtherSchema
313data ParamOtherSchema = ParamOtherSchema
286 { -- | The location of the parameter.
314 { -- | The location of the parameter.
@@ -297,7 +325,7 @@ data ParamOtherSchema = ParamOtherSchema
297 , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
325 , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
298
326
299 , _paramOtherSchemaParamSchema :: ParamSchema ParamOtherSchema Items
327 , _paramOtherSchemaParamSchema :: ParamSchema ParamOtherSchema Items
300− } deriving (Eq, Show, Generic)
328+ } deriving (Eq, Show, Generic, Data, Typeable)
301
329
302data SwaggerType t where
330data SwaggerType t where
303 SwaggerString :: SwaggerType t
331 SwaggerString :: SwaggerType t
@@ -311,6 +339,75 @@ data SwaggerType t where
311
339
312deriving instance Eq (SwaggerType t)
340deriving instance Eq (SwaggerType t)
313deriving instance Show (SwaggerType t)
341deriving instance Show (SwaggerType t)
342+deriving instance Typeable (SwaggerType t)
343+
344+swaggerStringConstr :: DataType -> Constr
345+swaggerStringConstr dt = mkConstr dt "SwaggerString" [] Prefix
346+
347+swaggerNumberConstr :: DataType -> Constr
348+swaggerNumberConstr dt = mkConstr dt "SwaggerNumber" [] Prefix
349+
350+swaggerIntegerConstr :: DataType -> Constr
351+swaggerIntegerConstr dt = mkConstr dt "SwaggerInteger" [] Prefix
352+
353+swaggerBooleanConstr :: DataType -> Constr
354+swaggerBooleanConstr dt = mkConstr dt "SwaggerBoolean" [] Prefix
355+
356+swaggerArrayConstr :: DataType -> Constr
357+swaggerArrayConstr dt = mkConstr dt "SwaggerArray" [] Prefix
358+
359+swaggerFileConstr :: DataType -> Constr
360+swaggerFileConstr dt = mkConstr dt "SwaggerFile" [] Prefix
361+
362+swaggerNullConstr :: DataType -> Constr
363+swaggerNullConstr dt = mkConstr dt "SwaggerNull" [] Prefix
364+
365+swaggerObjectConstr :: DataType -> Constr
366+swaggerObjectConstr dt = mkConstr dt "SwaggerObject" [] Prefix
367+
368+swaggerTypeDataType :: [DataType -> Constr] -> DataType
369+swaggerTypeDataType extra = dt
370+ where
371+ dt = mkDataType "Data.Swagger.SwaggerType" $ map ($ dt) $
372+ [ swaggerStringConstr, swaggerNumberConstr, swaggerIntegerConstr, swaggerBooleanConstr , swaggerArrayConstr ]
373+ ++ extra
374+
375+swaggerTypeToConstr :: Data (SwaggerType t) => SwaggerType t -> Constr
376+swaggerTypeToConstr t = case t of
377+ SwaggerString -> swaggerStringConstr dt
378+ SwaggerNumber -> swaggerNumberConstr dt
379+ SwaggerInteger -> swaggerIntegerConstr dt
380+ SwaggerBoolean -> swaggerBooleanConstr dt
381+ SwaggerArray -> swaggerArrayConstr dt
382+ SwaggerFile -> swaggerFileConstr dt
383+ SwaggerNull -> swaggerNullConstr dt
384+ SwaggerObject -> swaggerObjectConstr dt
385+ where
386+ dt = dataTypeOf t
387+
388+instance Data (SwaggerType Items) where
389+ gunfold = gunfoldEnum "SwaggerType Items" $ zip [1..]
390+ [SwaggerString, SwaggerNumber, SwaggerInteger, SwaggerBoolean, SwaggerArray]
391+ toConstr = swaggerTypeToConstr
392+ dataTypeOf _ = swaggerTypeDataType []
393+
394+instance Data (SwaggerType Header) where
395+ gunfold = gunfoldEnum "SwaggerType Header" $ zip [1..]
396+ [SwaggerString, SwaggerNumber, SwaggerInteger, SwaggerBoolean, SwaggerArray]
397+ toConstr = swaggerTypeToConstr
398+ dataTypeOf _ = swaggerTypeDataType []
399+
400+instance Data (SwaggerType ParamOtherSchema) where
401+ gunfold = gunfoldEnum "SwaggerType ParamOtherSchema" $ zip [1..]
402+ [SwaggerString, SwaggerNumber, SwaggerInteger, SwaggerBoolean, SwaggerArray, SwaggerFile]
403+ toConstr = swaggerTypeToConstr
404+ dataTypeOf _ = swaggerTypeDataType [swaggerFileConstr]
405+
406+instance Data (SwaggerType Schema) where
407+ gunfold = gunfoldEnum "SwaggerType Schema" $ zip [1, 2, 3, 4, 5, 7, 8]
408+ [SwaggerString, SwaggerNumber, SwaggerInteger, SwaggerBoolean, SwaggerArray, SwaggerNull, SwaggerObject]
409+ toConstr = swaggerTypeToConstr
410+ dataTypeOf _ = swaggerTypeDataType [swaggerNullConstr, swaggerObjectConstr]
314
411
315data ParamLocation
412data ParamLocation
316 = -- | Parameters that are appended to the URL.
413 = -- | Parameters that are appended to the URL.
@@ -330,7 +427,7 @@ data ParamLocation
330 -- Form parameters have a different format based on the content-type used
427 -- Form parameters have a different format based on the content-type used
331 -- (for further details, consult <http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4>).
428 -- (for further details, consult <http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4>).
332 | ParamFormData
429 | ParamFormData
333− deriving (Eq, Show)
430+ deriving (Eq, Show, Generic, Data, Typeable)
334
431
335type Format = Text
432type Format = Text
336
433
@@ -351,6 +448,36 @@ data CollectionFormat t where
351
448
352deriving instance Eq (CollectionFormat t)
449deriving instance Eq (CollectionFormat t)
353deriving instance Show (CollectionFormat t)
450deriving instance Show (CollectionFormat t)
451+deriving instance Typeable (CollectionFormat t)
452+
453+collectionCsvConstr :: Constr
454+collectionCsvConstr = mkConstr collectionFormatDataType "CollectionCSV" [] Prefix
455+
456+collectionSsvConstr :: Constr
457+collectionSsvConstr = mkConstr collectionFormatDataType "CollectionSSV" [] Prefix
458+
459+collectionTsvConstr :: Constr
460+collectionTsvConstr = mkConstr collectionFormatDataType "CollectionTSV" [] Prefix
461+
462+collectionPipesConstr :: Constr
463+collectionPipesConstr = mkConstr collectionFormatDataType "CollectionPipes" [] Prefix
464+
465+collectionFormatDataType :: DataType
466+collectionFormatDataType = mkDataType "Data.Swagger.CollectionFormat"
467+ [ collectionCsvConstr, collectionSsvConstr, collectionTsvConstr, collectionPipesConstr ]
468+
469+instance {-# OVERLAPPABLE #-} Data t => Data (CollectionFormat t) where
470+ gunfold = gunfoldEnum "CollectionFormat" $ zip [1..]
471+ [ CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes ]
472+
473+ toConstr CollectionCSV = collectionCsvConstr
474+ toConstr CollectionSSV = collectionSsvConstr
475+ toConstr CollectionTSV = collectionTsvConstr
476+ toConstr CollectionPipes = collectionPipesConstr
477+
478+ dataTypeOf _ = collectionFormatDataType
479+
480+deriving instance {-# OVERLAPPING #-} Data (CollectionFormat Param)
354
481
355type ParamName = Text
482type ParamName = Text
356
483
@@ -373,12 +500,12 @@ data Schema = Schema
373 , _schemaMinProperties :: Maybe Integer
500 , _schemaMinProperties :: Maybe Integer
374
501
375 , _schemaParamSchema :: ParamSchema Schema SchemaItems
502 , _schemaParamSchema :: ParamSchema Schema SchemaItems
376− } deriving (Eq, Show, Generic)
503+ } deriving (Eq, Show, Generic, Data, Typeable)
377
504
378data SchemaItems
505data SchemaItems
379 = SchemaItemsObject (Referenced Schema)
506 = SchemaItemsObject (Referenced Schema)
380 | SchemaItemsArray [Referenced Schema]
507 | SchemaItemsArray [Referenced Schema]
381− deriving (Eq, Show)
508+ deriving (Eq, Show, Generic, Data, Typeable)
382
509
383data ParamSchema t items = ParamSchema
510data ParamSchema t items = ParamSchema
384 { -- | Declares the value of the parameter that the server will use if none is provided,
511 { -- | Declares the value of the parameter that the server will use if none is provided,
@@ -403,7 +530,9 @@ data ParamSchema t items = ParamSchema
403 , _paramSchemaUniqueItems :: Maybe Bool
530 , _paramSchemaUniqueItems :: Maybe Bool
404 , _paramSchemaEnum :: Maybe [Value]
531 , _paramSchemaEnum :: Maybe [Value]
405 , _paramSchemaMultipleOf :: Maybe Scientific
532 , _paramSchemaMultipleOf :: Maybe Scientific
406− } deriving (Eq, Show, Generic)
533+ } deriving (Eq, Show, Generic, Typeable)
534+
535+deriving instance (Data t, Data (SwaggerType t), Data i) => Data (ParamSchema t i)
407
536
408data Xml = Xml
537data Xml = Xml
409 { -- | Replaces the name of the element/attribute used for the described schema property.
538 { -- | Replaces the name of the element/attribute used for the described schema property.
@@ -431,7 +560,7 @@ data Xml = Xml
431 -- Default value is @False@.
560 -- Default value is @False@.
432 -- The definition takes effect only when defined alongside type being array (outside the items).
561 -- The definition takes effect only when defined alongside type being array (outside the items).
433 , _xmlWrapped :: Maybe Bool
562 , _xmlWrapped :: Maybe Bool
434− } deriving (Eq, Show, Generic)
563+ } deriving (Eq, Show, Generic, Data, Typeable)
435
564
436data Items = Items
565data Items = Items
437 { -- | Determines the format of the array if type array is used.
566 { -- | Determines the format of the array if type array is used.
@@ -439,7 +568,7 @@ data Items = Items
439 _itemsCollectionFormat :: Maybe (CollectionFormat Items)
568 _itemsCollectionFormat :: Maybe (CollectionFormat Items)
440
569
441 , _itemsParamSchema :: ParamSchema Items Items
570 , _itemsParamSchema :: ParamSchema Items Items
442− } deriving (Eq, Show, Generic)
571+ } deriving (Eq, Show, Generic, Data, Typeable)
443
572
444-- | A container for the expected responses of an operation.
573-- | A container for the expected responses of an operation.
445-- The container maps a HTTP response code to the expected response.
574-- The container maps a HTTP response code to the expected response.
@@ -454,7 +583,7 @@ data Responses = Responses
454 -- | Any HTTP status code can be used as the property name (one property per HTTP status code).
583 -- | Any HTTP status code can be used as the property name (one property per HTTP status code).
455 -- Describes the expected response for those HTTP status codes.
584 -- Describes the expected response for those HTTP status codes.
456 , _responsesResponses :: HashMap HttpStatusCode (Referenced Response)
585 , _responsesResponses :: HashMap HttpStatusCode (Referenced Response)
457− } deriving (Eq, Show, Generic)
586+ } deriving (Eq, Show, Generic, Data, Typeable)
458
587
459type HttpStatusCode = Int
588type HttpStatusCode = Int
460
589
@@ -476,7 +605,7 @@ data Response = Response
476
605
477 -- | An example of the response message.
606 -- | An example of the response message.
478 , _responseExamples :: Maybe Example
607 , _responseExamples :: Maybe Example
479− } deriving (Eq, Show, Generic)
608+ } deriving (Eq, Show, Generic, Data, Typeable)
480
609
481type HeaderName = Text
610type HeaderName = Text
482
611
@@ -489,16 +618,29 @@ data Header = Header
489 , _headerCollectionFormat :: Maybe (CollectionFormat Items)
618 , _headerCollectionFormat :: Maybe (CollectionFormat Items)
490
619
491 , _headerParamSchema :: ParamSchema Header Items
620 , _headerParamSchema :: ParamSchema Header Items
492− } deriving (Eq, Show, Generic)
621+ } deriving (Eq, Show, Generic, Data, Typeable)
493
622
494data Example = Example { getExample :: Map MediaType Value }
623data Example = Example { getExample :: Map MediaType Value }
495− deriving (Eq, Show)
624+ deriving (Eq, Show, Generic, Typeable)
625+
626+exampleConstr :: Constr
627+exampleConstr = mkConstr exampleDataType "Example" ["getExample"] Prefix
628+
629+exampleDataType :: DataType
630+exampleDataType = mkDataType "Data.Swagger.Example" [exampleConstr]
631+
632+instance Data Example where
633+ gunfold k z c = case constrIndex c of
634+ 1 -> k (z (\m -> Example (Map.mapKeys fromString m)))
635+ _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type Example."
636+ toConstr (Example _) = exampleConstr
637+ dataTypeOf _ = exampleDataType
496
638
497-- | The location of the API key.
639-- | The location of the API key.
498data ApiKeyLocation
640data ApiKeyLocation
499 = ApiKeyQuery
641 = ApiKeyQuery
500 | ApiKeyHeader
642 | ApiKeyHeader
501− deriving (Eq, Show)
643+ deriving (Eq, Show, Generic, Data, Typeable)
502
644
503data ApiKeyParams = ApiKeyParams
645data ApiKeyParams = ApiKeyParams
504 { -- | The name of the header or query parameter to be used.
646 { -- | The name of the header or query parameter to be used.
@@ -506,7 +648,7 @@ data ApiKeyParams = ApiKeyParams
506
648
507 -- | The location of the API key.
649 -- | The location of the API key.
508 , _apiKeyIn :: ApiKeyLocation
650 , _apiKeyIn :: ApiKeyLocation
509− } deriving (Eq, Show)
651+ } deriving (Eq, Show, Generic, Data, Typeable)
510
652
511-- | The authorization URL to be used for OAuth2 flow. This SHOULD be in the form of a URL.
653-- | The authorization URL to be used for OAuth2 flow. This SHOULD be in the form of a URL.
512type AuthorizationURL = Text
654type AuthorizationURL = Text
@@ -519,7 +661,7 @@ data OAuth2Flow
519 | OAuth2Password TokenURL
661 | OAuth2Password TokenURL
520 | OAuth2Application TokenURL
662 | OAuth2Application TokenURL
521 | OAuth2AccessCode AuthorizationURL TokenURL
663 | OAuth2AccessCode AuthorizationURL TokenURL
522− deriving (Eq, Show)
664+ deriving (Eq, Show, Generic, Data, Typeable)
523
665
524data OAuth2Params = OAuth2Params
666data OAuth2Params = OAuth2Params
525 { -- | The flow used by the OAuth2 security scheme.
667 { -- | The flow used by the OAuth2 security scheme.
@@ -527,13 +669,13 @@ data OAuth2Params = OAuth2Params
527
669
528 -- | The available scopes for the OAuth2 security scheme.
670 -- | The available scopes for the OAuth2 security scheme.
529 , _oauth2Scopes :: HashMap Text Text
671 , _oauth2Scopes :: HashMap Text Text
530− } deriving (Eq, Show, Generic)
672+ } deriving (Eq, Show, Generic, Data, Typeable)
531
673
532data SecuritySchemeType
674data SecuritySchemeType
533 = SecuritySchemeBasic
675 = SecuritySchemeBasic
534 | SecuritySchemeApiKey ApiKeyParams
676 | SecuritySchemeApiKey ApiKeyParams
535 | SecuritySchemeOAuth2 OAuth2Params
677 | SecuritySchemeOAuth2 OAuth2Params
536− deriving (Eq, Show)
678+ deriving (Eq, Show, Generic, Data, Typeable)
537
679
538data SecurityScheme = SecurityScheme
680data SecurityScheme = SecurityScheme
539 { -- | The type of the security scheme.
681 { -- | The type of the security scheme.
@@ -541,14 +683,14 @@ data SecurityScheme = SecurityScheme
541
683
542 -- | A short description for security scheme.
684 -- | A short description for security scheme.
543 , _securitySchemeDescription :: Maybe Text
685 , _securitySchemeDescription :: Maybe Text
544− } deriving (Eq, Show, Generic)
686+ } deriving (Eq, Show, Generic, Data, Typeable)
545
687
546-- | Lists the required security schemes to execute this operation.
688-- | Lists the required security schemes to execute this operation.
547-- The object can have multiple security schemes declared in it which are all required
689-- The object can have multiple security schemes declared in it which are all required
548-- (that is, there is a logical AND between the schemes).
690-- (that is, there is a logical AND between the schemes).
549newtype SecurityRequirement = SecurityRequirement
691newtype SecurityRequirement = SecurityRequirement
550 { getSecurityRequirement :: HashMap Text [Text]
692 { getSecurityRequirement :: HashMap Text [Text]
551− } deriving (Eq, Read, Show, Monoid, ToJSON, FromJSON)
693+ } deriving (Eq, Read, Show, Monoid, ToJSON, FromJSON, Data, Typeable)
552
694
553-- | Allows adding meta data to a single tag that is used by @Operation@.
695-- | Allows adding meta data to a single tag that is used by @Operation@.
554-- It is not mandatory to have a @Tag@ per tag used there.
696-- It is not mandatory to have a @Tag@ per tag used there.
@@ -562,7 +704,7 @@ data Tag = Tag
562
704
563 -- | Additional external documentation for this tag.
705 -- | Additional external documentation for this tag.
564 , _tagExternalDocs :: Maybe ExternalDocs
706 , _tagExternalDocs :: Maybe ExternalDocs
565− } deriving (Eq, Show)
707+ } deriving (Eq, Show, Generic, Data, Typeable)
566
708
567-- | Allows referencing an external resource for extended documentation.
709-- | Allows referencing an external resource for extended documentation.
568data ExternalDocs = ExternalDocs
710data ExternalDocs = ExternalDocs
@@ -572,19 +714,19 @@ data ExternalDocs = ExternalDocs
572
714
573 -- | The URL for the target documentation.
715 -- | The URL for the target documentation.
574 , _externalDocsUrl :: URL
716 , _externalDocsUrl :: URL
575− } deriving (Eq, Show, Generic)
717+ } deriving (Eq, Show, Generic, Data, Typeable)
576
718
577-- | A simple object to allow referencing other definitions in the specification.
719-- | A simple object to allow referencing other definitions in the specification.
578-- It can be used to reference parameters and responses that are defined at the top level for reuse.
720-- It can be used to reference parameters and responses that are defined at the top level for reuse.
579newtype Reference = Reference { getReference :: Text }
721newtype Reference = Reference { getReference :: Text }
580− deriving (Eq, Show)
722+ deriving (Eq, Show, Data, Typeable)
581
723
582data Referenced a
724data Referenced a
583 = Ref Reference
725 = Ref Reference
584 | Inline a
726 | Inline a
585− deriving (Eq, Show)
727+ deriving (Eq, Show, Data, Typeable)
586
728
587−newtype URL = URL { getUrl :: Text } deriving (Eq, Show, ToJSON, FromJSON)
729+newtype URL = URL { getUrl :: Text } deriving (Eq, Show, ToJSON, FromJSON, Data, Typeable)
588
730
589-- =======================================================================
731-- =======================================================================
590-- Monoid instances
732-- Monoid instances
src/Data/Swagger/Internal/Utils.hs+7
@@ -1,6 +1,7 @@
1{-# LANGUAGE DefaultSignatures #-}
1{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE RankNTypes #-}
4{-# LANGUAGE TypeOperators #-}
5{-# LANGUAGE TypeOperators #-}
5module Data.Swagger.Internal.Utils where
6module Data.Swagger.Internal.Utils where
6
7
@@ -10,6 +11,7 @@ import Data.Aeson
10import Data.Aeson.TH
11import Data.Aeson.TH
11import Data.Aeson.Types (Parser, Pair)
12import Data.Aeson.Types (Parser, Pair)
12import Data.Char
13import Data.Char
14+import Data.Data
13import Data.Hashable (Hashable)
15import Data.Hashable (Hashable)
14import Data.HashMap.Strict (HashMap)
16import Data.HashMap.Strict (HashMap)
15import qualified Data.HashMap.Strict as HashMap
17import qualified Data.HashMap.Strict as HashMap
@@ -19,6 +21,11 @@ import GHC.Generics
19import Language.Haskell.TH
21import Language.Haskell.TH
20import Text.Read (readMaybe)
22import Text.Read (readMaybe)
21
23
24+gunfoldEnum :: String -> [(ConIndex, a)] -> (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a
25+gunfoldEnum tname xs _k z c = case lookup (constrIndex c) xs of
26+ Just x -> z x
27+ Nothing -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type " ++ tname ++ "."
28+
22hashMapMapKeys :: (Eq k', Hashable k') => (k -> k') -> HashMap k v -> HashMap k' v
29hashMapMapKeys :: (Eq k', Hashable k') => (k -> k') -> HashMap k v -> HashMap k' v
23hashMapMapKeys f = HashMap.fromList . map (first f) . HashMap.toList
30hashMapMapKeys f = HashMap.fromList . map (first f) . HashMap.toList
24
31