我正在尝试验证以下 JSON
{
"domain": "example.com",
"docker": {
"services": {
"app": {
"image": "nginxdemos/hello:latest",
"expose_port": 80,
"volumes": [
"./:/test"
]
},
"db": {
"image": "mariadb:10.5"
}
}
}
}
我想确保expose_port
里面的services
孩子只能定义一次。所以添加"expose_port": 1234
到“db”应该使 JSON 无效。
到目前为止,这是我的架构:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://saitho.me/project-configuration.schema.json",
"title": "Project Configuration",
"description": "Project configuration file",
"type": "object",
"definitions": {
"docker-service": {
"properties": {
"image": {
"description": "Name of Docker image",
"type": "string"
},
"volumes": {
"description": "Docker volumes to be mounted",
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
}
},
"required": [ "image" ]
}
},
"properties": {
"domain": {
"description": "The domain from which the app can be reached",
"type": "string"
},
"docker": {
"description": "Configuration for Docker containers that will be deployed",
"type": "object",
"properties": {
"services": {
"description": "List of Docker services to be started",
"type": "object",
"patternProperties": {
".*": {
"$ref": "#/definitions/docker-service",
"oneOf": [
{
"properties": {
"expose_port": {
"description": "Port that receives web traffic (e.g. 80, 3000, 8080 for most applications). Only one in this file!",
"type": "integer"
}
}
}
],
"type": "object"
}
},
"additionalProperties": false
}
},
"required": [ "services" ]
}
},
"required": [ "domain" ]
}
到目前为止,我已经尝试将 allOf 和 oneOf 结合起来,但这似乎只适用于当前的孩子,而不是看兄弟姐妹。有谁知道我的问题的解决方案?:)
谢谢!