forked from x52dev/oas3-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.rs
130 lines (118 loc) · 5.57 KB
/
link.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use super::{spec_extensions, Server};
/// The Link object represents a possible design-time link for a response.
///
/// The presence of a link does not guarantee the caller's ability to successfully invoke it, rather
/// it provides a known relationship and traversal mechanism between responses and other operations.
///
/// Unlike _dynamic_ links (i.e. links provided *in* the response payload), the OAS linking
/// mechanism does not require link information in the runtime response.
///
/// For computing links, and providing instructions to execute them, a [runtime expression] is used
/// for accessing values in an operation and using them as parameters while invoking the linked
/// operation.
///
/// The `operationRef` and `operationId` fields are mutually exclusive and so this structure is
/// modelled as an enum.
///
/// See <https://spec.openapis.org/oas/v3.1.0#link-object>.
///
/// [runtime expression]: https://spec.openapis.org/oas/v3.1.0#runtime-expressions
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(untagged)]
pub enum Link {
/// A relative or absolute reference to an OAS operation.
Ref {
/// A relative or absolute reference to an OAS operation.
///
/// This field is mutually exclusive of the `operationId` field, and MUST point to an
/// [Operation Object]. Relative `operationRef` values MAY be used to locate an existing
/// [Operation Object] in the OpenAPI definition.
///
/// [Operation Object]: https://spec.openapis.org/oas/v3.1.0#operation-object
#[serde(rename = "operationRef")]
operation_ref: String,
/// A map representing parameters to pass to an operation.
///
/// The key is the parameter name to be used, whereas the value can be a constant or an
/// expression to be evaluated and passed to the linked operation. The parameter name can be
/// qualified using the [parameter location] `[{in}.]{name}` for operations that use the
/// same parameter name in different locations (e.g. path.id).
///
/// [parameter location]: https://spec.openapis.org/oas/v3.1.0#parameterIn
//
// FIXME: Implement
// parameters: BTreeMap<String, Any | {expression}>,
//
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
parameters: BTreeMap<String, String>,
// FIXME: Implement
// /// A literal value or
// /// [{expression}](https://spec.openapis.org/oas/v3.1.0#runtimeExpression)
// /// to use as a request body when calling the target operation.
// #[serde(rename = "requestBody")]
// request_body: Any | {expression}
//
/// A description of the link.
///
/// [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text
/// representation.
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
/// A server object to be used by the target operation.
#[serde(skip_serializing_if = "Option::is_none")]
server: Option<Server>,
/// Specification extensions.
///
/// Only "x-" prefixed keys are collected, and the prefix is stripped.
///
/// See <https://spec.openapis.org/oas/v3.1.0#specification-extensions>.
#[serde(flatten, with = "spec_extensions")]
extensions: BTreeMap<String, serde_json::Value>,
},
/// The name of an _existing_, resolvable OAS operation, as defined with a unique `operationId`.
Id {
/// The name of an _existing_, resolvable OAS operation, as defined with a unique
/// `operationId`.
#[serde(rename = "operationId")]
operation_id: String,
/// A map representing parameters to pass to an operation.
///
/// The key is the parameter name to be used, whereas the value can be a constant or an
/// expression to be evaluated and passed to the linked operation. The parameter name can be
/// qualified using the [parameter location] `[{in}.]{name}` for operations that use the
/// same parameter name in different locations (e.g. path.id).
///
/// [parameter location]: https://spec.openapis.org/oas/v3.1.0#parameterIn
//
// FIXME: Implement
// parameters: BTreeMap<String, Any | {expression}>,
//
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
parameters: BTreeMap<String, String>,
// FIXME: Implement
// /// A literal value or
// /// [{expression}](https://spec.openapis.org/oas/v3.1.0#runtimeExpression)
// /// to use as a request body when calling the target operation.
// #[serde(rename = "requestBody")]
// request_body: Any | {expression}
//
/// A description of the link.
///
/// [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text
/// representation.
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
/// A server object to be used by the target operation.
#[serde(skip_serializing_if = "Option::is_none")]
server: Option<Server>,
/// Specification extensions.
///
/// Only "x-" prefixed keys are collected, and the prefix is stripped.
///
/// See <https://spec.openapis.org/oas/v3.1.0#specification-extensions>.
#[serde(flatten, with = "spec_extensions")]
extensions: BTreeMap<String, serde_json::Value>,
},
}