valico/json_schema/keywords/
property_names.rs1use serde_json::Value;
2
3use super::super::helpers;
4use super::super::schema;
5use super::super::validators;
6
7#[allow(missing_copy_implementations)]
8pub struct PropertyNames;
9impl super::Keyword for PropertyNames {
10 fn compile(&self, def: &Value, ctx: &schema::WalkContext<'_>) -> super::KeywordResult {
11 let property_names = keyword_key_exists!(def, "propertyNames");
12
13 if property_names.is_object() || property_names.is_boolean() {
14 Ok(Some(Box::new(validators::PropertyNames {
15 url: helpers::alter_fragment_path(
16 ctx.url.clone(),
17 [ctx.escaped_fragment().as_ref(), "propertyNames"].join("/"),
18 ),
19 })))
20 } else {
21 Err(schema::SchemaError::Malformed {
22 path: ctx.fragment.join("/"),
23 detail: "The value of propertyNames MUST be an object or a boolean".to_string(),
24 })
25 }
26 }
27}