Skip to content

Commit 8924796

Browse files
committed
custom json_schema for crds
1 parent b6fe637 commit 8924796

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

src/types.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Common types shared across CRDs
22
3-
use std::collections::HashMap;
3+
use std::{borrow::Cow, collections::HashMap};
44

5-
use schemars::JsonSchema;
5+
use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};
66
use serde::{Deserialize, Serialize};
77

88
pub use self::{replica::*, restore::*};
@@ -52,7 +52,7 @@ pub struct SecretKeySelector {
5252
pub key: String,
5353
}
5454

55-
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
55+
#[derive(Debug, Clone, Deserialize, Serialize)]
5656
#[serde(untagged)]
5757
pub enum HeaderValue {
5858
Plain(String),
@@ -61,3 +61,36 @@ pub enum HeaderValue {
6161
secret_key_ref: SecretKeySelector,
6262
},
6363
}
64+
65+
impl JsonSchema for HeaderValue {
66+
fn inline_schema() -> bool {
67+
true
68+
}
69+
70+
fn schema_name() -> Cow<'static, str> {
71+
"HeaderValue".into()
72+
}
73+
74+
fn json_schema(_generator: &mut SchemaGenerator) -> Schema {
75+
// Kubernetes structural schemas forbid `type` inside `anyOf` items,
76+
// so we emit the branches without top-level `type`.
77+
json_schema!({
78+
"anyOf": [
79+
{},
80+
{
81+
"required": ["secretKeyRef"],
82+
"properties": {
83+
"secretKeyRef": {
84+
"type": "object",
85+
"properties": {
86+
"name": { "type": "string" },
87+
"key": { "type": "string" }
88+
},
89+
"required": ["name", "key"]
90+
}
91+
}
92+
}
93+
]
94+
})
95+
}
96+
}

0 commit comments

Comments
 (0)