Skip to content

Commit 267de29

Browse files
fix: Fix the JSON schema of JsonConfigOverrides
1 parent bf80520 commit 267de29

2 files changed

Lines changed: 79 additions & 2 deletions

File tree

crates/stackable-operator/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ All notable changes to this project will be documented in this file.
77
### Fixed
88

99
- [v2] Don't require the `attributed_string_type` macro caller to have `std::str::FromStr` in scope ([#1244]).
10+
- [v2] Fix the JSON schema of `JsonConfigOverrides` ([#1245]).
1011

1112
[#1244]: https://github.com/stackabletech/operator-rs/pull/1244
13+
[#1245]: https://github.com/stackabletech/operator-rs/pull/1245
1214

1315
## [0.113.2] - 2026-07-07
1416

crates/stackable-operator/src/v2/config_overrides.rs

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use serde_json::json;
99
use tracing::warn;
1010

1111
use crate::{
12-
config::merge::Merge, k8s_openapi::DeepMerge, schemars, utils::crds::raw_object_schema,
12+
config::merge::Merge,
13+
k8s_openapi::DeepMerge,
14+
schemars,
15+
utils::crds::{raw_object_list_schema, raw_object_schema},
1316
};
1417

1518
// Variant of [`crate::config_overrides::KeyValueConfigOverrides`] that implements
@@ -93,7 +96,7 @@ pub enum JsonConfigOverrides {
9396
/// or
9497
///
9598
/// `- {"op": "add", "path": "/0/happy", "value": true}`
96-
#[schemars(schema_with = "raw_object_schema")]
99+
#[schemars(schema_with = "raw_object_list_schema")]
97100
JsonPatch(json_patch::Patch),
98101

99102
/// Override the entire config file with the specified JSON value.
@@ -251,11 +254,83 @@ impl Merge for JsonOrKeyValueConfigOverrides {
251254

252255
#[cfg(test)]
253256
mod tests {
257+
use indoc::indoc;
258+
use kube::core::schema::StructuralSchemaRewriter;
259+
use schemars::generate::SchemaSettings;
254260
use serde_json::json;
255261

256262
use super::*;
257263
use crate::config::merge;
258264

265+
#[test]
266+
fn test_json_config_overrides_schema() {
267+
let schema = SchemaSettings::default()
268+
.with_transform(StructuralSchemaRewriter)
269+
.into_generator()
270+
.into_root_schema_for::<JsonConfigOverrides>();
271+
272+
assert_eq!(
273+
json!({
274+
"$schema": "https://json-schema.org/draft/2020-12/schema",
275+
"description": "ConfigOverrides that can be applied to a JSON file.",
276+
"oneOf": [
277+
{
278+
"required": [
279+
"jsonMergePatch"
280+
]
281+
},
282+
{
283+
"required": [
284+
"jsonPatch"
285+
]
286+
},
287+
{
288+
"required": [
289+
"userProvided"
290+
]
291+
}
292+
],
293+
"properties": {
294+
"jsonMergePatch": {
295+
"description": indoc!("
296+
Can be set to arbitrary YAML content, which is converted to JSON and used as
297+
[RFC 7396](https://datatracker.ietf.org/doc/html/rfc7396) JSON merge patch."),
298+
"type": "object",
299+
"x-kubernetes-preserve-unknown-fields": true
300+
},
301+
"jsonPatch": {
302+
"description": indoc!(r#"
303+
An [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patch.
304+
305+
Can be used when more flexibility is needed, e.g. to only modify elements
306+
in a list based on a condition.
307+
308+
A patch looks something like
309+
310+
`- {"op": "test", "path": "/0/name", "value": "Andrew"}`
311+
312+
or
313+
314+
`- {"op": "add", "path": "/0/happy", "value": true}`"#),
315+
"items": {
316+
"type": "object",
317+
"x-kubernetes-preserve-unknown-fields": true
318+
},
319+
"type": "array"
320+
},
321+
"userProvided": {
322+
"description": "Override the entire config file with the specified JSON value.",
323+
"type": "object",
324+
"x-kubernetes-preserve-unknown-fields": true
325+
}
326+
},
327+
"title": "JsonConfigOverrides",
328+
"type": "object"
329+
}),
330+
schema
331+
);
332+
}
333+
259334
#[test]
260335
fn test_json_config_overrides_apply() {
261336
let base = json!({

0 commit comments

Comments
 (0)