schema: make schema types #[non_exhaustive]

This way extending them is not a breaking change anymore.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2025-01-15 10:53:30 +01:00
parent c794c42919
commit 72c95c35bb
2 changed files with 9 additions and 7 deletions

View File

@ -183,6 +183,7 @@ impl<'a> FromIterator<(&'a str, Error)> for ParameterError {
/// Data type to describe boolean values
#[derive(Debug)]
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
#[non_exhaustive]
pub struct BooleanSchema {
pub description: &'static str,
/// Optional default value.
@ -218,6 +219,7 @@ impl BooleanSchema {
/// Data type to describe integer values.
#[derive(Debug)]
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
#[non_exhaustive]
pub struct IntegerSchema {
pub description: &'static str,
/// Optional minimum.
@ -293,6 +295,7 @@ impl IntegerSchema {
/// Data type to describe (JSON like) number value
#[derive(Debug)]
#[non_exhaustive]
pub struct NumberSchema {
pub description: &'static str,
/// Optional minimum.
@ -390,6 +393,7 @@ impl PartialEq for NumberSchema {
/// Data type to describe string values.
#[derive(Debug)]
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
#[non_exhaustive]
pub struct StringSchema {
pub description: &'static str,
/// Optional default value.
@ -512,6 +516,7 @@ impl StringSchema {
/// schema.
#[derive(Debug)]
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
#[non_exhaustive]
pub struct ArraySchema {
pub description: &'static str,
/// Element type schema.
@ -632,6 +637,7 @@ impl KeyAliasInfo {
/// Data type to describe objects (maps).
#[derive(Debug)]
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
#[non_exhaustive]
pub struct ObjectSchema {
pub description: &'static str,
/// If set, allow additional properties which are not defined in
@ -719,6 +725,7 @@ impl ObjectSchema {
/// Schema, this is not supported, so here we simply assume additional properties to be allowed.
#[derive(Debug)]
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
#[non_exhaustive]
pub struct AllOfSchema {
pub description: &'static str,
@ -771,6 +778,7 @@ impl AllOfSchema {
/// Note that these are limited to object schemas. Other schemas will produce errors.
#[derive(Debug)]
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
#[non_exhaustive]
pub struct OneOfSchema {
pub description: &'static str,

View File

@ -20,13 +20,7 @@ fn parse_query_string<T: Into<ParameterSchema>>(
#[test]
fn test_schema1() {
let schema = Schema::Object(ObjectSchema {
description: "TEST",
additional_properties: false,
properties: &[],
default_key: None,
key_alias_info: None,
});
let schema = ObjectSchema::new("TEST", &[]).schema();
println!("TEST Schema: {:?}", schema);
}