Function validate_property

Source
pub fn validate_property(
    s: &mut Schema,
    property_index: usize,
    rule: impl Into<Rule>,
) -> Result<(), Error>
Expand description

Validate property mutates property under property_index of the schema with the provided set of validation rules.

use schemars::JsonSchema;
use kube::core::{Rule, validate_property};

#[derive(JsonSchema)]
struct MyStruct {
    field: Option<String>,
}

let gen = &mut schemars::gen::SchemaSettings::openapi3().into_generator();
let mut schema = MyStruct::json_schema(gen);
let rule = Rule::new("self != oldSelf");
validate_property(&mut schema, 0, rule)?;
assert_eq!(
    serde_json::to_string(&schema).unwrap(),
    r#"{"type":"object","properties":{"field":{"type":"string","nullable":true,"x-kubernetes-validations":[{"rule":"self != oldSelf"}]}}}"#
);