Skip to content

Commit

Permalink
fix: generate openapi json have duplicated fields #360 (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn authored Aug 10, 2023
1 parent bfab74a commit 9def4b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/extra/src/concurrency_limiter.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! size limiter middleware
//! concurrency limiter middleware

use tokio::sync::Semaphore;

use salvo_core::http::StatusError;
use salvo_core::http::{Body, Request, Response};
use salvo_core::http::{Request, Response};
use salvo_core::{async_trait, Depot, FlowCtrl, Handler};

/// MaxConcurrency
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 @@ -230,7 +230,7 @@ impl ToSchema for StatusError {
.property("name", String::to_schema(components))
.required("brief")
.property("brief", String::to_schema(components))
.required("brief")
.required("detail")
.property("detail", String::to_schema(components))
.property("cause", String::to_schema(components)),
);
Expand Down
7 changes: 4 additions & 3 deletions crates/oapi/src/openapi/schema/object.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;

use indexmap::IndexSet;
use serde::{Deserialize, Serialize};
use serde_json::Value;

Expand Down Expand Up @@ -50,8 +51,8 @@ pub struct Object {
pub enum_values: Option<Vec<Value>>,

/// Vector of required field names.
#[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")]
pub required: Vec<String>,
#[serde(skip_serializing_if = "IndexSet::is_empty", default = "IndexSet::new")]
pub required: IndexSet<String>,

/// Map of fields with their [`Schema`] types.
///
Expand Down Expand Up @@ -194,7 +195,7 @@ impl Object {

/// Add field to the required fields of [`Object`].
pub fn required(mut self, required_field: impl Into<String>) -> Self {
self.required.push(required_field.into());
self.required.insert(required_field.into());
self
}

Expand Down

0 comments on commit 9def4b2

Please sign in to comment.