forked from oxidecomputer/typify
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmulti_derive.rs
191 lines (189 loc) · 5.36 KB
/
multi_derive.rs
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
#![allow(clippy::redundant_closure_call)]
#![allow(clippy::needless_lifetimes)]
#![allow(clippy::match_single_binding)]
#![allow(clippy::clone_on_copy)]
use serde::{Deserialize, Serialize};
#[doc = r" Error types."]
pub mod error {
#[doc = r" Error from a TryFrom or FromStr implementation."]
pub struct ConversionError(std::borrow::Cow<'static, str>);
impl std::error::Error for ConversionError {}
impl std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
std::fmt::Display::fmt(&self.0, f)
}
}
impl std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
#[doc = "Fruit"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
#[doc = r""]
#[doc = r" ```json"]
#[doc = "{"]
#[doc = " \"type\": \"object\""]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(AnotherDerive, Clone, Debug, Deserialize, ExtraDerive, Serialize)]
pub struct Fruit(pub serde_json::Map<String, serde_json::Value>);
impl std::ops::Deref for Fruit {
type Target = serde_json::Map<String, serde_json::Value>;
fn deref(&self) -> &serde_json::Map<String, serde_json::Value> {
&self.0
}
}
impl From<Fruit> for serde_json::Map<String, serde_json::Value> {
fn from(value: Fruit) -> Self {
value.0
}
}
impl From<&Self> for Fruit {
fn from(value: &Self) -> Self {
value.clone()
}
}
impl From<serde_json::Map<String, serde_json::Value>> for Fruit {
fn from(value: serde_json::Map<String, serde_json::Value>) -> Self {
Self(value)
}
}
#[doc = "FruitOrVeg"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
#[doc = r""]
#[doc = r" ```json"]
#[doc = "{"]
#[doc = " \"oneOf\": ["]
#[doc = " {"]
#[doc = " \"title\": \"veg\","]
#[doc = " \"anyOf\": ["]
#[doc = " {"]
#[doc = " \"$ref\": \"#/defs/veggie\""]
#[doc = " }"]
#[doc = " ]"]
#[doc = " },"]
#[doc = " {"]
#[doc = " \"title\": \"fruit\","]
#[doc = " \"anyOf\": ["]
#[doc = " {"]
#[doc = " \"$ref\": \"#/defs/fruit\""]
#[doc = " }"]
#[doc = " ]"]
#[doc = " }"]
#[doc = " ]"]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(AnotherDerive, Clone, Debug, Deserialize, ExtraDerive, Serialize)]
#[serde(untagged)]
pub enum FruitOrVeg {
Veg(Veggie),
Fruit(Fruit),
}
impl From<&Self> for FruitOrVeg {
fn from(value: &Self) -> Self {
value.clone()
}
}
impl From<Veggie> for FruitOrVeg {
fn from(value: Veggie) -> Self {
Self::Veg(value)
}
}
impl From<Fruit> for FruitOrVeg {
fn from(value: Fruit) -> Self {
Self::Fruit(value)
}
}
#[doc = "Veggie"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
#[doc = r""]
#[doc = r" ```json"]
#[doc = "{"]
#[doc = " \"type\": \"object\","]
#[doc = " \"required\": ["]
#[doc = " \"veggieLike\","]
#[doc = " \"veggieName\""]
#[doc = " ],"]
#[doc = " \"properties\": {"]
#[doc = " \"veggieLike\": {"]
#[doc = " \"description\": \"Do I like this vegetable?\","]
#[doc = " \"type\": \"boolean\""]
#[doc = " },"]
#[doc = " \"veggieName\": {"]
#[doc = " \"description\": \"The name of the vegetable.\","]
#[doc = " \"type\": \"string\""]
#[doc = " }"]
#[doc = " }"]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(AnotherDerive, Clone, Debug, Deserialize, ExtraDerive, Serialize)]
pub struct Veggie {
#[doc = "Do I like this vegetable?"]
#[serde(rename = "veggieLike")]
pub veggie_like: bool,
#[doc = "The name of the vegetable."]
#[serde(rename = "veggieName")]
pub veggie_name: String,
}
impl From<&Self> for Veggie {
fn from(value: &Self) -> Self {
value.clone()
}
}
#[doc = "A representation of a person, company, organization, or place"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
#[doc = r""]
#[doc = r" ```json"]
#[doc = "{"]
#[doc = " \"$id\": \"https://example.com/arrays.schema.json\","]
#[doc = " \"title\": \"veggies\","]
#[doc = " \"description\": \"A representation of a person, company, organization, or place\","]
#[doc = " \"type\": \"object\","]
#[doc = " \"properties\": {"]
#[doc = " \"fruits\": {"]
#[doc = " \"type\": \"array\","]
#[doc = " \"items\": {"]
#[doc = " \"type\": \"string\""]
#[doc = " }"]
#[doc = " },"]
#[doc = " \"vegetables\": {"]
#[doc = " \"type\": \"array\","]
#[doc = " \"items\": {"]
#[doc = " \"$ref\": \"#/$defs/veggie\""]
#[doc = " }"]
#[doc = " }"]
#[doc = " }"]
#[doc = "}"]
#[doc = r" ```"]
#[doc = r" </details>"]
#[derive(AnotherDerive, Clone, Debug, Deserialize, ExtraDerive, Serialize)]
pub struct Veggies {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub fruits: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub vegetables: Vec<Veggie>,
}
impl From<&Self> for Veggies {
fn from(value: &Self) -> Self {
value.clone()
}
}