predawn_schema/impls/
json.rs

1use std::{borrow::Cow, collections::BTreeMap};
2
3use openapiv3::{AnySchema, NumberType, Schema, SchemaData, SchemaKind, Type};
4use serde_json::{Map, Number, Value};
5
6use super::forward_impl;
7use crate::ToSchema;
8
9impl ToSchema for Value {
10    fn title() -> Cow<'static, str> {
11        "Any".into()
12    }
13
14    fn schema(_: &mut BTreeMap<String, Schema>, _: &mut Vec<String>) -> Schema {
15        Schema {
16            schema_data: SchemaData {
17                title: Some(Self::title().into()),
18                ..Default::default()
19            },
20            schema_kind: SchemaKind::Any(AnySchema::default()),
21        }
22    }
23}
24
25forward_impl!(Map<String, Value> => BTreeMap<String, Value>);
26
27impl ToSchema for Number {
28    fn title() -> Cow<'static, str> {
29        "Number".into()
30    }
31
32    fn schema(_: &mut BTreeMap<String, Schema>, _: &mut Vec<String>) -> Schema {
33        Schema {
34            schema_data: SchemaData {
35                title: Some(Self::title().into()),
36                ..Default::default()
37            },
38            schema_kind: SchemaKind::Type(Type::Number(NumberType::default())),
39        }
40    }
41}
42
43#[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))]
44#[cfg(feature = "raw_value")]
45mod raw_value {
46    use serde_json::{value::RawValue, Value};
47
48    use super::forward_impl;
49    forward_impl!(RawValue => Value);
50}