diff --git a/packages/quicktype-core/src/input/JSONSchemaInput.ts b/packages/quicktype-core/src/input/JSONSchemaInput.ts index 6907c0e48..0ce315291 100644 --- a/packages/quicktype-core/src/input/JSONSchemaInput.ts +++ b/packages/quicktype-core/src/input/JSONSchemaInput.ts @@ -1108,6 +1108,11 @@ async function addTypesInSchema( ) { additionalProperties = schema.patternProperties[".*"]; } + + // Handle unevaluatedProperties if additionalProperties is not defined + if (additionalProperties === undefined && schema.unevaluatedProperties !== undefined) { + additionalProperties = schema.unevaluatedProperties; + } const objectAttributes = combineTypeAttributes( "union", diff --git a/test/inputs/schema/unevaluated-properties.1.json b/test/inputs/schema/unevaluated-properties.1.json new file mode 100644 index 000000000..a8e22fbc6 --- /dev/null +++ b/test/inputs/schema/unevaluated-properties.1.json @@ -0,0 +1,14 @@ +{ + "config": { + "name": "test-config", + "settings": { + "option1": [ + {"key": "foo", "value": "bar"}, + {"key": "baz", "value": "qux"} + ], + "option2": [ + {"key": "hello", "value": "world"} + ] + } + } +} \ No newline at end of file diff --git a/test/inputs/schema/unevaluated-properties.2.json b/test/inputs/schema/unevaluated-properties.2.json new file mode 100644 index 000000000..a739f3e56 --- /dev/null +++ b/test/inputs/schema/unevaluated-properties.2.json @@ -0,0 +1,19 @@ +{ + "config": { + "name": "multiple-versions", + "settings": { + "v1.0.0": [ + {"key": "checksum1", "value": "abc123"}, + {"key": "checksum2", "value": "def456"} + ], + "v1.1.0": [ + {"key": "checksum1", "value": "ghi789"} + ], + "latest": [ + {"key": "checksum1", "value": "jkl012"}, + {"key": "checksum2", "value": "mno345"}, + {"key": "checksum3", "value": "pqr678"} + ] + } + } +} \ No newline at end of file diff --git a/test/inputs/schema/unevaluated-properties.schema b/test/inputs/schema/unevaluated-properties.schema new file mode 100644 index 000000000..1e1382a19 --- /dev/null +++ b/test/inputs/schema/unevaluated-properties.schema @@ -0,0 +1,46 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "unevaluated-properties.schema", + "title": "Test unevaluatedProperties support", + "type": "object", + "properties": { + "config": { + "$ref": "#/$defs/Config" + } + }, + "$defs": { + "Config": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "settings": { + "$ref": "#/$defs/Settings" + } + } + }, + "Settings": { + "type": "object", + "properties": {}, + "unevaluatedProperties": { + "type": "array", + "items": { + "$ref": "#/$defs/Item" + } + } + }, + "Item": { + "type": "object", + "properties": { + "key": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "required": ["key", "value"] + } + } +} \ No newline at end of file