I'm trying to define a referenced schema for use as a Cassandra CQL map type with text fields. Specifically, I want to map URIs to strings.
Right now I have:
"scope": {
"type": "object",
"properties": {
"uri": {
"type": "string",
"format": "uri"
},
"permission": {
"type": "string",
"enum": ["read_only", "read_write", "write_only"]
}
},
"required": ["uri", "permission"],
"additionalProperties": false
}
This is good for data like
{"uri":"http://example.com",
"permission": "read_only"}
But I want a schema for data like
{"http://example.com": "read_only"}
http://spacetelescope.github.io/understanding-json-schema/reference/object.html has a solution:
{
"type": "object",
"patternProperties": {
"^S_": { "type": "string" },
"^I_": { "type": "integer" }
}
}
The problem with this is that I'd have to define a built-in format with a regular expression. Looking at examples of regexs for URIs makes me want to avoid this.
Since the number of URIs I have are limited, mapping enum to enum would also be a solution. Is that doable?
If I can be permitted to answer my own question, I believe the solution is to use a PatternProperties definition for the key, with a very specific regex. The value can be any type supported by json-schema, including another regex. In my case, it's an enum.
So the definition looks something like-
"patternProperties": {
"^https:\/\/www.example.com\/auth\/\\w+$": {
"type": "string",
"enum": ["read_only", "read_write", "write_only"]
}
},
"additionalProperties": false
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.