git.iko.soy/typeable/openapi3
on master help sign in
Add Callback and Link
23caa64Maxim Koltsov
src/Data/Swagger.hs+2
@@ -86,6 +86,8 @@ module Data.Swagger (
86 Responses(..),
86 Responses(..),
87 Response(..),
87 Response(..),
88 HttpStatusCode,
88 HttpStatusCode,
89+ Link(..),
90+ Callback(..),
89
91
90 -- ** Security
92 -- ** Security
91 SecurityScheme(..),
93 SecurityScheme(..),
src/Data/Swagger/Internal.hs+88−7
@@ -196,8 +196,8 @@ data Components = Components
196 , _componentsRequestBodies :: Definitions RequestBody
196 , _componentsRequestBodies :: Definitions RequestBody
197 , _componentsHeader :: Definitions Header
197 , _componentsHeader :: Definitions Header
198 , _componentsSecuritySchemes :: Definitions SecurityScheme
198 , _componentsSecuritySchemes :: Definitions SecurityScheme
199−-- , _componentsLinks
199+ , _componentsLinks :: Definitions Link
200−-- , _componentsCallbacks
200+ , _componentsCallbacks :: Definitions Callback
201 } deriving (Eq, Show, Generic, Data, Typeable)
201 } deriving (Eq, Show, Generic, Data, Typeable)
202
202
203-- | Describes the operations available on a single path.
203-- | Describes the operations available on a single path.
@@ -287,7 +287,11 @@ data Operation = Operation
287 -- | The list of possible responses as they are returned from executing this operation.
287 -- | The list of possible responses as they are returned from executing this operation.
288 , _operationResponses :: Responses
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 -- | Declares this operation to be deprecated.
296 -- | Declares this operation to be deprecated.
293 -- Usage of the declared operation should be refrained.
297 -- Usage of the declared operation should be refrained.
@@ -519,6 +523,42 @@ data Example = Example
519 , _exampleExternalValue :: Maybe URL
523 , _exampleExternalValue :: Maybe URL
520 } deriving (Eq, Show, Generic, Typeable, Data)
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-- | Items for @'SwaggerArray'@ schemas.
562-- | Items for @'SwaggerArray'@ schemas.
523--
563--
524-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
564-- __Warning__: OpenAPI 3.0 does not support tuple arrays. However, OpenAPI 3.1 will, as
@@ -690,19 +730,29 @@ data Response = Response
690 -- | Maps a header name to its definition.
730 -- | Maps a header name to its definition.
691 , _responseHeaders :: InsOrdHashMap HeaderName (Referenced Header)
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 } deriving (Eq, Show, Generic, Data, Typeable)
737 } deriving (Eq, Show, Generic, Data, Typeable)
695
738
696instance IsString Response where
739instance 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
699type HeaderName = Text
750type HeaderName = Text
700
751
701−
702-- TODO this is mostly a copy of 'Param'.
752-- TODO this is mostly a copy of 'Param'.
703data Header = Header
753data Header = Header
704 { -- | A short description of the header.
754 { -- | A short description of the header.
705− _headerDescription :: Maybe Text
755+ _headerDescription :: Maybe HeaderName
706
756
707 , _headerSchema :: Maybe (Referenced Schema)
757 , _headerSchema :: Maybe (Referenced Schema)
708 } deriving (Eq, Show, Generic, Data, Typeable)
758 } deriving (Eq, Show, Generic, Data, Typeable)
@@ -873,6 +923,7 @@ deriveGeneric ''ParamSchema
873deriveGeneric ''Swagger
923deriveGeneric ''Swagger
874deriveGeneric ''Example
924deriveGeneric ''Example
875deriveGeneric ''Encoding
925deriveGeneric ''Encoding
926+deriveGeneric ''Link
876
927
877-- =======================================================================
928-- =======================================================================
878-- Monoid instances
929-- Monoid instances
@@ -1264,6 +1315,10 @@ instance ToJSON Encoding where
1264 toJSON = sopSwaggerGenericToJSON
1315 toJSON = sopSwaggerGenericToJSON
1265 toEncoding = sopSwaggerGenericToEncoding
1316 toEncoding = sopSwaggerGenericToEncoding
1266
1317
1318+instance ToJSON Link where
1319+ toJSON = sopSwaggerGenericToJSON
1320+ toEncoding = sopSwaggerGenericToEncoding
1321+
1267instance ToJSON SecurityDefinitions where
1322instance ToJSON SecurityDefinitions where
1268 toJSON (SecurityDefinitions sd) = toJSON sd
1323 toJSON (SecurityDefinitions sd) = toJSON sd
1269
1324
@@ -1280,6 +1335,8 @@ instance ToJSON (Referenced Response) where toJSON = referencedToJSON "#/compone
1280instance ToJSON (Referenced RequestBody) where toJSON = referencedToJSON "#/components/requestBodies/"
1335instance ToJSON (Referenced RequestBody) where toJSON = referencedToJSON "#/components/requestBodies/"
1281instance ToJSON (Referenced Example) where toJSON = referencedToJSON "#/components/examples/"
1336instance ToJSON (Referenced Example) where toJSON = referencedToJSON "#/components/examples/"
1282instance ToJSON (Referenced Header) where toJSON = referencedToJSON "#/components/headers/"
1337instance 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
1284instance ToJSON ParamSchema where
1341instance ToJSON ParamSchema where
1285 -- TODO: this is a bit fishy, why we need sub object only in `ToJSON`?
1342 -- TODO: this is a bit fishy, why we need sub object only in `ToJSON`?
@@ -1290,6 +1347,13 @@ instance ToJSON AdditionalProperties where
1290 toJSON (AdditionalPropertiesAllowed b) = toJSON b
1347 toJSON (AdditionalPropertiesAllowed b) = toJSON b
1291 toJSON (AdditionalPropertiesSchema s) = toJSON s
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-- Manual FromJSON instances
1358-- Manual FromJSON instances
1295-- =======================================================================
1359-- =======================================================================
@@ -1385,6 +1449,9 @@ instance FromJSON MediaTypeObject where
1385instance FromJSON Encoding where
1449instance FromJSON Encoding where
1386 parseJSON = sopSwaggerGenericParseJSON
1450 parseJSON = sopSwaggerGenericParseJSON
1387
1451
1452+instance FromJSON Link where
1453+ parseJSON = sopSwaggerGenericParseJSON
1454+
1388instance FromJSON Reference where
1455instance FromJSON Reference where
1389 parseJSON (Object o) = Reference <$> o .: "$ref"
1456 parseJSON (Object o) = Reference <$> o .: "$ref"
1390 parseJSON _ = empty
1457 parseJSON _ = empty
@@ -1408,6 +1475,8 @@ instance FromJSON (Referenced Response) where parseJSON = referencedParseJSON "#
1408instance FromJSON (Referenced RequestBody) where parseJSON = referencedParseJSON "#/components/requestBodies/"
1475instance FromJSON (Referenced RequestBody) where parseJSON = referencedParseJSON "#/components/requestBodies/"
1409instance FromJSON (Referenced Example) where parseJSON = referencedParseJSON "#/components/examples/"
1476instance FromJSON (Referenced Example) where parseJSON = referencedParseJSON "#/components/examples/"
1410instance FromJSON (Referenced Header) where parseJSON = referencedParseJSON "#/components/headers/"
1477instance 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
1412instance FromJSON Xml where
1481instance FromJSON Xml where
1413 parseJSON = genericParseJSON (jsonPrefix "xml")
1482 parseJSON = genericParseJSON (jsonPrefix "xml")
@@ -1419,6 +1488,14 @@ instance FromJSON AdditionalProperties where
1419 parseJSON (Bool b) = pure $ AdditionalPropertiesAllowed b
1488 parseJSON (Bool b) = pure $ AdditionalPropertiesAllowed b
1420 parseJSON js = AdditionalPropertiesSchema <$> parseJSON js
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+
1422instance HasSwaggerAesonOptions Server where
1499instance HasSwaggerAesonOptions Server where
1423 swaggerAesonOptions _ = mkSwaggerAesonOptions "server"
1500 swaggerAesonOptions _ = mkSwaggerAesonOptions "server"
1424instance HasSwaggerAesonOptions Components where
1501instance HasSwaggerAesonOptions Components where
@@ -1454,6 +1531,9 @@ instance HasSwaggerAesonOptions Example where
1454instance HasSwaggerAesonOptions Encoding where
1531instance HasSwaggerAesonOptions Encoding where
1455 swaggerAesonOptions _ = mkSwaggerAesonOptions "encoding"
1532 swaggerAesonOptions _ = mkSwaggerAesonOptions "encoding"
1456
1533
1534+instance HasSwaggerAesonOptions Link where
1535+ swaggerAesonOptions _ = mkSwaggerAesonOptions "link"
1536+
1457instance HasSwaggerAesonOptions ParamSchema where
1537instance HasSwaggerAesonOptions ParamSchema where
1458 swaggerAesonOptions _ = mkSwaggerAesonOptions "paramSchema"
1538 swaggerAesonOptions _ = mkSwaggerAesonOptions "paramSchema"
1459
1539
@@ -1471,3 +1551,4 @@ instance AesonDefaultValue SwaggerType
1471instance AesonDefaultValue MimeList where defaultValue = Just mempty
1551instance AesonDefaultValue MimeList where defaultValue = Just mempty
1472instance AesonDefaultValue Info
1552instance AesonDefaultValue Info
1473instance AesonDefaultValue ParamLocation
1553instance AesonDefaultValue ParamLocation
1554+instance AesonDefaultValue Link
src/Data/Swagger/Lens.hs+1
@@ -59,6 +59,7 @@ makeFields ''ExternalDocs
59makeFields ''Encoding
59makeFields ''Encoding
60makeFields ''Example
60makeFields ''Example
61makeFields ''Discriminator
61makeFields ''Discriminator
62+makeFields ''Link
62
63
63-- * Prisms
64-- * Prisms
64-- ** 'SecuritySchemeType' prisms
65-- ** 'SecuritySchemeType' prisms
src/Data/Swagger/Optics.hs+1
@@ -97,6 +97,7 @@ makeFieldLabels ''ExternalDocs
97makeFieldLabels ''Encoding
97makeFieldLabels ''Encoding
98makeFieldLabels ''Example
98makeFieldLabels ''Example
99makeFieldLabels ''Discriminator
99makeFieldLabels ''Discriminator
100+makeFieldLabels ''Link
100
101
101-- Prisms
102-- Prisms
102
103