feat: Add support for unevaluatedProperties in JSON Schema by haya14busa · Pull Request #2800 · glideapps/quicktype
Summary
This PR adds support for the unevaluatedProperties keyword from JSON Schema draft 2019-09/2020-12.
Problem
When using JSON Schema with unevaluatedProperties, quicktype was generating incorrect types. For example, in Go, it would generate map[string]interface{} instead of properly typed maps like map[string][]SomeType.
Solution
When additionalProperties is not defined in a schema, quicktype now falls back to using unevaluatedProperties to determine the type of additional properties in an object.
Changes
- Modified
JSONSchemaInput.tsto handleunevaluatedPropertieswhenadditionalPropertiesis undefined - Added test cases with JSON Schema using
unevaluatedProperties
Test
Added test schema and data files:
test/inputs/schema/unevaluated-properties.schematest/inputs/schema/unevaluated-properties.1.jsontest/inputs/schema/unevaluated-properties.2.json
The tests can be run with:
QUICKTEST=true FIXTURE=schema-golang npm testExample
Before this fix:
type ChecksumConfig struct { EmbeddedChecksums map[string]interface{} `json:"embedded_checksums,omitempty"` }
After this fix:
type ChecksumConfig struct { EmbeddedChecksums map[string][]EmbeddedChecksum `json:"embedded_checksums,omitempty"` }