Skip to content

Commit 7cc56ac

Browse files
Simplify schema for schemars bump
Signed-off-by: Danil-Grigorev <[email protected]>
1 parent 1c46714 commit 7cc56ac

File tree

2 files changed

+10
-150
lines changed

2 files changed

+10
-150
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ hyper-timeout = "0.5.1"
6060
hyper-util = "0.1.11"
6161
json-patch = "4"
6262
jsonpath-rust = "0.7.3"
63-
k8s-openapi = { git = "https://github.com/Arnavion/k8s-openapi.git", branch = "master", default-features = false }
63+
k8s-openapi = { git = "https://github.com/Arnavion/k8s-openapi.git", rev = "e9a9eaf", default-features = false }
6464
openssl = "0.10.36"
6565
parking_lot = "0.12.0"
6666
pem = "3.0.1"

kube-core/src/schema.rs

Lines changed: 9 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -54,48 +54,26 @@ struct SchemaObject {
5454
/// and [JSON Schema 4.2.1. Instance Data Model](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-4.2.1).
5555
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
5656
instance_type: Option<SingleOrVec<InstanceType>>,
57-
/// The `format` keyword.
58-
///
59-
/// See [JSON Schema Validation 7. A Vocabulary for Semantic Content With "format"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-7).
60-
#[serde(skip_serializing_if = "Option::is_none")]
61-
format: Option<String>,
6257
/// The `enum` keyword.
6358
///
6459
/// See [JSON Schema Validation 6.1.2. "enum"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.2)
6560
#[serde(rename = "enum", skip_serializing_if = "Option::is_none")]
6661
enum_values: Option<Vec<Value>>,
67-
/// The `const` keyword.
68-
///
69-
/// See [JSON Schema Validation 6.1.3. "const"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.1.3)
70-
#[serde(
71-
rename = "const",
72-
skip_serializing_if = "Option::is_none",
73-
deserialize_with = "allow_null"
74-
)]
75-
const_value: Option<Value>,
7662
/// Properties of the [`SchemaObject`] which define validation assertions in terms of other schemas.
7763
#[serde(flatten, deserialize_with = "skip_if_default")]
7864
subschemas: Option<Box<SubschemaValidation>>,
79-
/// Properties of the [`SchemaObject`] which define validation assertions for numbers.
80-
#[serde(flatten, deserialize_with = "skip_if_default")]
81-
number: Option<Box<NumberValidation>>,
82-
/// Properties of the [`SchemaObject`] which define validation assertions for strings.
83-
#[serde(flatten, deserialize_with = "skip_if_default")]
84-
string: Option<Box<StringValidation>>,
8565
/// Properties of the [`SchemaObject`] which define validation assertions for arrays.
8666
#[serde(flatten, deserialize_with = "skip_if_default")]
8767
array: Option<Box<ArrayValidation>>,
8868
/// Properties of the [`SchemaObject`] which define validation assertions for objects.
8969
#[serde(flatten, deserialize_with = "skip_if_default")]
9070
object: Option<Box<ObjectValidation>>,
91-
/// The `$ref` keyword.
92-
///
93-
/// See [JSON Schema 8.2.4.1. Direct References with "$ref"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-8.2.4.1).
94-
#[serde(rename = "$ref", skip_serializing_if = "Option::is_none")]
95-
reference: Option<String>,
9671
/// Arbitrary extra properties which are not part of the JSON Schema specification, or which `schemars` does not support.
9772
#[serde(flatten)]
9873
extensions: BTreeMap<String, Value>,
74+
/// Arbitrary data.
75+
#[serde(flatten)]
76+
other: Value,
9977
}
10078

10179
// Deserializing "null" to `Option<Value>` directly results in `None`,
@@ -124,16 +102,6 @@ where
124102
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
125103
#[serde(rename_all = "camelCase", default)]
126104
struct Metadata {
127-
/// The `$id` keyword.
128-
///
129-
/// See [JSON Schema 8.2.2. The "$id" Keyword](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-8.2.2).
130-
#[serde(rename = "$id", skip_serializing_if = "Option::is_none")]
131-
id: Option<String>,
132-
/// The `title` keyword.
133-
///
134-
/// See [JSON Schema Validation 9.1. "title" and "description"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.1).
135-
#[serde(skip_serializing_if = "Option::is_none")]
136-
title: Option<String>,
137105
/// The `description` keyword.
138106
///
139107
/// See [JSON Schema Validation 9.1. "title" and "description"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.1).
@@ -144,42 +112,15 @@ struct Metadata {
144112
/// See [JSON Schema Validation 9.2. "default"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.2).
145113
#[serde(skip_serializing_if = "Option::is_none", deserialize_with = "allow_null")]
146114
default: Option<Value>,
147-
/// The `deprecated` keyword.
148-
///
149-
/// See [JSON Schema Validation 9.3. "deprecated"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.3).
150-
#[serde(skip_serializing_if = "is_false")]
151-
deprecated: bool,
152-
/// The `readOnly` keyword.
153-
///
154-
/// See [JSON Schema Validation 9.4. "readOnly" and "writeOnly"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.4).
155-
#[serde(skip_serializing_if = "is_false")]
156-
read_only: bool,
157-
/// The `writeOnly` keyword.
158-
///
159-
/// See [JSON Schema Validation 9.4. "readOnly" and "writeOnly"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.4).
160-
#[serde(skip_serializing_if = "is_false")]
161-
write_only: bool,
162-
/// The `examples` keyword.
163-
///
164-
/// See [JSON Schema Validation 9.5. "examples"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-9.5).
165-
#[serde(skip_serializing_if = "Vec::is_empty")]
166-
examples: Vec<Value>,
167-
}
168-
169-
#[allow(clippy::trivially_copy_pass_by_ref)]
170-
fn is_false(b: &bool) -> bool {
171-
!b
115+
/// Arbitrary data.
116+
#[serde(flatten)]
117+
other: Value,
172118
}
173119

174120
/// Properties of a [`SchemaObject`] which define validation assertions in terms of other schemas.
175121
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
176122
#[serde(rename_all = "camelCase", default)]
177123
struct SubschemaValidation {
178-
/// The `allOf` keyword.
179-
///
180-
/// See [JSON Schema 9.2.1.1. "allOf"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-9.2.1.1).
181-
#[serde(skip_serializing_if = "Option::is_none")]
182-
all_of: Option<Vec<Schema>>,
183124
/// The `anyOf` keyword.
184125
///
185126
/// See [JSON Schema 9.2.1.2. "anyOf"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-9.2.1.2).
@@ -190,78 +131,9 @@ struct SubschemaValidation {
190131
/// See [JSON Schema 9.2.1.3. "oneOf"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-9.2.1.3).
191132
#[serde(skip_serializing_if = "Option::is_none")]
192133
one_of: Option<Vec<Schema>>,
193-
/// The `not` keyword.
194-
///
195-
/// See [JSON Schema 9.2.1.4. "not"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-9.2.1.4).
196-
#[serde(skip_serializing_if = "Option::is_none")]
197-
not: Option<Box<Schema>>,
198-
/// The `if` keyword.
199-
///
200-
/// See [JSON Schema 9.2.2.1. "if"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-9.2.2.1).
201-
#[serde(rename = "if", skip_serializing_if = "Option::is_none")]
202-
if_schema: Option<Box<Schema>>,
203-
/// The `then` keyword.
204-
///
205-
/// See [JSON Schema 9.2.2.2. "then"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-9.2.2.2).
206-
#[serde(rename = "then", skip_serializing_if = "Option::is_none")]
207-
then_schema: Option<Box<Schema>>,
208-
/// The `else` keyword.
209-
///
210-
/// See [JSON Schema 9.2.2.3. "else"](https://tools.ietf.org/html/draft-handrews-json-schema-02#section-9.2.2.3).
211-
#[serde(rename = "else", skip_serializing_if = "Option::is_none")]
212-
else_schema: Option<Box<Schema>>,
213-
}
214-
215-
/// Properties of a [`SchemaObject`] which define validation assertions for numbers.
216-
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
217-
#[serde(rename_all = "camelCase", default)]
218-
struct NumberValidation {
219-
/// The `multipleOf` keyword.
220-
///
221-
/// See [JSON Schema Validation 6.2.1. "multipleOf"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.1).
222-
#[serde(skip_serializing_if = "Option::is_none")]
223-
multiple_of: Option<f64>,
224-
/// The `maximum` keyword.
225-
///
226-
/// See [JSON Schema Validation 6.2.2. "maximum"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.2).
227-
#[serde(skip_serializing_if = "Option::is_none")]
228-
maximum: Option<f64>,
229-
/// The `exclusiveMaximum` keyword.
230-
///
231-
/// See [JSON Schema Validation 6.2.3. "exclusiveMaximum"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.3).
232-
#[serde(skip_serializing_if = "Option::is_none")]
233-
exclusive_maximum: Option<f64>,
234-
/// The `minimum` keyword.
235-
///
236-
/// See [JSON Schema Validation 6.2.4. "minimum"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.4).
237-
#[serde(skip_serializing_if = "Option::is_none")]
238-
minimum: Option<f64>,
239-
/// The `exclusiveMinimum` keyword.
240-
///
241-
/// See [JSON Schema Validation 6.2.5. "exclusiveMinimum"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.2.5).
242-
#[serde(skip_serializing_if = "Option::is_none")]
243-
exclusive_minimum: Option<f64>,
244-
}
245-
246-
/// Properties of a [`SchemaObject`] which define validation assertions for strings.
247-
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
248-
#[serde(rename_all = "camelCase", default)]
249-
struct StringValidation {
250-
/// The `maxLength` keyword.
251-
///
252-
/// See [JSON Schema Validation 6.3.1. "maxLength"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.3.1).
253-
#[serde(skip_serializing_if = "Option::is_none")]
254-
max_length: Option<u32>,
255-
/// The `minLength` keyword.
256-
///
257-
/// See [JSON Schema Validation 6.3.2. "minLength"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.3.2).
258-
#[serde(skip_serializing_if = "Option::is_none")]
259-
min_length: Option<u32>,
260-
/// The `pattern` keyword.
261-
///
262-
/// See [JSON Schema Validation 6.3.3. "pattern"](https://tools.ietf.org/html/draft-handrews-json-schema-validation-02#section-6.3.3).
263-
#[serde(skip_serializing_if = "Option::is_none")]
264-
pattern: Option<String>,
134+
/// Arbitrary data.
135+
#[serde(flatten)]
136+
other: Value,
265137
}
266138

267139
/// Properties of a [`SchemaObject`] which define validation assertions for arrays.
@@ -375,18 +247,6 @@ enum SingleOrVec<T> {
375247
Vec(Vec<T>),
376248
}
377249

378-
impl<T> From<T> for SingleOrVec<T> {
379-
fn from(single: T) -> Self {
380-
SingleOrVec::Single(Box::new(single))
381-
}
382-
}
383-
384-
impl<T> From<Vec<T>> for SingleOrVec<T> {
385-
fn from(vec: Vec<T>) -> Self {
386-
SingleOrVec::Vec(vec)
387-
}
388-
}
389-
390250
impl Transform for StructuralSchemaRewriter {
391251
fn transform(&mut self, transform_schema: &mut schemars::Schema) {
392252
schemars::transform::transform_subschemas(self, transform_schema);

0 commit comments

Comments
 (0)