Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ jobs:
- name: Create tests
run: cargo run -p generate-tests --verbose
- name: Run tests
run: cargo test --verbose
run: cargo test --verbose
- name: Run tests with feature utoipa
run: cargo test --features utoipa --doc --verbose
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ readme = "README.md"
serde = {version = "1.0.130", features = ["derive"]}
serde_json = "1.0.67"
serde_yaml = "0.9.21"
indexmap = { version = "1.8.1", features = ["serde-1"] }
utoipa = { version = "3.3.0", optional = true, features=["debug"] }

[features]
utoipa = ["dep:utoipa"]

[workspace]
members = [
Expand Down
5 changes: 2 additions & 3 deletions generate-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ edition = "2018"
[dependencies]
serde = {version = "1.0.130", features = ["derive"]}
serde_json = "1.0.67"
serde_yaml = "0.8.20"
indexmap = { version = "1.8.1", features = ["serde-1"] }
serde_yaml = "0.9.21"
quote = "1.0.10"
convert_case = "0.4.0"
convert_case = "0.6.0"
regex = "1.5.4"
paste = "1.0.5"
12 changes: 6 additions & 6 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

use crate::{Channel, Components, ExternalDocumentation, Info, ReferenceOr, Server, Tag};
use crate::{Channel, Components, ExternalDocumentation, Info, RefOr, Server, Tag};

/// This is the root document object for the API specification.
/// It combines resource listing and API declaration together into one document.
Expand Down Expand Up @@ -97,8 +97,8 @@ pub struct AsyncAPI {
/// protocol: kafka
/// protocolVersion: '1.0.0'
/// ```
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub servers: IndexMap<String, ReferenceOr<Server>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub servers: BTreeMap<String, RefOr<Server>>,
/// Default content type to use when encoding/decoding a message's payload.
/// A string representing the default content type to use when encoding/decoding a
/// message's payload. The value MUST be a specific media type (e.g. `application/json`).
Expand Down Expand Up @@ -150,7 +150,7 @@ pub struct AsyncAPI {
/// subscribe:
/// $ref: "#/components/messages/userSignedUp"
/// ```
pub channels: IndexMap<String, Channel>,
pub channels: BTreeMap<String, Channel>,
/// An element to hold various schemas for the specification.
#[serde(skip_serializing_if = "Option::is_none")]
pub components: Option<Components>,
Expand All @@ -164,5 +164,5 @@ pub struct AsyncAPI {
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}
22 changes: 11 additions & 11 deletions src/channel.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

use crate::{
ChannelBinding, ExternalDocumentation, Message, OperationBinding, OperationTrait, Parameter,
ReferenceOr, Tag,
RefOr, Tag,
};

/// Describes the operations available on a single channel.
Expand Down Expand Up @@ -153,16 +153,16 @@ pub struct Channel {
/// subscribe:
/// $ref: "#/components/messages/userSignedUp"
/// ```
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub parameters: IndexMap<String, ReferenceOr<Parameter>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub parameters: BTreeMap<String, RefOr<Parameter>>,
/// A map where the keys describe the name of the protocol and the values
/// describe protocol-specific definitions for the channel.
#[serde(skip_serializing_if = "Option::is_none")]
pub bindings: Option<ReferenceOr<ChannelBinding>>,
pub bindings: Option<RefOr<ChannelBinding>>,
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}

/// Describes a publish or a subscribe operation. This provides a place to document how
Expand Down Expand Up @@ -274,13 +274,13 @@ pub struct Operation {
/// A map where the keys describe the name of the protocol and the
/// values describe protocol-specific definitions for the operation.
#[serde(skip_serializing_if = "Option::is_none")]
pub bindings: Option<ReferenceOr<OperationBinding>>,
pub bindings: Option<RefOr<OperationBinding>>,
/// A list of traits to apply to the operation object.
/// Traits MUST be merged into the operation object using the
/// [JSON Merge Patch](https://tools.ietf.org/html/rfc7386)
/// algorithm in the same order they are defined here.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub traits: Vec<ReferenceOr<OperationTrait>>,
pub traits: Vec<RefOr<OperationTrait>>,
/// A definition of the message that will be published or received on
/// this channel. `oneOf` is allowed here to specify multiple messages, however,
/// **a message MUST be valid only against one of the referenced message objects.**
Expand All @@ -289,12 +289,12 @@ pub struct Operation {
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum OperationMessageType {
Map(IndexMap<String, ReferenceOr<Message>>),
Single(ReferenceOr<Message>),
Map(BTreeMap<String, RefOr<Message>>),
Single(RefOr<Message>),
}
4 changes: 2 additions & 2 deletions src/channel_binding.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use indexmap::IndexMap;
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};

use crate::Schema;
Expand Down Expand Up @@ -60,7 +60,7 @@ pub struct ChannelBinding {
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}

/// This object MUST NOT contain any properties. Its name is reserved for future use.
Expand Down
58 changes: 29 additions & 29 deletions src/components.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

use crate::{
message_binding::MessageBinding, Channel, ChannelBinding, CorrelationId, Message, MessageTrait,
OperationBinding, OperationTrait, Parameter, ReferenceOr, Schema, SecurityScheme, Server,
OperationBinding, OperationTrait, Parameter, RefOr, Schema, SecurityScheme, Server,
ServerBinding,
};

Expand Down Expand Up @@ -186,56 +186,56 @@ use crate::{
pub struct Components {
/// An object to hold reusable
/// [Schema Objects][crate::Schema].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub schemas: IndexMap<String, ReferenceOr<Schema>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub schemas: BTreeMap<String, RefOr<Schema>>,
/// An object to hold reusable
/// [Message Objects][crate::Message].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub messages: IndexMap<String, ReferenceOr<Message>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub messages: BTreeMap<String, RefOr<Message>>,
/// An object to hold reusable
/// [Security Scheme Objects][crate::SecurityScheme].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub security_schemes: IndexMap<String, ReferenceOr<SecurityScheme>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub security_schemes: BTreeMap<String, RefOr<SecurityScheme>>,
/// An object to hold reusable
/// [Parameter Objects][crate::Parameter].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub parameters: IndexMap<String, ReferenceOr<Parameter>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub parameters: BTreeMap<String, RefOr<Parameter>>,
/// An object to hold reusable
/// [Correlation ID Objects][crate::CorrelationId].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub correlation_ids: IndexMap<String, ReferenceOr<CorrelationId>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub correlation_ids: BTreeMap<String, RefOr<CorrelationId>>,
/// An object to hold reusable
/// [Operation Trait Objects][crate::OperationTrait].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub operation_traits: IndexMap<String, ReferenceOr<OperationTrait>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub operation_traits: BTreeMap<String, RefOr<OperationTrait>>,
/// An object to hold reusable
/// [Message Trait Objects][crate::MessageTrait].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub message_traits: IndexMap<String, ReferenceOr<MessageTrait>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub message_traits: BTreeMap<String, RefOr<MessageTrait>>,
/// An object to hold reusable [Server Objects][crate::Server].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub servers: IndexMap<String, ReferenceOr<Server>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub servers: BTreeMap<String, RefOr<Server>>,
/// An object to hold reusable
/// [Server Bindings Objects][crate::ServerBinding].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub server_bindings: IndexMap<String, ReferenceOr<ServerBinding>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub server_bindings: BTreeMap<String, RefOr<ServerBinding>>,
/// An object to hold reusable [Channel Item Objects][crate::Channel].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub channels: IndexMap<String, Channel>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub channels: BTreeMap<String, Channel>,
/// An object to hold reusable
/// [Channel Bindings Objects][crate::ChannelBinding].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub channel_bindings: IndexMap<String, ReferenceOr<ChannelBinding>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub channel_bindings: BTreeMap<String, RefOr<ChannelBinding>>,
/// An object to hold reusable
/// [Operation Bindings Objects][crate::OperationBinding].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub operation_bindings: IndexMap<String, ReferenceOr<OperationBinding>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub operation_bindings: BTreeMap<String, RefOr<OperationBinding>>,
/// An object to hold reusable
/// [Message Bindings Objects][crate::MessageBinding].
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub message_bindings: IndexMap<String, ReferenceOr<MessageBinding>>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub message_bindings: BTreeMap<String, RefOr<MessageBinding>>,
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}
4 changes: 2 additions & 2 deletions src/correlation_id.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use indexmap::IndexMap;
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};

/// An object that specifies an identifier at design time that can used for
Expand All @@ -21,5 +21,5 @@ pub struct CorrelationId {
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}
8 changes: 4 additions & 4 deletions src/discriminator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use indexmap::IndexMap;
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};

/// When request bodies or response payloads may be one of a number of different schemas,
Expand All @@ -15,9 +15,9 @@ pub struct Discriminator {
/// will hold the discriminator value.
pub property_name: String,
/// An object to hold mappings between payload values and schema names or references.
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub mapping: IndexMap<String, String>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub mapping: BTreeMap<String, String>,
/// Inline extensions to this object.
#[serde(flatten)]
pub extensions: IndexMap<String, serde_json::Value>,
pub extensions: BTreeMap<String, serde_json::Value>,
}
4 changes: 2 additions & 2 deletions src/example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use indexmap::IndexMap;
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};

/// The asyncapi spec doesn't describe a structured example object.
Expand Down Expand Up @@ -27,5 +27,5 @@ pub struct Example {
pub headers: Option<serde_json::Value>,
/// Inline extensions to this object.
#[serde(flatten)]
pub extensions: IndexMap<String, serde_json::Value>,
pub extensions: BTreeMap<String, serde_json::Value>,
}
4 changes: 2 additions & 2 deletions src/external_documentation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use indexmap::IndexMap;
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};

/// Allows referencing an external resource for extended documentation.
Expand All @@ -14,5 +14,5 @@ pub struct ExternalDocumentation {
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}
8 changes: 4 additions & 4 deletions src/info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use indexmap::IndexMap;
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};

/// The object provides metadata about the API. The metadata can be used by the clients if needed.
Expand Down Expand Up @@ -60,7 +60,7 @@ pub struct Info {
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}

/// Contact information for the exposed API.
Expand Down Expand Up @@ -96,7 +96,7 @@ pub struct Contact {
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}

/// License information for the exposed API.
Expand Down Expand Up @@ -125,5 +125,5 @@ pub struct License {
/// 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>,
pub extensions: BTreeMap<String, serde_json::Value>,
}
Loading