quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

feat: Add support for unevaluatedProperties in JSON Schema

Open haya14busa opened this issue 7 months ago • 0 comments

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.ts to handle unevaluatedProperties when additionalProperties is undefined
  • Added test cases with JSON Schema using unevaluatedProperties

Test

Added test schema and data files:

  • test/inputs/schema/unevaluated-properties.schema
  • test/inputs/schema/unevaluated-properties.1.json
  • test/inputs/schema/unevaluated-properties.2.json

The tests can be run with:

QUICKTEST=true FIXTURE=schema-golang npm test

Example

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"`
}

haya14busa avatar Jul 05 '25 13:07 haya14busa