openapiv3/link.rs
1use crate::*;
2use indexmap::IndexMap;
3use serde::{Deserialize, Serialize};
4
5/// The Link object represents a possible design-time link for a response.
6/// The presence of a link does not guarantee the caller's ability to
7/// successfully invoke it, rather it provides a known relationship and
8/// traversal mechanism between responses and other operations.
9///
10/// Unlike dynamic links (i.e. links provided in the response payload),
11/// the OAS linking mechanism does not require link information in the runtime response.
12///
13/// For computing links, and providing instructions to execute them,
14/// a runtime expression is used for accessing values in an operation
15/// and using them as parameters while invoking the linked operation.
16#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
17#[serde(rename_all = "camelCase")]
18pub struct Link {
19 /// A description of the link.
20 /// CommonMark syntax MAY be used for rich text representation.
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub description: Option<String>,
23 /// Either a operationRef or operationId
24 #[serde(flatten)]
25 pub operation: LinkOperation,
26 /// A literal value or {expression} to use as a request body
27 /// when calling the target operation.
28 #[serde(skip_serializing_if = "Option::is_none")]
29 pub request_body: Option<serde_json::Value>,
30 /// A map representing parameters to pass to an operation
31 /// as specified with operationId or identified via operationRef.
32 /// The key is the parameter name to be used, whereas the value
33 /// can be a constant or an expression to be evaluated and passed
34 /// to the linked operation. The parameter name can be qualified
35 /// using the parameter location [{in}.]{name} for operations
36 /// that use the same parameter name in different locations (e.g. path.id).
37 #[serde(default, skip_serializing_if = "IndexMap::is_empty")]
38 pub parameters: IndexMap<String, serde_json::Value>,
39 /// A server object to be used by the target operation.
40 #[serde(skip_serializing_if = "Option::is_none")]
41 pub server: Option<Server>,
42 /// Inline extensions to this object.
43 #[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
44 pub extensions: IndexMap<String, serde_json::Value>,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
48#[serde(rename_all = "camelCase")]
49pub enum LinkOperation {
50 /// A relative or absolute reference to an OAS operation.
51 /// This field is mutually exclusive of the operationId field,
52 /// and MUST point to an Operation Object. Relative operationRef
53 /// values MAY be used to locate an existing Operation Object
54 /// in the OpenAPI definition.
55 OperationRef(String),
56 /// The name of an existing, resolvable OAS operation,
57 /// as defined with a unique operationId. This field is
58 /// mutually exclusive of the operationRef field.
59 OperationId(String),
60}