schemars/json_schema_impls/
nonzero_signed.rs

1use crate::gen::SchemaGenerator;
2use crate::schema::*;
3use crate::JsonSchema;
4use std::num::*;
5
6macro_rules! nonzero_unsigned_impl {
7    ($type:ty => $primitive:ty) => {
8        impl JsonSchema for $type {
9            no_ref_schema!();
10
11            fn schema_name() -> String {
12                stringify!($type).to_owned()
13            }
14
15            fn json_schema(gen: &mut SchemaGenerator) -> Schema {
16                let zero_schema: Schema = SchemaObject {
17                    const_value: Some(0.into()),
18                    ..Default::default()
19                }
20                .into();
21                let mut schema: SchemaObject = <$primitive>::json_schema(gen).into();
22                schema.subschemas().not = Some(Box::from(zero_schema));
23                schema.into()
24            }
25        }
26    };
27}
28
29nonzero_unsigned_impl!(NonZeroI8 => i8);
30nonzero_unsigned_impl!(NonZeroI16 => i16);
31nonzero_unsigned_impl!(NonZeroI32 => i32);
32nonzero_unsigned_impl!(NonZeroI64 => i64);
33nonzero_unsigned_impl!(NonZeroI128 => i128);
34nonzero_unsigned_impl!(NonZeroIsize => isize);