Skip to content

Commit

Permalink
oapi: Fix ToSchema #[serde(default)] conflict (#574)
Browse files Browse the repository at this point in the history
* oapi: Fix ToSchema #[serde(default)] conflict

* Format Rust code using rustfmt

* wip

* wip

* cargo fmt

* wip

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
chrislearn and github-actions[bot] authored Dec 19, 2023
1 parent 1d1940e commit 5f765a9
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
16 changes: 8 additions & 8 deletions crates/oapi-macros/src/endpoint/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ impl Server {
/// Add url to the target [`Server`].
pub fn url<U: Into<String>>(mut self, url: U) -> Self {
self.url = url.into();
self
self
}

/// Add or change description of the [`Server`].
pub fn description<S: Into<String>>(mut self, description: S) -> Self {
self.description = Some(description.into());
self
self
}

/// Add parameter to [`Server`] which is used to substitute values in [`Server::url`].
Expand Down Expand Up @@ -304,21 +304,21 @@ impl ServerVariable {
Default::default()
}
/// Add default value for substitution.
pub fn default_value<S: Into<String>>(mut self, default_value: S) -> Self {
self.default_value = default_value.into();
self
pub fn default_value(mut self, default: impl Into<String>) -> Self {
self.default_value = Some(default.into());
self
}

/// Add or change description of substituted parameter.
pub fn description<S: Into<String>>(mut self, description: S) -> Self {
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
self
}

/// Add or change possible values used to substitute parameter.
pub fn enum_values<I: IntoIterator<Item = V>, V: Into<String>>(mut self, enum_values: I) -> Self {
self.enum_values = enum_values.into_iter().map(|value| value.into()).collect();
self
self
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oapi-macros/src/schema/enum_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl ToTokens for UntaggedEnum {
tokens.extend(quote! {
#oapi::oapi::schema::Object::new()
.nullable(true)
.default(Some(serde_json::Value::Null))
.default_value(serde_json::Value::Null)
#symbol
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl<T: ToSchema> ToSchema for Option<T> {

impl<T> ToSchema for PhantomData<T> {
fn to_schema(_components: &mut Components) -> RefOr<schema::Schema> {
Schema::Object(Object::default()).into()
Schema::Object(Default::default()).into()
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oapi/src/openapi/schema/all_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct AllOf {
pub description: Option<String>,

/// Default value which is provided when user has not provided the input in Swagger UI.
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<Value>,
#[serde(rename = "default", skip_serializing_if = "Option::is_none")]
pub default_value: Option<Value>,

/// Example shown in UI of the value for richer documentation.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -89,7 +89,7 @@ impl AllOf {

/// Add or change default value for the object which is provided when user has not provided the input in Swagger UI.
pub fn default_value(mut self, default: Value) -> Self {
self.default = Some(default);
self.default_value = Some(default);
self
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oapi/src/openapi/schema/any_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct AnyOf {
pub description: Option<String>,

/// Default value which is provided when user has not provided the input in Swagger UI.
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<Value>,
#[serde(rename = "default", skip_serializing_if = "Option::is_none")]
pub default_value: Option<Value>,

/// Example shown in UI of the value for richer documentation.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -89,7 +89,7 @@ impl AnyOf {

/// Add or change default value for the object which is provided when user has not provided the input in Swagger UI.
pub fn default_value(mut self, default: Value) -> Self {
self.default = Some(default);
self.default_value = Some(default);
self
}

Expand Down
10 changes: 5 additions & 5 deletions crates/oapi/src/openapi/schema/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct Array {
pub example: Option<Value>,

/// Default value which is provided when user has not provided the input in Swagger UI.
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<Value>,
#[serde(rename = "default", skip_serializing_if = "Option::is_none")]
pub default_value: Option<Value>,

/// Max length of the array.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -69,7 +69,7 @@ impl Default for Array {
description: Default::default(),
deprecated: Default::default(),
example: Default::default(),
default: Default::default(),
default_value: Default::default(),
max_items: Default::default(),
min_items: Default::default(),
xml: Default::default(),
Expand Down Expand Up @@ -125,8 +125,8 @@ impl Array {
}

/// Add or change default value for the object which is provided when user has not provided the input in Swagger UI.
pub fn default(mut self, default: Value) -> Self {
self.default = Some(default);
pub fn default_value(mut self, default: Value) -> Self {
self.default_value = Some(default);
self
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oapi/src/openapi/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub enum Schema {

impl Default for Schema {
fn default() -> Self {
Schema::Object(Object::default())
Schema::Object(Default::default())
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oapi/src/openapi/schema/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub struct Object {
pub description: Option<String>,

/// Default value which is provided when user has not provided the input in Swagger UI.
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<Value>,
#[serde(rename = "default", skip_serializing_if = "Option::is_none")]
pub default_value: Option<Value>,

/// Enum variants of fields that can be represented as `unit` type `enums`
#[serde(rename = "enum", skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -213,7 +213,7 @@ impl Object {

/// Add or change default value for the object which is provided when user has not provided the input in Swagger UI.
pub fn default_value(mut self, default: Value) -> Self {
self.default = Some(default);
self.default_value = Some(default);
self
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oapi/src/openapi/schema/one_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct OneOf {
pub description: Option<String>,

/// Default value which is provided when user has not provided the input in Swagger UI.
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<Value>,
#[serde(rename = "default", skip_serializing_if = "Option::is_none")]
pub default_value: Option<Value>,

/// Example shown in UI of the value for richer documentation.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -89,7 +89,7 @@ impl OneOf {

/// Add or change default value for the object which is provided when user has not provided the input in Swagger UI.
pub fn default_value(mut self, default: Value) -> Self {
self.default = Some(default);
self.default_value = Some(default);
self
}

Expand Down

0 comments on commit 5f765a9

Please sign in to comment.