自定义Policy的properties数组无法保留历史配置值问题
解决MuleSoft自定义Flex Policy数组配置不回显问题
核心问题定位
你的JSON Schema中存在一个明显错误:username字段被定义为string类型,却设置了数组类型的默认值[],这会导致API Manager在加载已保存的配置时解析失败,无法正确回显数组内的用户数据。
修正后的JSON Schema
将username的default属性移除(或设置为合理的字符串默认值,比如空字符串""),修正后的Schema如下:
{ "title": "ACME Custom Basic Auth Policy", "description": "Basic Authentication policy which enforces security according with custom consumer credentials", "type": "object", "properties": { "users": { "title": "users", "type": "array", "items": { "type": "object", "required": [ "username", "password" ], "properties": { "username": { "title": "User Name", "type": "string" // 移除错误的default: [],或改为 "default": "" }, "password": { "title": "User Password", "type": "string", "@context": { "@characteristics": [ "security:sensitive" ] } } } }, "minItems": 1 } }, "@context": { "@vocab": "anypoint://vocabulary/policy.yaml#", "security": "anypoint://vocabulary/policy.yaml#" }, "$id": "allow-dynamic-resources", "$schema": "https://json-schema.org/draft/2019-09/schema" }
额外验证要点
- 确认数组类型字段的
items定义完全符合JSON Schema规范,嵌套对象的类型和约束无冲突 - 敏感字段(如
password)的security:sensitive特性配置正确,该特性仅会对值进行掩码处理,不会影响配置的保存与回显逻辑
内容的提问来源于stack exchange,提问作者mhery
相关产品推荐
相关产品推荐

