Skip to content

Commit

Permalink
Oapi: Enable required usage with schema_with attribute (#513)
Browse files Browse the repository at this point in the history
* Enable required usage with schema_with attribute

* wip
  • Loading branch information
chrislearn authored Nov 27, 2023
1 parent 1f79496 commit ddb457a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Display for CompressionAlgo {
CompressionAlgo::Gzip => write!(f, "gzip"),
#[cfg(feature = "zstd")]
CompressionAlgo::Zstd => write!(f, "zstd"),
_ => write!(f, "unreached"),
_ => unreachable!(),
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions crates/oapi-macros/src/schema/struct_schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,15 @@ impl ToTokens for NamedStructSchema<'_> {
.property(#name, #property)
});

if let Property::Schema(_) = property {
if (!is_option && crate::is_required(field_rule.as_ref(), container_rules.as_ref()))
|| required
.as_ref()
.map(crate::feature::Required::is_true)
.unwrap_or(false)
{
object_tokens.extend(quote! {
.required(#name)
})
}
if (!is_option && crate::is_required(field_rule.as_ref(), container_rules.as_ref()))
|| required
.as_ref()
.map(crate::feature::Required::is_true)
.unwrap_or(false)
{
object_tokens.extend(quote! {
.required(#name)
})
}

object_tokens
Expand Down
2 changes: 2 additions & 0 deletions crates/oapi/src/openapi/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//! used to define field properties, enum values, array or object types.
//!
//! [schema]: https://spec.openapis.org/oas/latest.html#schema-object
use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

use crate::RefOr;
Expand Down

0 comments on commit ddb457a

Please sign in to comment.