From b6298ec797f1e04df39ad14dbe7601d4cf88c46e Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Wed, 20 Jan 2021 23:25:17 +0000 Subject: [PATCH 01/11] Enable Travis on v5 maintenance branch Signed-off-by: Richard Whitehouse --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6def95f524..20cc21eee8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,7 @@ branches: - staging - trying - master + - v5 deploy: - provider: script script: bash deploy.sh From b256a11213493c0ea0e00c709814ef1c9887a6a0 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Fri, 27 Nov 2020 10:18:31 +0000 Subject: [PATCH 02/11] Support conversion for AnyOf and OneOf Signed-off-by: Richard Whitehouse --- CHANGELOG.md | 1 + Cargo.toml | 8 ++++++++ src/one_any_of.rs | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c2b25728e..d555f47a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added +- Support conversion for AnyOf and OneOf ### Changed diff --git a/Cargo.toml b/Cargo.toml index 68e5ae99d6..edfbf9f97c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ default = ["serdejson"] multipart_form = ["mime"] multipart_related = ["mime_multipart", "hyper_0_10", "mime_0_2"] serdejson = ["serde", "serde_json"] +conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-enum-derive"] [dependencies] base64 = "0.12" @@ -30,6 +31,13 @@ hyper-old-types = "0.11.0" chrono = "0.4.6" futures = "0.3" +# Conversion +frunk = { version = "0.3.0", optional = true } +frunk_derives = { version = "0.3.0", optional = true } +frunk_core = { version = "0.3.0", optional = true } +frunk-enum-derive = { version = "0.2.0", optional = true } +frunk-enum-core = { version = "0.2.0", optional = true } + # multipart/form-data mime = { version = "0.3", optional = true } diff --git a/src/one_any_of.rs b/src/one_any_of.rs index c1f41db8a4..a5b77ce04b 100644 --- a/src/one_any_of.rs +++ b/src/one_any_of.rs @@ -6,6 +6,8 @@ use serde::{ }; use std::str::FromStr; use std::string::ToString; +use frunk_enum_derive::LabelledGenericEnum; +use frunk::LabelledGeneric; // Define a macro to define the common parts between `OneOf` and `AnyOf` enums for a specific // number of inner types. @@ -15,7 +17,7 @@ macro_rules! common_one_any_of { $($i:ident),* ) => { /// $t - #[derive(Debug, PartialEq, Clone)] + #[derive(Debug, PartialEq, Clone, LabelledGenericEnum)] pub enum $t<$($i),*> where $($i: PartialEq,)* { From 21c5e4d71b83a432abe6760ad7c65a5f7f44301d Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Fri, 27 Nov 2020 13:54:31 +0000 Subject: [PATCH 03/11] Expose CompositeMakeServiceEntry Signed-off-by: Richard Whitehouse --- CHANGELOG.md | 1 + src/composites.rs | 6 ++++-- src/lib.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c2b25728e..f3ddae4fdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added +- Expose CompositeMakeServiceEntry ### Changed diff --git a/src/composites.rs b/src/composites.rs index eb5788b810..3ede1e9927 100644 --- a/src/composites.rs +++ b/src/composites.rs @@ -100,10 +100,12 @@ type CompositeServiceVec = Vec<( Box + Send>, )>; -type CompositeMakeServiceVec = Vec<( +type CompositeMakeServiceVec = Vec>; + +pub type CompositeMakeServiceEntry = ( &'static str, Box + Send>, -)>; +); /// Wraps a vector of pairs, each consisting of a base path as a `&'static str` /// and a `MakeService` instance. Implements `Deref` and `DerefMut` so diff --git a/src/lib.rs b/src/lib.rs index ca9422b9c4..89cc898d76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,7 @@ pub mod connector; pub use connector::Connector; pub mod composites; -pub use composites::{CompositeMakeService, CompositeService, NotFound}; +pub use composites::{CompositeMakeService, CompositeMakeServiceEntry, CompositeService, NotFound}; pub mod add_context; pub use add_context::{AddContextMakeService, AddContextService}; From 180d2bb93621246203bbffd0c43ee9492ea52f79 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 25 Feb 2021 19:37:44 +0000 Subject: [PATCH 04/11] Conditionally derive based on feature Signed-off-by: Richard Whitehouse --- src/one_any_of.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/one_any_of.rs b/src/one_any_of.rs index a5b77ce04b..87e4dfe736 100644 --- a/src/one_any_of.rs +++ b/src/one_any_of.rs @@ -6,7 +6,9 @@ use serde::{ }; use std::str::FromStr; use std::string::ToString; +#[cfg(feature="conversion")] use frunk_enum_derive::LabelledGenericEnum; +#[cfg(feature="conversion")] use frunk::LabelledGeneric; // Define a macro to define the common parts between `OneOf` and `AnyOf` enums for a specific @@ -17,7 +19,8 @@ macro_rules! common_one_any_of { $($i:ident),* ) => { /// $t - #[derive(Debug, PartialEq, Clone, LabelledGenericEnum)] + #[cfg_attr(feature = "conversion", derive(LabelledGenericEnum))] + #[derive(Debug, PartialEq, Clone)] pub enum $t<$($i),*> where $($i: PartialEq,)* { From 8d28ffecbf4c21f5199935c9ef61ecca349ad765 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 25 Feb 2021 20:12:41 +0000 Subject: [PATCH 05/11] Add docs for CompositeMakeServiceEntry Signed-off-by: Richard Whitehouse --- src/composites.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/composites.rs b/src/composites.rs index 3ede1e9927..a07f90f82c 100644 --- a/src/composites.rs +++ b/src/composites.rs @@ -102,6 +102,10 @@ type CompositeServiceVec = Vec<( type CompositeMakeServiceVec = Vec>; +/// Service which can be composited with other services as part of a CompositeMakeService +/// +/// Consists of a base path for requests which should be handled by this service, and a boxed +/// MakeService. pub type CompositeMakeServiceEntry = ( &'static str, Box + Send>, From 57cceef735aa372751cdf927ac41256ba54c8bbe Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 25 Feb 2021 20:53:46 +0000 Subject: [PATCH 06/11] Fix clippy error Signed-off-by: Richard Whitehouse --- src/body.rs | 1 + src/composites.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/body.rs b/src/body.rs index 3209e2abbf..2b65fcde0c 100644 --- a/src/body.rs +++ b/src/body.rs @@ -11,6 +11,7 @@ pub trait BodyExt { type Error; /// Collect the body into a raw form + #[allow(clippy::wrong_self_convention)] fn to_raw(self) -> futures::future::BoxFuture<'static, Result>; } diff --git a/src/composites.rs b/src/composites.rs index a07f90f82c..4796745cbc 100644 --- a/src/composites.rs +++ b/src/composites.rs @@ -100,7 +100,8 @@ type CompositeServiceVec = Vec<( Box + Send>, )>; -type CompositeMakeServiceVec = Vec>; +type CompositeMakeServiceVec = + Vec>; /// Service which can be composited with other services as part of a CompositeMakeService /// From 6ca22f1b362a815c846cfcff0ae0eac669f432a0 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Wed, 3 Mar 2021 19:51:16 +0000 Subject: [PATCH 07/11] Use frunk-enum 0.2.1 Signed-off-by: Richard Whitehouse --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index edfbf9f97c..dc5849c67c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,8 +35,8 @@ futures = "0.3" frunk = { version = "0.3.0", optional = true } frunk_derives = { version = "0.3.0", optional = true } frunk_core = { version = "0.3.0", optional = true } -frunk-enum-derive = { version = "0.2.0", optional = true } -frunk-enum-core = { version = "0.2.0", optional = true } +frunk-enum-derive = { version = "0.2.1", optional = true } +frunk-enum-core = { version = "0.2.1", optional = true } # multipart/form-data mime = { version = "0.3", optional = true } From 18050ebdf518390444dfd789999c40f70868a789 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 4 Mar 2021 10:29:29 +0000 Subject: [PATCH 08/11] Fixup clippy and rustfmt warnings Signed-off-by: Richard Whitehouse --- src/one_any_of.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/one_any_of.rs b/src/one_any_of.rs index 87e4dfe736..71b3e52e4e 100644 --- a/src/one_any_of.rs +++ b/src/one_any_of.rs @@ -1,4 +1,6 @@ //! Implementations of OpenAPI `oneOf` and `anyOf` types, assuming rules are just types +#[cfg(feature = "conversion")] +use frunk_enum_derive::LabelledGenericEnum; use serde::{ de::Error, Deserialize, Deserializer, Serialize, Serializer, @@ -6,10 +8,6 @@ use serde::{ }; use std::str::FromStr; use std::string::ToString; -#[cfg(feature="conversion")] -use frunk_enum_derive::LabelledGenericEnum; -#[cfg(feature="conversion")] -use frunk::LabelledGeneric; // Define a macro to define the common parts between `OneOf` and `AnyOf` enums for a specific // number of inner types. From 31a4ad50042a54ed0b57cef52a3c8208c51ea0c2 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 4 Mar 2021 21:07:14 +0000 Subject: [PATCH 09/11] Release 5.1.0 Signed-off-by: Richard Whitehouse --- CHANGELOG.md | 10 +++++++--- Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 103d16935a..f41df88629 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added -- Support conversion for AnyOf and OneOf -- Expose CompositeMakeServiceEntry ### Changed ### Removed +## [5.1.0] - 2021-03-04 +### Added +- Support conversion for AnyOf and OneOf +- Expose CompositeMakeServiceEntry + ## [5.0.2] - 2021-01-13 ### Fixed - Fix off by one error declaring OneOf and AnyOf with more than 10 arguments @@ -161,7 +164,8 @@ No changes. We now think we've got enough to declare this crate stable. ## [0.5.0] - 2017-09-18 - Start of changelog. -[Unreleased]: https://github.com/Metaswitch/swagger-rs/compare/5.0.2...HEAD +[Unreleased]: https://github.com/Metaswitch/swagger-rs/compare/5.1.0...HEAD +[5.1.0]: https://github.com/Metaswitch/swagger-rs/compare/5.0.2...5.1.0 [5.0.2]: https://github.com/Metaswitch/swagger-rs/compare/5.0.1...5.0.2 [5.0.1]: https://github.com/Metaswitch/swagger-rs/compare/5.0.0...5.0.1 [5.0.0]: https://github.com/Metaswitch/swagger-rs/compare/4.0.2...5.0.0 diff --git a/Cargo.toml b/Cargo.toml index dc5849c67c..ce93660034 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swagger" -version = "5.0.2" +version = "5.1.0" authors = ["Metaswitch Networks Ltd"] license = "Apache-2.0" description = "A set of common utilities for Rust code generated by swagger-codegen" From c13ce3530a60a0f506ee72475849e9527969021e Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Wed, 17 Mar 2021 23:37:19 +0000 Subject: [PATCH 10/11] Fix Clippy allow Signed-off-by: Richard Whitehouse --- src/request_parser.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/request_parser.rs b/src/request_parser.rs index 98d3615890..43608819d9 100644 --- a/src/request_parser.rs +++ b/src/request_parser.rs @@ -16,7 +16,7 @@ macro_rules! request_parser_joiner { impl RequestParser for $name where $($T: RequestParser, )* { - fn parse_operation_id(request: &Request) -> Result<&'static str, ()> { + fn parse_operation_id(request: &Request) -> Option<&'static str> { __impl_request_parser_joiner!(request, $($T), *) } } @@ -30,8 +30,8 @@ macro_rules! __impl_request_parser_joiner { ($argname:expr, $head:ty) => {<$head as RequestParser>::parse_operation_id(&$argname)}; ($argname:expr, $head:ty, $( $tail:ty), *) => { match <$head as RequestParser>::parse_operation_id(&$argname) { - Ok(s) => Ok(s), - Err(_) => __impl_request_parser_joiner!($argname, $( $tail), *), + Some(s) => Some(s), + None => __impl_request_parser_joiner!($argname, $( $tail), *), } }; } @@ -46,10 +46,8 @@ macro_rules! __impl_request_parser_joiner { pub trait RequestParser { /// Retrieve the Swagger operation identifier that matches this request. /// - /// Returns `Err(())` if this request does not match any known operation on this API. - // Allow this lint, as changing the signature is a breaking change. - #[allow(clippy::result_unit_err)] - fn parse_operation_id(req: &Request) -> Result<&'static str, ()>; + /// Returns `None` if this request does not match any known operation on this API. + fn parse_operation_id(req: &Request) -> Result<&'static str, Box>; } #[cfg(test)] @@ -61,11 +59,11 @@ mod context_tests { struct TestParser1; impl RequestParser for TestParser1 { - fn parse_operation_id(request: &Request) -> Result<&'static str, ()> { + fn parse_operation_id(request: &Request) -> Option<&'static str> { match request.uri().path() { - "/test/t11" => Ok("t11"), - "/test/t12" => Ok("t12"), - _ => Err(()), + "/test/t11" => Some("t11"), + "/test/t12" => Some("t12"), + _ => None, } } } @@ -73,11 +71,11 @@ mod context_tests { struct TestParser2; impl RequestParser for TestParser2 { - fn parse_operation_id(request: &Request) -> Result<&'static str, ()> { + fn parse_operation_id(request: &Request) -> Option<&'static str> { match request.uri().path() { - "/test/t21" => Ok("t21"), - "/test/t22" => Ok("t22"), - _ => Err(()), + "/test/t21" => Some("t21"), + "/test/t22" => Some("t22"), + _ => None, } } } @@ -95,8 +93,8 @@ mod context_tests { request_parser_joiner!(JoinedReqParser, TestParser1, TestParser2); - assert_eq!(JoinedReqParser::parse_operation_id(&req1), Ok("t11")); - assert_eq!(JoinedReqParser::parse_operation_id(&req2), Ok("t22")); - assert_eq!(JoinedReqParser::parse_operation_id(&req3), Err(())); + assert_eq!(JoinedReqParser::parse_operation_id(&req1), Some("t11")); + assert_eq!(JoinedReqParser::parse_operation_id(&req2), Some("t22")); + assert_eq!(JoinedReqParser::parse_operation_id(&req3), None); } } From f498e06def7c8f8d23719e2e3c12b1db2003b825 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 18 Mar 2021 16:43:33 +0000 Subject: [PATCH 11/11] Fix RequestParser definition Signed-off-by: Richard Whitehouse --- src/request_parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/request_parser.rs b/src/request_parser.rs index 43608819d9..36eaf460a7 100644 --- a/src/request_parser.rs +++ b/src/request_parser.rs @@ -47,7 +47,7 @@ pub trait RequestParser { /// Retrieve the Swagger operation identifier that matches this request. /// /// Returns `None` if this request does not match any known operation on this API. - fn parse_operation_id(req: &Request) -> Result<&'static str, Box>; + fn parse_operation_id(req: &Request) -> Option<&'static str>; } #[cfg(test)]