1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::collections::BTreeMap;

use openapiv3::{AnySchema, NumberType, Schema, SchemaData, SchemaKind, Type};
use serde_json::{Map, Number, Value};

use super::forward_impl;
use crate::ToSchema;

impl ToSchema for Value {
    fn schema(_: &mut BTreeMap<String, Schema>, _: &mut Vec<String>) -> Schema {
        Schema {
            schema_data: SchemaData {
                title: Some("Any".to_string()),
                ..Default::default()
            },
            schema_kind: SchemaKind::Any(AnySchema::default()),
        }
    }
}

forward_impl!(Map<String, Value> => BTreeMap<String, Value>);

impl ToSchema for Number {
    fn schema(_: &mut BTreeMap<String, Schema>, _: &mut Vec<String>) -> Schema {
        Schema {
            schema_data: SchemaData {
                title: Some("Number".to_string()),
                ..Default::default()
            },
            schema_kind: SchemaKind::Type(Type::Number(NumberType::default())),
        }
    }
}

#[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))]
#[cfg(feature = "raw_value")]
mod raw_value {
    use serde_json::{value::RawValue, Value};

    use super::forward_impl;
    forward_impl!(RawValue => Value);
}