Skip to content

Commit af0c9ff

Browse files
committed
feat: Add support for unevaluatedProperties in JSON Schema
Add support for the unevaluatedProperties keyword from JSON Schema draft 2019-09/2020-12. When additionalProperties is not defined, unevaluatedProperties is now used as a fallback to determine the type of additional properties in an object. This fixes issues where objects using unevaluatedProperties would generate incorrect types (e.g., map[string]interface{} instead of properly typed maps in Go).
1 parent 4195020 commit af0c9ff

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

packages/quicktype-core/src/input/JSONSchemaInput.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,11 @@ async function addTypesInSchema(
11081108
) {
11091109
additionalProperties = schema.patternProperties[".*"];
11101110
}
1111+
1112+
// Handle unevaluatedProperties if additionalProperties is not defined
1113+
if (additionalProperties === undefined && schema.unevaluatedProperties !== undefined) {
1114+
additionalProperties = schema.unevaluatedProperties;
1115+
}
11111116

11121117
const objectAttributes = combineTypeAttributes(
11131118
"union",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"config": {
3+
"name": "test-config",
4+
"settings": {
5+
"option1": [
6+
{"key": "foo", "value": "bar"},
7+
{"key": "baz", "value": "qux"}
8+
],
9+
"option2": [
10+
{"key": "hello", "value": "world"}
11+
]
12+
}
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"config": {
3+
"name": "multiple-versions",
4+
"settings": {
5+
"v1.0.0": [
6+
{"key": "checksum1", "value": "abc123"},
7+
{"key": "checksum2", "value": "def456"}
8+
],
9+
"v1.1.0": [
10+
{"key": "checksum1", "value": "ghi789"}
11+
],
12+
"latest": [
13+
{"key": "checksum1", "value": "jkl012"},
14+
{"key": "checksum2", "value": "mno345"},
15+
{"key": "checksum3", "value": "pqr678"}
16+
]
17+
}
18+
}
19+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "unevaluated-properties.schema",
4+
"title": "Test unevaluatedProperties support",
5+
"type": "object",
6+
"properties": {
7+
"config": {
8+
"$ref": "#/$defs/Config"
9+
}
10+
},
11+
"$defs": {
12+
"Config": {
13+
"type": "object",
14+
"properties": {
15+
"name": {
16+
"type": "string"
17+
},
18+
"settings": {
19+
"$ref": "#/$defs/Settings"
20+
}
21+
}
22+
},
23+
"Settings": {
24+
"type": "object",
25+
"properties": {},
26+
"unevaluatedProperties": {
27+
"type": "array",
28+
"items": {
29+
"$ref": "#/$defs/Item"
30+
}
31+
}
32+
},
33+
"Item": {
34+
"type": "object",
35+
"properties": {
36+
"key": {
37+
"type": "string"
38+
},
39+
"value": {
40+
"type": "string"
41+
}
42+
},
43+
"required": ["key", "value"]
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)