From d40ab9f1c41cdb931601c8635e87fff49d3dc4a2 Mon Sep 17 00:00:00 2001 From: Iovoslav Iovchev Date: Sat, 7 May 2022 18:23:59 +0300 Subject: [PATCH 1/5] using a http method enum instead of separate fields --- src/v3_0/schema.rs | 50 ++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/v3_0/schema.rs b/src/v3_0/schema.rs index ab8ba7d..5cb7bf4 100644 --- a/src/v3_0/schema.rs +++ b/src/v3_0/schema.rs @@ -180,6 +180,29 @@ pub struct ServerVariable { pub description: Option, } +/// Describes all of the possible HTTP method verbs for operations on a single path. +/// +/// See +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Ord, PartialOrd, Eq)] +pub enum Method { + #[serde(rename = "get")] + Get, + #[serde(rename = "put")] + Put, + #[serde(rename = "post")] + Post, + #[serde(rename = "delete")] + Delete, + #[serde(rename = "options")] + Options, + #[serde(rename = "head")] + Head, + #[serde(rename = "patch")] + Patch, + #[serde(rename = "trace")] + Trace, +} + /// Describes the operations available on a single path. /// /// A Path Item MAY be empty, due to [ACL @@ -205,30 +228,9 @@ pub struct PathItem { #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, - /// A definition of a GET operation on this path. - #[serde(skip_serializing_if = "Option::is_none")] - pub get: Option, - /// A definition of a PUT operation on this path. - #[serde(skip_serializing_if = "Option::is_none")] - pub put: Option, - /// A definition of a POST operation on this path. - #[serde(skip_serializing_if = "Option::is_none")] - pub post: Option, - /// A definition of a DELETE operation on this path. - #[serde(skip_serializing_if = "Option::is_none")] - pub delete: Option, - /// A definition of a OPTIONS operation on this path. - #[serde(skip_serializing_if = "Option::is_none")] - pub options: Option, - /// A definition of a HEAD operation on this path. - #[serde(skip_serializing_if = "Option::is_none")] - pub head: Option, - /// A definition of a PATCH operation on this path. - #[serde(skip_serializing_if = "Option::is_none")] - pub patch: Option, - /// A definition of a TRACE operation on this path. - #[serde(skip_serializing_if = "Option::is_none")] - pub trace: Option, + /// The definitions of a all operation on this path. + #[serde(flatten)] + pub operations: BTreeMap, /// An alternative `server` array to service all operations in this path. #[serde(skip_serializing_if = "Option::is_none")] From 5047260ed7afe0b48a804d6ddafa3e1935605ca4 Mon Sep 17 00:00:00 2001 From: Iovoslav Iovchev Date: Sat, 28 May 2022 21:38:16 +0300 Subject: [PATCH 2/5] security requirements --- src/v3_0/schema.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/v3_0/schema.rs b/src/v3_0/schema.rs index 5cb7bf4..f161384 100644 --- a/src/v3_0/schema.rs +++ b/src/v3_0/schema.rs @@ -59,13 +59,12 @@ pub struct Spec { #[serde(skip_serializing_if = "Option::is_none")] pub components: Option, - // FIXME: Implement - // /// A declaration of which security mechanisms can be used across the API. - // /// The list of values includes alternative security requirement objects that can be used. - // /// Only one of the security requirement objects need to be satisfied to authorize a request. - // /// Individual operations can override this definition. - // #[serde(skip_serializing_if = "Option::is_none")] - // pub security: Option, + /// A declaration of which security mechanisms can be used across the API. + /// The list of values includes alternative security requirement objects that can be used. + /// Only one of the security requirement objects need to be satisfied to authorize a request. + /// Individual operations can override this definition. + #[serde(skip_serializing_if = "Option::is_none")] + pub security: Option, /// A list of tags used by the specification with additional metadata. ///The order of the tags can be used to reflect on their order by the parsing tools. /// Not all tags that are used by the @@ -330,14 +329,13 @@ pub struct Operation { #[serde(skip_serializing_if = "Option::is_none")] pub deprecated: Option, - // FIXME: Implement - // /// A declaration of which security mechanisms can be used for this operation. The list of - // /// values includes alternative security requirement objects that can be used. Only one - // /// of the security requirement objects need to be satisfied to authorize a request. - // /// This definition overrides any declared top-level - // /// [`security`](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#oasSecurity). - // /// To remove a top-level security declaration, an empty array can be used. - // pub security: Option, + /// A declaration of which security mechanisms can be used for this operation. The list of + /// values includes alternative security requirement objects that can be used. Only one + /// of the security requirement objects need to be satisfied to authorize a request. + /// This definition overrides any declared top-level + /// [`security`](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#oasSecurity). + /// To remove a top-level security declaration, an empty array can be used. + pub security: Option, /// An alternative `server` array to service this operation. If an alternative `server` /// object is specified at the Path Item Object or Root level, it will be overridden by /// this value. @@ -347,6 +345,11 @@ pub struct Operation { pub extensions: Extensions, } +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] +pub struct SecurityRequirement { + scopes: BTreeMap>, +} + // FIXME: Verify against OpenAPI 3.0 /// Describes a single operation parameter. /// A unique parameter is defined by a combination of a From 381a1747966f730ae304bbedb3efda5ac2df9bca Mon Sep 17 00:00:00 2001 From: Iovoslav Iovchev Date: Sat, 28 May 2022 22:08:16 +0300 Subject: [PATCH 3/5] visibility --- src/v3_0/schema.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v3_0/schema.rs b/src/v3_0/schema.rs index f161384..9787ac9 100644 --- a/src/v3_0/schema.rs +++ b/src/v3_0/schema.rs @@ -347,7 +347,7 @@ pub struct Operation { #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] pub struct SecurityRequirement { - scopes: BTreeMap>, + pub scopes: BTreeMap>, } // FIXME: Verify against OpenAPI 3.0 From f29693d463b22b70cec8b3ae523570f873ba3bbd Mon Sep 17 00:00:00 2001 From: Iovoslav Iovchev Date: Sun, 29 May 2022 13:08:04 +0300 Subject: [PATCH 4/5] method as_str fn --- src/v3_0/schema.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/v3_0/schema.rs b/src/v3_0/schema.rs index 9787ac9..f66886c 100644 --- a/src/v3_0/schema.rs +++ b/src/v3_0/schema.rs @@ -202,6 +202,22 @@ pub enum Method { Trace, } +impl Method { + pub fn as_str(&self) -> &str { + use Method::*; + match self { + Get => "get", + Put => "put", + Post => "post", + Delete => "delete", + Options => "options", + Head => "head", + Patch => "patch", + Trace => "trace", + } + } +} + /// Describes the operations available on a single path. /// /// A Path Item MAY be empty, due to [ACL From 92fbdc9f7a5d27e8b7f351bfd7d0aa3bbba7c242 Mon Sep 17 00:00:00 2001 From: Iovoslav Iovchev Date: Tue, 31 May 2022 12:23:37 +0300 Subject: [PATCH 5/5] $ref for Response --- src/v3_0/schema.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/v3_0/schema.rs b/src/v3_0/schema.rs index f66886c..8167840 100644 --- a/src/v3_0/schema.rs +++ b/src/v3_0/schema.rs @@ -330,6 +330,8 @@ pub struct Operation { /// See . pub responses: BTreeMap, + // TODO: see why this doesn't work + // pub responses: BTreeMap>, /// A map of possible out-of band callbacks related to the parent operation. The key is /// a unique identifier for the Callback Object. Each value in the map is a /// [Callback Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#callbackObject) @@ -599,6 +601,10 @@ pub struct Schema { /// See . #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Default)] pub struct Response { + #[serde(rename = "$ref")] + #[serde(skip_serializing_if = "Option::is_none")] + pub ref_path: Option, + /// A short description of the response. /// [CommonMark syntax](http://spec.commonmark.org/) MAY be used for rich text representation. pub description: Option,