@@ -196,8 +196,8 @@ data Components = Components
196
196
, _componentsRequestBodies :: Definitions RequestBody
197
197
, _componentsHeader :: Definitions Header
198
198
, _componentsSecuritySchemes :: Definitions SecurityScheme
199
- -- , _componentsLinks
200
- -- , _componentsCallbacks
199
+ , _componentsLinks :: Definitions Link
200
+ , _componentsCallbacks :: Definitions Callback
201
201
} deriving (Eq , Show , Generic , Data , Typeable )
202
202
203
203
-- | Describes the operations available on a single path.
@@ -287,7 +287,11 @@ data Operation = Operation
287
287
-- | The list of possible responses as they are returned from executing this operation.
288
288
, _operationResponses :: Responses
289
289
290
- -- TODO callbacks
290
+ -- | A map of possible out-of band callbacks related to the parent operation.
291
+ -- The key is a unique identifier for the 'Callback' Object.
292
+ -- Each value in the map is a 'Callback' Object that describes a request
293
+ -- that may be initiated by the API provider and the expected responses.
294
+ , _operationCallbacks :: InsOrdHashMap Text (Referenced Callback )
291
295
292
296
-- | Declares this operation to be deprecated.
293
297
-- Usage of the declared operation should be refrained.
@@ -519,6 +523,42 @@ data Example = Example
519
523
, _exampleExternalValue :: Maybe URL
520
524
} deriving (Eq , Show , Generic , Typeable , Data )
521
525
526
+ data ExpressionOrValue
527
+ = Expression Text
528
+ | Value Value
529
+ deriving (Eq , Show , Generic , Typeable , Data )
530
+
531
+ -- | The Link object represents a possible design-time link for a response.
532
+ -- The presence of a link does not guarantee the caller's ability to successfully invoke it,
533
+ -- rather it provides a known relationship and traversal mechanism between responses and other operations.
534
+ data Link = Link
535
+ { -- | A relative or absolute URI reference to an OAS operation.
536
+ -- This field is mutually exclusive of the '_linkOperationId' field,
537
+ -- and MUST point to an 'Operation' Object. Relative '_linkOperationRef'
538
+ -- values MAY be used to locate an existing 'Operation' Object in the OpenAPI definition.
539
+ _linkOperationRef :: Maybe Text
540
+
541
+ -- | The name of an /existing/, resolvable OAS operation, as defined with a unique
542
+ -- '_operationOperationId'. This field is mutually exclusive of the '_linkOperationRef' field.
543
+ , _linkOperationId :: Maybe Text
544
+
545
+ -- | A map representing parameters to pass to an operation as specified with '_linkOperationId'
546
+ -- or identified via '_linkOperationRef'. The key is the parameter name to be used, whereas
547
+ -- the value can be a constant or an expression to be evaluated and passed to the linked operation.
548
+ -- The parameter name can be qualified using the parameter location @[{in}.]{name}@
549
+ -- for operations that use the same parameter name in different locations (e.g. path.id).
550
+ , _linkParameters :: InsOrdHashMap Text ExpressionOrValue
551
+
552
+ -- | A literal value or @{expression}@ to use as a request body when calling the target operation.
553
+ , _linkRequestBody :: Maybe ExpressionOrValue
554
+
555
+ -- | A description of the link.
556
+ , _linkDescription :: Maybe Text
557
+
558
+ -- | A server object to be used by the target operation.
559
+ , _linkServer :: Maybe Server
560
+ } deriving (Eq , Show , Generic , Typeable , Data )
561
+
522
562
-- | Items for @'SwaggerArray'@ schemas.
523
563
--
524
564
-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
@@ -690,19 +730,29 @@ data Response = Response
690
730
-- | Maps a header name to its definition.
691
731
, _responseHeaders :: InsOrdHashMap HeaderName (Referenced Header )
692
732
693
- -- TODO links
733
+ -- | A map of operations links that can be followed from the response.
734
+ -- The key of the map is a short name for the link, following the naming
735
+ -- constraints of the names for 'Component' Objects.
736
+ , _responseLinks :: InsOrdHashMap Text (Referenced Link )
694
737
} deriving (Eq , Show , Generic , Data , Typeable )
695
738
696
739
instance IsString Response where
697
- fromString s = Response (fromString s) mempty mempty
740
+ fromString s = Response (fromString s) mempty mempty mempty
741
+
742
+ -- | A map of possible out-of band callbacks related to the parent operation.
743
+ -- Each value in the map is a 'PathItem' Object that describes a set of requests that
744
+ -- may be initiated by the API provider and the expected responses.
745
+ -- The key value used to identify the path item object is an expression, evaluated at runtime,
746
+ -- that identifies a URL to use for the callback operation.
747
+ newtype Callback = Callback (InsOrdHashMap Text PathItem )
748
+ deriving (Eq , Show , Generic , Data , Typeable )
698
749
699
750
type HeaderName = Text
700
751
701
-
702
752
-- TODO this is mostly a copy of 'Param'.
703
753
data Header = Header
704
754
{ -- | A short description of the header.
705
- _headerDescription :: Maybe Text
755
+ _headerDescription :: Maybe HeaderName
706
756
707
757
, _headerSchema :: Maybe (Referenced Schema )
708
758
} deriving (Eq , Show , Generic , Data , Typeable )
@@ -873,6 +923,7 @@ deriveGeneric ''ParamSchema
873
923
deriveGeneric ''Swagger
874
924
deriveGeneric ''Example
875
925
deriveGeneric ''Encoding
926
+ deriveGeneric ''Link
876
927
877
928
-- =======================================================================
878
929
-- Monoid instances
@@ -1264,6 +1315,10 @@ instance ToJSON Encoding where
1264
1315
toJSON = sopSwaggerGenericToJSON
1265
1316
toEncoding = sopSwaggerGenericToEncoding
1266
1317
1318
+ instance ToJSON Link where
1319
+ toJSON = sopSwaggerGenericToJSON
1320
+ toEncoding = sopSwaggerGenericToEncoding
1321
+
1267
1322
instance ToJSON SecurityDefinitions where
1268
1323
toJSON (SecurityDefinitions sd) = toJSON sd
1269
1324
@@ -1280,6 +1335,8 @@ instance ToJSON (Referenced Response) where toJSON = referencedToJSON "#/compone
1280
1335
instance ToJSON (Referenced RequestBody ) where toJSON = referencedToJSON " #/components/requestBodies/"
1281
1336
instance ToJSON (Referenced Example ) where toJSON = referencedToJSON " #/components/examples/"
1282
1337
instance ToJSON (Referenced Header ) where toJSON = referencedToJSON " #/components/headers/"
1338
+ instance ToJSON (Referenced Link ) where toJSON = referencedToJSON " #/components/links/"
1339
+ instance ToJSON (Referenced Callback ) where toJSON = referencedToJSON " #/components/callbacks/"
1283
1340
1284
1341
instance ToJSON ParamSchema where
1285
1342
-- TODO: this is a bit fishy, why we need sub object only in `ToJSON`?
@@ -1290,6 +1347,13 @@ instance ToJSON AdditionalProperties where
1290
1347
toJSON (AdditionalPropertiesAllowed b) = toJSON b
1291
1348
toJSON (AdditionalPropertiesSchema s) = toJSON s
1292
1349
1350
+ instance ToJSON ExpressionOrValue where
1351
+ toJSON (Expression expr) = toJSON expr
1352
+ toJSON (Value val) = toJSON val
1353
+
1354
+ instance ToJSON Callback where
1355
+ toJSON (Callback ps) = toJSON ps
1356
+
1293
1357
-- =======================================================================
1294
1358
-- Manual FromJSON instances
1295
1359
-- =======================================================================
@@ -1385,6 +1449,9 @@ instance FromJSON MediaTypeObject where
1385
1449
instance FromJSON Encoding where
1386
1450
parseJSON = sopSwaggerGenericParseJSON
1387
1451
1452
+ instance FromJSON Link where
1453
+ parseJSON = sopSwaggerGenericParseJSON
1454
+
1388
1455
instance FromJSON Reference where
1389
1456
parseJSON (Object o) = Reference <$> o .: " $ref"
1390
1457
parseJSON _ = empty
@@ -1408,6 +1475,8 @@ instance FromJSON (Referenced Response) where parseJSON = referencedParseJSON "#
1408
1475
instance FromJSON (Referenced RequestBody ) where parseJSON = referencedParseJSON " #/components/requestBodies/"
1409
1476
instance FromJSON (Referenced Example ) where parseJSON = referencedParseJSON " #/components/examples/"
1410
1477
instance FromJSON (Referenced Header ) where parseJSON = referencedParseJSON " #/components/headers/"
1478
+ instance FromJSON (Referenced Link ) where parseJSON = referencedParseJSON " #/components/links/"
1479
+ instance FromJSON (Referenced Callback ) where parseJSON = referencedParseJSON " #/components/callbacks/"
1411
1480
1412
1481
instance FromJSON Xml where
1413
1482
parseJSON = genericParseJSON (jsonPrefix " xml" )
@@ -1419,6 +1488,14 @@ instance FromJSON AdditionalProperties where
1419
1488
parseJSON (Bool b) = pure $ AdditionalPropertiesAllowed b
1420
1489
parseJSON js = AdditionalPropertiesSchema <$> parseJSON js
1421
1490
1491
+ -- | All strings are parsed as expressions
1492
+ instance FromJSON ExpressionOrValue where
1493
+ parseJSON (String expr) = pure $ Expression expr
1494
+ parseJSON v = pure $ Value v
1495
+
1496
+ instance FromJSON Callback where
1497
+ parseJSON = fmap Callback . parseJSON
1498
+
1422
1499
instance HasSwaggerAesonOptions Server where
1423
1500
swaggerAesonOptions _ = mkSwaggerAesonOptions " server"
1424
1501
instance HasSwaggerAesonOptions Components where
@@ -1454,6 +1531,9 @@ instance HasSwaggerAesonOptions Example where
1454
1531
instance HasSwaggerAesonOptions Encoding where
1455
1532
swaggerAesonOptions _ = mkSwaggerAesonOptions " encoding"
1456
1533
1534
+ instance HasSwaggerAesonOptions Link where
1535
+ swaggerAesonOptions _ = mkSwaggerAesonOptions " link"
1536
+
1457
1537
instance HasSwaggerAesonOptions ParamSchema where
1458
1538
swaggerAesonOptions _ = mkSwaggerAesonOptions " paramSchema"
1459
1539
@@ -1471,3 +1551,4 @@ instance AesonDefaultValue SwaggerType
1471
1551
instance AesonDefaultValue MimeList where defaultValue = Just mempty
1472
1552
instance AesonDefaultValue Info
1473
1553
instance AesonDefaultValue ParamLocation
1554
+ instance AesonDefaultValue Link
0 commit comments