From abe9e254adf14b26bd6a45e5f3f440c61a9fdcb6 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Tue, 7 Nov 2023 11:51:12 +0000 Subject: [PATCH] Fix the `SecurityScheme` definition (#9) For `{"type": "http", "scheme": "basic"}` no `bearer_format`, is provided, so make that field optional. --- src/spec/security_scheme.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/spec/security_scheme.rs b/src/spec/security_scheme.rs index a2ce28e..f1de2a4 100644 --- a/src/spec/security_scheme.rs +++ b/src/spec/security_scheme.rs @@ -27,7 +27,7 @@ pub enum SecurityScheme { Http { scheme: String, #[serde(rename = "bearerFormat")] - bearer_format: String, + bearer_format: Option, }, #[serde(rename = "oauth2")] @@ -45,6 +45,20 @@ mod tests { use super::*; use url::Url; + #[test] + fn test_http_basic_deser() { + const HTTP_BASIC_SAMPLE: &str = r#"{"type": "http", "scheme": "basic"}"#; + let obj: SecurityScheme = serde_json::from_str(&HTTP_BASIC_SAMPLE).unwrap(); + + assert!(matches!( + obj, + SecurityScheme::Http { + scheme, + bearer_format: None, + } if scheme == "basic" + )); + } + #[test] fn test_security_scheme_oauth_deser() { const IMPLICIT_OAUTH2_SAMPLE: &str = r#"{