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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//! # Doodle
//!
//! The *Doodle* library provides means for data structures to document themselves loosely
//! following the [OpenAPI specification](https://swagger.io/docs/specification/) specification
//!
//! Types that implement the `Schema` trait can document themselves using the methods available.
//! See the `Schema` trait for more info
//!
//! The crate also re-exports `doodle_derive` which provides the derive `Schema` which implements
//! The neccessary methods to serialize the data structure
//!
//! ## Usage example
//!
//! __Cargo.toml__:
//!
//! ```toml
//! [dependencies]
//! serde_json = "1.0.0"
//! doodle = { version = "0.1.1", features = ["derive"] }
//! ```
//!
//! ```
//! use doodle::*;
//! use serde_json::json;
//!
//! #[derive(Schema)]
//! struct Woods {
//! pub id: i32,
//! pub epic: Vec<Vec<Tale>>,
//! }
//!
//! #[derive(Schema)]
//! struct Tale {
//! pub value: Option<String>,
//! }
//!
//! // Initialize an empty dict
//! let mut schema = json! {{}};
//! let map = schema.as_object_mut().unwrap();
//!
//! // Append our schemas
//! Woods::append_to_schema(map);
//! Tale::append_to_schema(map);
//!
//! // print the output
//! let output = serde_json::to_string_pretty(&schema).unwrap();
//! println!("Schema:\n\n{}", output);
//!
//!
//! ////////////////////// Test the example //////////////////////
//!
//!
//! let expected = json! {{
//! "Tale": {
//! "properties": {
//! "value": {
//! "type": "string",
//! "nullable": true
//! }
//! },
//! "type": "object"
//! },
//! "Woods": {
//! "properties": {
//! "epic": {
//! "items": {
//! "items": {
//! "$ref": "#/components/schemas/Tale"
//! },
//! "type": "array"
//! },
//! "type": "array"
//! },
//! "id": {
//! "type": "number"
//! }
//! },
//! "type": "object"
//! }
//! }};
//!
//! assert_eq!(expected, schema);
//!
//! ```
// Reexport serde_json
// Not public API.
pub extern crate serde_json;
// Reexport `Value` which is used by our traits
pub use Value;
// Reexport doodle_derive
pub extern crate doodle_derive;
pub use *;
use Map;
use HashMap;
/// Used to retreive meta information for a `struct`
/// Provides methods to get the `serde_json::Value` representations of the type schema
/// Represents meta information of a single field of a struct