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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//! # Rschema
//!
//! *Rschema* provides a macro for generating JSON schemas from Rust structures.
//!
//! # Example
//!
//! ```no_run
//! use rschema::{
//! Schema,
//! Schematic,
//! };
//!
//! #[derive(Debug, Schematic)]
//! #[rschema(additional_properties)]
//! struct Data {
//! #[rschema(
//! title = "Test flag",
//! description = "The flag whether for test.",
//! )]
//! test_flag: bool,
//! }
//!
//! #[derive(Debug, Schematic)]
//! struct AppConfig {
//! #[rschema(
//! title = "Application name",
//! required,
//! )]
//! name: String,
//!
//! #[rschema(
//! title = "Application version",
//! pattern = r"^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$",
//! required,
//! )]
//! version: String,
//!
//! #[rschema(
//! title = "Application data",
//! description = "This property is optional.",
//! )]
//! other_data: Data,
//! }
//!
//! fn main() -> rschema::Result<()> {
//! Schema::new::<AppConfig>("Application Config")
//! .write_pretty("../schemas/config.schema.json")?;
//!
//! Ok(())
//! }
//! ```
//!
//! This code generates the following JSON schema file.
//!
//! ```json
//! {
//! "title": "Application Config",
//! "type": "object",
//! "properties": {
//! "name": {
//! "title": "Application name",
//! "type": "string"
//! },
//! "version": {
//! "title": "Application version",
//! "type": "string",
//! "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
//! },
//! "other_data": {
//! "title": "Application data",
//! "type": "object",
//! "properties": {
//! "test_flag": {
//! "title": "Test flag",
//! "description": "The flag whether for test.",
//! "type": "boolean"
//! }
//! },
//! "additionalProperties": true
//! }
//! },
//! "required": [
//! "name",
//! "version"
//! ],
//! "additionalProperties": false
//! }
//! ```
//!
//! # Attributes provided
//!
//! - [**Container attributes**](#container-attributes) — apply to a struct or enum declaration.
//! - [**Variant attributes**](#variant-attributes) — apply to a variant of an enum.
//! - [**Field attributes**](#field-attributes) — apply to one field in a struct or in an enum variant.
//!
//! See [Understanding JSON Schema](https://json-schema.org/understanding-json-schema/) for more information on each keywords.
//!
//!
//! ## Container attributes
//!
//! - `#[rschema(additional_properties)]`
//!
//! Indicates whether to allow properties not included in `properties`.
//!
//! - `#[rschema(rename_all = "...")]`
//!
//! Rename all the fields of structs or **unit** variants of enums according to the given case convention.
//!
//! The possible values:
//!
//! - `"lowercase"`
//! - `"UPPERCASE"`
//! - `"camelCase"`
//! - `"PascalCase"`
//! - `"kebab-case"`
//! - `"Train-Case"`
//! - `"COBOL-CASE"`
//! - `"snake_case"`
//! - `"UPPER_SNAKE_CASE"`
//! - `"flatcase"`
//! - `"UPPERFLATCASE"`
//!
//! **Note**: For enums, the `rename_all` attribute is only effective for unit variants.
//! Because the other variants always behave as if the `flatten` attribute of *serde* is applied.
//!
//! - `#[rschema(unique_items)]`
//!
//! Indicates that the tuple struct has unique values.
//!
//! - `#[rschema(defs)]`
//!
//! Define in `$defs` with an auto-generated name.
//!
//! **Note**: This uses `std::any::type_name()` to generate as unique a name as possible.
//! However, it is not guaranteed to be unique.
//!
//! - `#[rschema(defs = "name")]`
//!
//! Define in `$defs` with the given name.
//!
//! **Note**: Any name can be given, but if a name is duplicated, the definition is overwritten.
//! Therefore, it is recommended that do not use this for types that are published.
//!
//!
//! ## Variant attributes
//!
//! - `#[rschema(additional_properties)]`
//!
//! Indicates whether to allow properties not included in `properties`.
//!
//! - `#[rschema(rename = "...")]`
//!
//! Rename a unit variant. This takes precedence over the `rename_all` attribute.
//!
//! - `#[rschema(rename_all = "...")]`
//!
//! Rename all the fields of struct variants according to the given case convention.
//!
//! The possible values are the same as of `Container attributes`' one.
//!
//! - `#[rschema(skip)]`
//!
//! Skip not to include in schema.
//!
//! - `#[rschema(unique_items)]`
//!
//! Indicates that the tuple struct has unique values.
//!
//!
//! ## Field attributes
//!
//! None of these keywords are required, but they are encouraged for good practice.
//!
//! For keywords other than in [`Common`](#common), while it raises no errors to use attributes of another types, it doesn’t really make sense to do so.
//!
//! #### Common
//!
//! - `#[rschema(title = "title")]`
//!
//! The short description for the field.
//!
//! - `#[rschema(description = "description")]`
//!
//! The more lengthy description for the field.
//!
//! - `#[rschema(comment)]`
//!
//! The comment for this schema.
//!
//! - `#[rschema(deprecated)]`
//!
//! Indicate that the property this keyword applies to should not be used and may be removed in the future.
//!
//! - `#[rschema(required)]`
//!
//! Indicate that the property this keyword applies to is required.
//!
//! - `#[rschema(rename = "name")]`
//!
//! Renames the field name with the given name.
//!
//! - `#[rschema(alt = "path")]`
//!
//! This is very similar to the serde's `remote` attribute. But it does not check that all the fields in the definition you provided match those in the external type.
//!
//! If use external types, it probably does not implement `Schematic`. In such a case, you need to give the schema information instead by specifying another type that implements `Schematic`.
//!
//! **Note**: Rschema does not pre-implement the `Schematic` for types provided by non-standard crates. It is to prevent cyclic package dependency, in the case that external crates come to implement `Schematic` in the future.
//!
//! - `#[rschema(skip)]`
//!
//! Skip not to include in schema.
//!
//!
//! #### `string`
//!
//! - `#[rschema(min_length = 1)]`
//!
//! Specify the minimum length. Give an integer greater than or equal to 0.
//!
//! - `#[rschema(max_length = 1)]`
//!
//! Specify the maximum length. Give an integer greater than or equal to 0.
//!
//! - `#[rschema(pattern = "regular expressions")]`
//!
//! The regular expression to restrict a string. If necessary, you should use raw string literals to work around escaping.
//!
//! - `#[rschema(format = "format")]`
//!
//! The basic semantic identification of certain kinds of string values that are commonly used.
//!
//!
//! #### `number`
//!
//! - `#[rschema(minimum = 1)]`
//!
//! Specify the minimum of the range.
//!
//! - `#[rschema(maximum = 1)]`
//!
//! Specify the maximum of the range.
//!
//! - `#[rschema(multiple_of = 1)]`
//!
//! Restrict the number to a multiple of a given number.
//!
//! - `#[rschema(exclusive_minimum = 1)]`
//!
//! Specify the **exclusive** minimum of the range.
//!
//! - `#[rschema(exclusive_maximum = 1)]`
//!
//! Specify the **exclusive** maximum of the range.
//!
//!
//! #### `array`
//!
//! - `#[rschema(min_items = 1)]`
//!
//! Specify the minimum length of the array. Give an integer greater than or equal to 0.
//!
//! - `#[rschema(max_items = 1)]`
//!
//! Specify the maximum length of the array. Give an integer greater than or equal to 0.
//!
//! - `#[rschema(unique_items)]`
//!
//! Indicates that the array has unique values.
//!
//!
//! # Combination with Serde
//!
//! *Rschema* is strongly intended to be used in combination with [*Serde*](https://serde.rs/).
//!
//! For example, generate a JSON schema from structs and enums you define.
//! Data files validated by the JSON schema are always deserializable to the original structures!
//!
//!
pub use ;
extern crate rschema_derive;
pub use *;