asyncapi 0.2.0

This crate aims to provide data structures that represent the AsyncAPI specification easily deserializable with serde.
Documentation
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};

use crate::Schema;

/// Map describing protocol-specific definitions for a message.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct ChannelBinding {
    /// Protocol-specific information for an HTTP channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub http: Option<HTTPChannelBinding>,
    /// Protocol-specific information for a WebSockets channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ws: Option<WebsocketsChannelBinding>,
    /// Protocol-specific information for a Kafka channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub kafka: Option<KafkaChannelBinding>,
    /// Protocol-specific information for an Anypoint MQ channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub anypointmq: Option<AnyPointMQChannelBinding>,
    /// Protocol-specific information for an AMQP 0-9-1 channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amqp: Option<AMQPChannelBinding>,
    /// Protocol-specific information for an AMQP 1.0 channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amqp1: Option<AMQPChannelBinding>,
    /// Protocol-specific information for an MQTT channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mqtt: Option<MQTTChannelBinding>,
    /// Protocol-specific information for an MQTT 5 channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mqtt5: Option<MQTT5ChannelBinding>,
    /// Protocol-specific information for a NATS channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nats: Option<NATSChannelBinding>,
    /// Protocol-specific information for a JMS channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub jms: Option<JMSChannelBinding>,
    /// Protocol-specific information for an SNS channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sns: Option<SNSChannelBinding>,
    /// Protocol-specific information for a Solace channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub solace: Option<SolaceChannelBinding>,
    /// Protocol-specific information for an SQS channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sqs: Option<SQSChannelBinding>,
    /// Protocol-specific information for a STOMP channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stomp: Option<STOMPChannelBinding>,
    /// Protocol-specific information for a Redis channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub redis: Option<RedisChannelBinding>,
    /// Protocol-specific information for a Mercure channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mercure: Option<MercureChannelBinding>,
    /// Protocol-specific information for an IBM MQ channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ibmmq: Option<IBMMQChannelBinding>,
    /// This object can be extended with
    /// [Specification Extensions](https://www.asyncapi.com/docs/specifications/v2.3.0#specificationExtensions).
    #[serde(flatten)]
    pub extensions: IndexMap<String, serde_json::Value>,
}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct HTTPChannelBinding {}

/// When using WebSockets, the channel represents the connection. Unlike other protocols
/// that support multiple virtual channels (topics, routing keys, etc.) per connection,
/// WebSockets doesn't support virtual channels or, put it another way, there's only one
/// channel and its characteristics are strongly related to the protocol used for the
/// handshake, i.e., HTTP.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct WebsocketsChannelBinding {
    /// The HTTP method to use when establishing the connection.
    /// Its value MUST be either `GET` or `POST`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub method: Option<String>,
    /// A Schema object containing the definitions for each query parameter.
    /// This schema MUST be of type `object` and have a `properties` key.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub query: Option<Schema>,
    /// A Schema object containing the definitions of the HTTP headers to use when
    /// establishing the connection. This schema MUST be of type `object` and have
    /// a `properties` key.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub headers: Option<Schema>,
    /// The version of this binding. If omitted, "latest" MUST be assumed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub binding_version: Option<String>,
}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct KafkaChannelBinding {}

/// The Anypoint MQ [Channel Binding Object][ChannelBinding] is defined by a
/// [JSON Schema](https://github.com/asyncapi/bindings/blob/master/anypointmq/json_schemas/channel.json),
/// which defines these fields.
///
/// Note that an Anypoint MQ exchange can only be sent to, not received from.
/// To receive messages sent to an exchange,
/// [an intermediary queue must be defined and bound to the exchange](https://docs.mulesoft.com/mq/mq-understanding#message-exchanges).
/// In this bindings specification, these intermediary queues are not exposed
/// in the AsyncAPI document. Instead, it is simply assumed that whenever
/// messages must be received from an exchange, such an intermediary queue is
/// involved yet invisible in the AsyncAPI document.
///
/// # Examples
///
/// The following example shows a `channels` object with two channels,
/// the second having a channel binding object for `anypointmq`:
///
/// ```yaml
/// channels:
///   user/signup:
///     description: |
///       This application receives command messages from this channel about users to sign up.
///       Minimal configuration, omitting a channel binding object.
///     publish:
///       #...
///   user/signedup:
///     description: |
///       This application sends events to this channel about users that have signed up.
///       Explicitly provides a channel binding object.
///     bindings:
///       anypointmq:
///         destination:     user-signup-exchg
///         destinationType: exchange
///         bindingVersion:  '0.0.1'
///     subscribe:
///       #...
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AnyPointMQChannelBinding {
    /// **Optional**, defaults to the channel name. The destination (queue or exchange)
    /// name for this channel. SHOULD only be specified if the channel name differs
    /// from the actual destination name, such as when the channel name is not a valid
    /// destination name in Anypoint MQ.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub destination: Option<String>,
    /// **Optional**, defaults to `queue`. The type of destination, which MUST be
    /// either `exchange` or `queue` or `fifo-queue`. SHOULD be specified to document
    /// the messaging model (publish/subscribe, point-to-point, strict message
    /// ordering) supported by this channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub destination_type: Option<String>,
    /// **Optional**, defaults to `latest`. The version of this binding.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub binding_version: Option<String>,
}

/// This object contains information about the channel representation in AMQP.
///
/// # Examples
///
/// ```yaml
/// channels:
///   user/signedup:
///     bindings:
///       amqp:
///         is: routingKey
///         queue:
///           name: my-queue-name
///           durable: true
///           exclusive: true
///           autoDelete: false
///           vhost: /
///         exchange:
///           name: myExchange
///           type: topic
///           durable: true
///           autoDelete: false
///           vhost: /
///         bindingVersion: 0.2.0
///
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AMQPChannelBinding {
    /// Defines what type of channel is it. Can be either `queue` or `routingKey` (default).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is: Option<String>,
    /// When `is`=`routingKey`, this object defines the exchange properties.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub exchange: Option<AMQPChannelBindingExchange>,
    /// When `is`=`queue`, this object defines the queue properties.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub queue: Option<AMQPChannelBindingQueue>,
    /// The version of this binding. If omitted, "latest" MUST be assumed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub binding_version: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AMQPChannelBindingExchange {
    /// The name of the exchange. It MUST NOT exceed 255 characters long.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// The type of the exchange. Can be either
    /// `topic`, `direct`, `fanout`, `default` or `headers`.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub typ: Option<String>,
    /// Whether the exchange should survive broker restarts or not.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub durable: Option<bool>,
    /// Whether the exchange should be deleted when the last queue is unbound from it.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub auto_delete: Option<bool>,
    /// The virtual host of the exchange. Defaults to `/`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vhost: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AMQPChannelBindingQueue {
    /// The name of the queue. It MUST NOT exceed 255 characters long.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Whether the queue should survive broker restarts or not.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub durable: Option<bool>,
    /// Whether the queue should be used only by one connection or not.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub exclusive: Option<bool>,
    ///  Whether the queue should be deleted when the last consumer unsubscribes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub auto_delete: Option<bool>,
    /// The virtual host of the queue. Defaults to `/`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vhost: Option<String>,
}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AMQP1ChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MQTTChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MQTT5ChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct NATSChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct JMSChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct SNSChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct SolaceChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct SQSChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct STOMPChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RedisChannelBinding {}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MercureChannelBinding {}

/// This object contains information about the channel representation in IBM MQ. Each channel corresponds to a Queue or Topic within IBM MQ.
///
/// # Examples
///
/// Example for an IBM MQ Topic where topic string is defined by AsyncAPI channel
/// ```yaml
/// channels:
///   user/signedup:
/// ```
///
/// Example for AsyncAPI channel mapping to an IBM MQ topic with a specified MQ Topic object
/// ```yaml
/// channels:
///   user/signedup:
///     bindings:
///       ibmmq:
///         destinationType: topic
///         topic:
///           objectName: myTopicName
///         bindingVersion: 0.1.0
/// ```
///
/// Example for AsyncAPI channel mapping to an IBM MQ Queue
/// ```yaml
/// channels:
///   user/signedup:
///     bindings:
///       ibmmq:
///         destinationType: queue
///         queue:
///           objectName: myQueueName
///           exclusive: true
///         bindingVersion: 0.1.0
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct IBMMQChannelBinding {
    /// Defines the type of AsyncAPI channel.
    ///
    /// MUST be either `topic` or `queue`. For type `topic`,
    /// the AsyncAPI channel name MUST be assumed for the
    /// IBM MQ topic string unless overridden.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub destination_type: Option<String>,
    /// Defines the properties of a queue.
    ///
    /// `queue` and `topic` fields MUST NOT coexist within a channel binding
    #[serde(skip_serializing_if = "Option::is_none")]
    pub queue: Option<IBMMQChannelBindingQueue>,
    /// Defines the properties of a topic.
    ///
    /// `queue` and `topic` fields MUST NOT coexist within a channel binding.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub topic: Option<IBMMQChannelBindingTopic>,
    /// The maximum length of the physical message (in bytes) accepted
    /// by the Topic or Queue. Messages produced that are greater in size
    /// than this value may fail to be delivered. More information on the
    /// maximum message length can be found on this
    /// [page](https://www.ibm.com/support/knowledgecenter/SSFKSJ_latest/com.ibm.mq.ref.adm.doc/q085520_.html#q085520___maxmsgl)
    /// in the IBM MQ Knowledge Center.
    ///
    /// MUST be `0-104,857,600` bytes (100 MB).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_msg_length: Option<i32>,
    /// The version of this binding.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub binding_version: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct IBMMQChannelBindingQueue {
    /// Defines the name of the IBM MQ queue associated with the channel.
    ///
    /// A value MUST be specified. MUST NOT exceed 48 characters in length.
    /// MUST be a valid IBM MQ queue name
    pub object_name: String,
    /// Defines if the queue is a cluster queue and therefore partitioned.
    /// If true, a binding option MAY be specified when accessing the queue.
    /// More information on binding options can be found on this
    /// [page](https://www.ibm.com/support/knowledgecenter/SSFKSJ_latest/com.ibm.mq.ref.dev.doc/q101870_.html#q101870___BIND_ON_OPEN)
    /// in the IBM MQ Knowledge Center.
    ///
    /// If `false`, binding options SHOULD NOT be specified when accessing the queue.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_partitioned: Option<bool>,
    /// Specifies if it is recommended to open the queue exclusively.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub exclusive: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct IBMMQChannelBindingTopic {
    /// The value of the IBM MQ topic string to be used.
    ///
    /// Note: if specified, SHALL override AsyncAPI channel name.
    ///
    /// MUST NOT exceed 10240 characters in length.
    /// MAY coexist with `topic.objectName`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub string: Option<String>,
    /// The name of the IBM MQ topic object.
    ///
    /// Note: if specified, SHALL override AsyncAPI channel name.
    ///
    /// MUST NOT exceed 48 characters in length.
    /// MAY coexist with `topic.string`
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object_name: Option<String>,
    /// Defines if the subscription may be durable.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub durable_permitted: Option<bool>,
    /// Defines if the last message published will be made
    /// available to new subscriptions.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_msg_retained: Option<bool>,
}