aide/openapi/
link.rs

1use crate::openapi::*;
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
12/// response.
13///
14/// For computing links, and providing instructions to execute them,
15/// a runtime expression is used for accessing values in an operation
16/// and using them as parameters while invoking the linked operation.
17#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
18#[serde(rename_all = "camelCase")]
19#[derive(schemars::JsonSchema)]
20pub struct Link {
21    /// A description of the link.
22    /// CommonMark syntax MAY be used for rich text representation.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub description: Option<String>,
25    /// Either a operationRef or operationId
26    #[serde(flatten)]
27    pub operation: LinkOperation,
28    /// A literal value or {expression} to use as a request body
29    /// when calling the target operation.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub request_body: Option<serde_json::Value>,
32    /// A map representing parameters to pass to an operation
33    /// as specified with operationId or identified via operationRef.
34    /// The key is the parameter name to be used, whereas the value
35    /// can be a constant or an expression to be evaluated and passed
36    /// to the linked operation. The parameter name can be qualified
37    /// using the parameter location [{in}.]{name} for operations
38    /// that use the same parameter name in different locations (e.g. path.id).
39    #[serde(default, skip_serializing_if = "IndexMap::is_empty")]
40    pub parameters: IndexMap<String, serde_json::Value>,
41    /// A server object to be used by the target operation.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub server: Option<Server>,
44    /// Inline extensions to this object.
45    #[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
46    pub extensions: IndexMap<String, serde_json::Value>,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
50#[serde(rename_all = "camelCase")]
51#[derive(schemars::JsonSchema)]
52pub enum LinkOperation {
53    /// A relative or absolute reference to an OAS operation.
54    /// This field is mutually exclusive of the operationId field,
55    /// and MUST point to an Operation Object. Relative operationRef
56    /// values MAY be used to locate an existing Operation Object
57    /// in the OpenAPI definition. See the rules for resolving Relative
58    /// References.
59    OperationRef(String),
60    /// The name of an existing, resolvable OAS operation,
61    /// as defined with a unique operationId. This field is
62    /// mutually exclusive of the operationRef field.
63    OperationId(String),
64}