From f4ee8cb47e7f5c9cdf7ce4913ff331441cfd1f57 Mon Sep 17 00:00:00 2001 From: Yannick Poirier Date: Wed, 30 Oct 2024 16:22:50 +0100 Subject: [PATCH] Optional feature to generate openAPI schema --- Cargo.toml | 2 ++ src/common/fdtinstance.rs | 1 + src/common/lct.rs | 1 + src/common/oti.rs | 6 ++++++ src/common/udpendpoint.rs | 1 + 5 files changed, 11 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 2ba894b..0a2050b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ raptor-code = "1.0.6" opentelemetry = { version = "0.25", optional = true } opentelemetry-semantic-conventions = { version = "0.25" , optional = true } rand = "0.8" +utoipa = { version = "5", optional = true } [dev-dependencies] env_logger = "0.11" @@ -44,3 +45,4 @@ tempfile = "3.10.1" [features] python = ["pyo3", "pyo3-log"] optel = ["opentelemetry", "opentelemetry-semantic-conventions"] +openapi = ["utoipa"] diff --git a/src/common/fdtinstance.rs b/src/common/fdtinstance.rs index e2d4f7b..a9ba286 100644 --- a/src/common/fdtinstance.rs +++ b/src/common/fdtinstance.rs @@ -120,6 +120,7 @@ where } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] pub struct FdtInstance { #[serde(rename = "@xmlns", serialize_with = "xmlns")] pub xmlns: Option, diff --git a/src/common/lct.rs b/src/common/lct.rs index 35ee5e6..2b5d1b7 100644 --- a/src/common/lct.rs +++ b/src/common/lct.rs @@ -5,6 +5,7 @@ use crate::tools::error::{FluteError, Result}; /// Content Encoding, compressed #[repr(u8)] #[derive(Clone, Copy, PartialEq, Debug, Serialize)] +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] pub enum Cenc { /// Do not encode content before transmission Null = 0, diff --git a/src/common/oti.rs b/src/common/oti.rs index 8ad35a9..e6f647f 100644 --- a/src/common/oti.rs +++ b/src/common/oti.rs @@ -9,6 +9,7 @@ use serde::Serialize; /// #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Serialize)] +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] pub enum FECEncodingID { /// No FEC NoCode = 0, @@ -45,6 +46,7 @@ impl TryFrom for FECEncodingID { /// /// Reed Solomon GS2M Scheme Specific parameters #[derive(Clone, Debug, Serialize)] +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] pub struct ReedSolomonGF2MSchemeSpecific { /// Length of the finite field elements, in bits pub m: u8, @@ -57,6 +59,7 @@ pub struct ReedSolomonGF2MSchemeSpecific { /// RaptorQ Scheme Specific parameters /// #[derive(Clone, Debug, Default, Serialize)] +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] pub struct RaptorQSchemeSpecific { /// The number of source blocks (Z): 8-bit unsigned integer. pub source_blocks_length: u8, @@ -75,6 +78,7 @@ pub struct RaptorQSchemeSpecific { ///| Z | N | Al | ///+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #[derive(Clone, Debug, Serialize)] +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] pub struct RaptorSchemeSpecific { /// The number of source blocks (Z): 16-bit unsigned integer. pub source_blocks_length: u16, @@ -162,6 +166,7 @@ impl RaptorSchemeSpecific { /// Scheme Specific information /// #[derive(Clone, Debug, Serialize)] +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] pub enum SchemeSpecific { /// if `fec_encoding_id` is `FECEncodingID::ReedSolomonGF2M` ReedSolomon(ReedSolomonGF2MSchemeSpecific), @@ -175,6 +180,7 @@ pub enum SchemeSpecific { /// FEC Object Transmission Information /// Contains the parameters using the build the blocks and FEC for the objects transmission #[derive(Clone, Debug, Serialize)] +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] pub struct Oti { /// Select the FEC for the object transmission pub fec_encoding_id: FECEncodingID, diff --git a/src/common/udpendpoint.rs b/src/common/udpendpoint.rs index c483883..682f435 100644 --- a/src/common/udpendpoint.rs +++ b/src/common/udpendpoint.rs @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize}; /// UDP Endpoint #[derive(Debug, PartialEq, Deserialize, Serialize, Clone, Eq, Hash)] +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] pub struct UDPEndpoint { /// Network source adress pub source_address: Option,