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
//! [JSON Schema](https://json-schema.org) exporter and importer for [Specta](specta).
//!
//! This crate provides bidirectional conversion between Specta types and JSON Schema:
//! - Export Specta types to JSON Schema (Draft 7, 2019-09, or 2020-12)
//! - Import JSON Schema definitions as Specta DataTypes
//!
//! # Features
//!
//! - **Bidirectional conversion**: Export to JSON Schema and import from JSON Schema
//! - **Multiple schema versions**: Support for Draft 7 (default), Draft 2019-09, and Draft 2020-12
//! - **Serde integration**: Use `specta-serde` in userspace before export
//! - **Flexible layouts**: Single file with `$defs` or separate files per type
//! - **schemars ecosystem**: Compatible with the schemars crate for interoperability
//!
//! # Usage
//!
//! ## Exporting to JSON Schema
//!
//! ```ignore
//! use serde::{Deserialize, Serialize};
//! use specta::{Type, Types};
//! use specta_jsonschema::{JsonSchema, SchemaVersion};
//!
//! #[derive(Serialize, Deserialize, Type)]
//! #[serde(rename_all = "camelCase")]
//! pub struct User {
//! pub id: u32,
//! pub name: String,
//! pub email: Option<String>,
//! }
//!
//! fn main() {
//! let types = Types::default()
//! .register::<User>();
//!
//! // Export to JSON Schema
//! let schema = JsonSchema::default()
//! .schema_version(SchemaVersion::Draft7)
//! .export(&types, specta_serde::Format)
//! .unwrap();
//!
//! println!("{}", schema);
//! }
//! ```
//!
//! ## With Serde Integration
//!
//! ```ignore
//! use serde::{Deserialize, Serialize};
//! use specta::{Type, Types};
//! use specta_jsonschema::JsonSchema;
//!
//! #[derive(Serialize, Deserialize, Type)]
//! #[serde(rename_all = "camelCase")]
//! pub struct User {
//! pub user_id: u32,
//! #[serde(rename = "fullName")]
//! pub name: String,
//! }
//!
//! fn main() {
//! let types = Types::default().register::<User>();
//!
//! JsonSchema::default()
//! .export_to("./schema.json", &types, specta_serde::Format)
//! .unwrap();
//! }
//! ```
//!
//! ## Importing from JSON Schema
//!
//! ```ignore
//! use schemars::Schema;
//! use specta_jsonschema::import::from_schema;
//!
//! let schema: Schema = serde_json::from_str(r#"{
//! "type": "object",
//! "properties": {
//! "name": { "type": "string" },
//! "age": { "type": "integer" }
//! },
//! "required": ["name"]
//! }"#).unwrap();
//!
//! let datatype = from_schema(&schema).unwrap();
//! ```
//!
//! ## Multiple Output Layouts
//!
//! ```ignore
//! use specta_jsonschema::{JsonSchema, Layout};
//!
//! // Single file with all types in $defs
//! JsonSchema::default()
//! .layout(Layout::SingleFile)
//! .export_to(
//! "./schema.json",
//! &types,
//! specta_serde::Format,
//! )
//! .unwrap();
//!
//! // Separate file per type, organized by module
//! JsonSchema::default()
//! .layout(Layout::Files)
//! .export_to(
//! "./schemas/",
//! &types,
//! specta_serde::Format,
//! )
//! .unwrap();
//! ```
// TODO: leaving this until it's implemented to avoid unnecessary warnings.
pub use Error;
pub use JsonSchema;
pub use Layout;
pub use SchemaVersion;
// Legacy function - kept for backward compatibility