Skip to content

Commit

Permalink
oapi: Add extensions support for OpenApi (#897)
Browse files Browse the repository at this point in the history
* oapi: Add extensions support for OpenApi

* Format Rust code using rustfmt

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
chrislearn and github-actions[bot] authored Sep 10, 2024
1 parent 390a96b commit 8873730
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
10 changes: 10 additions & 0 deletions crates/oapi/src/openapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ pub struct OpenApi {
/// All the references and invidual files could use their own schema dialect.
#[serde(rename = "$schema", default, skip_serializing_if = "String::is_empty")]
pub schema: String,

/// Optional extensions "x-something".
#[serde(skip_serializing_if = "Option::is_none", flatten)]
pub extensions: Option<PropMap<String, serde_json::Value>>,
}

impl OpenApi {
Expand Down Expand Up @@ -399,6 +403,12 @@ impl OpenApi {
self
}

/// Add openapi extensions (`x-something`) for [`OpenApi`].
pub fn extensions(mut self, extensions: PropMap<String, serde_json::Value>) -> Self {
self.extensions = Some(extensions);
self
}

/// Consusmes the [`OpenApi`] and returns [`Router`] with the [`OpenApi`] as handler.
pub fn into_router(self, path: impl Into<String>) -> Router {
Router::with_path(path.into()).goal(self)
Expand Down
4 changes: 2 additions & 2 deletions crates/oapi/src/openapi/schema/all_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ impl AllOf {
}

/// Add openapi extensions (`x-something`) for [`AllOf`].
pub fn extensions(mut self, extensions: Option<PropMap<String, serde_json::Value>>) -> Self {
self.extensions = extensions;
pub fn extensions(mut self, extensions: PropMap<String, serde_json::Value>) -> Self {
self.extensions = Some(extensions);
self
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oapi/src/openapi/schema/any_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ impl AnyOf {
}

/// Add openapi extensions (`x-something`) for [`AnyOf`].
pub fn extensions(mut self, extensions: Option<PropMap<String, serde_json::Value>>) -> Self {
self.extensions = extensions;
pub fn extensions(mut self, extensions: PropMap<String, serde_json::Value>) -> Self {
self.extensions = Some(extensions);
self
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oapi/src/openapi/schema/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ impl Array {
}

/// Add openapi extensions (`x-something`) for [`Array`].
pub fn extensions(mut self, extensions: Option<PropMap<String, serde_json::Value>>) -> Self {
self.extensions = extensions;
pub fn extensions(mut self, extensions: PropMap<String, serde_json::Value>) -> Self {
self.extensions = Some(extensions);
self
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oapi/src/openapi/schema/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ impl Object {
}

/// Add openapi extensions (`x-something`) for [`Object`].
pub fn extensions(mut self, extensions: Option<PropMap<String, serde_json::Value>>) -> Self {
self.extensions = extensions;
pub fn extensions(mut self, extensions: PropMap<String, serde_json::Value>) -> Self {
self.extensions = Some(extensions);
self
}

Expand Down
4 changes: 2 additions & 2 deletions crates/oapi/src/openapi/schema/one_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ impl OneOf {
}

/// Add openapi extensions (`x-something`) for [`OneOf`].
pub fn extensions(mut self, extensions: Option<PropMap<String, serde_json::Value>>) -> Self {
self.extensions = extensions;
pub fn extensions(mut self, extensions: PropMap<String, serde_json::Value>) -> Self {
self.extensions = Some(extensions);
self
}
}
Expand Down

0 comments on commit 8873730

Please sign in to comment.