Skip to content

Commit

Permalink
Add some deprecated attributes for example method
Browse files Browse the repository at this point in the history
  • Loading branch information
juhaku committed Aug 11, 2024
1 parent 67f04b3 commit 55544ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions utoipa-gen/tests/path_derive_actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ fn derive_into_params_in_another_module() {

#[derive(Deserialize, IntoParams)]
pub struct FooParams {
#[allow(unused)]
pub id: String,
}
}
Expand Down
11 changes: 8 additions & 3 deletions utoipa/src/openapi/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ impl OneOfBuilder {
/// Add or change example shown in UI of the value for richer documentation.
///
/// **Deprecated since 3.0.x. Prefer [`OneOfBuilder::examples`] instead**
#[deprecated = "Since OpenAPI 3.1 prefer using `examples`"]
pub fn example(mut self, example: Option<Value>) -> Self {
set_value!(self example example)
}
Expand Down Expand Up @@ -613,6 +614,7 @@ impl AllOfBuilder {
/// Add or change example shown in UI of the value for richer documentation.
///
/// **Deprecated since 3.0.x. Prefer [`AllOfBuilder::examples`] instead**
#[deprecated = "Since OpenAPI 3.1 prefer using `examples`"]
pub fn example(mut self, example: Option<Value>) -> Self {
set_value!(self example example)
}
Expand Down Expand Up @@ -773,6 +775,7 @@ impl AnyOfBuilder {
/// Add or change example shown in UI of the value for richer documentation.
///
/// **Deprecated since 3.0.x. Prefer [`AllOfBuilder::examples`] instead**
#[deprecated = "Since OpenAPI 3.1 prefer using `examples`"]
pub fn example(mut self, example: Option<Value>) -> Self {
set_value!(self example example)
}
Expand Down Expand Up @@ -1079,6 +1082,7 @@ impl ObjectBuilder {
/// Add or change example shown in UI of the value for richer documentation.
///
/// **Deprecated since 3.0.x. Prefer [`Object::examples`] instead**
#[deprecated = "Since OpenAPI 3.1 prefer using `examples`"]
pub fn example(mut self, example: Option<Value>) -> Self {
set_value!(self example example)
}
Expand Down Expand Up @@ -1527,6 +1531,7 @@ impl ArrayBuilder {
/// Add or change example shown in UI of the value for richer documentation.
///
/// **Deprecated since 3.0.x. Prefer [`Array::examples`] instead**
#[deprecated = "Since OpenAPI 3.1 prefer using `examples`"]
pub fn example(mut self, example: Option<Value>) -> Self {
set_value!(self example example)
}
Expand Down Expand Up @@ -2066,10 +2071,10 @@ mod tests {
}

#[test]
fn derive_object_with_example() {
let expected = r#"{"type":"object","example":{"age":20,"name":"bob the cat"}}"#;
fn derive_object_with_examples() {
let expected = r#"{"type":"object","examples":[{"age":20,"name":"bob the cat"}]}"#;
let json_value = ObjectBuilder::new()
.example(Some(json!({"age": 20, "name": "bob the cat"})))
.examples([Some(json!({"age": 20, "name": "bob the cat"}))])
.build();

let value_string = serde_json::to_string(&json_value).unwrap();
Expand Down

0 comments on commit 55544ef

Please sign in to comment.