fix(typescript): emit top-level aliases for bare map schemas#2991
Merged
Conversation
Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
Co-Authored-By: Claude <noreply@anthropic.com>
The bare empty-object.1.fail.json (a non-object array) runs for every language, but the Elixir emitter renders a bare top-level map as a Jason.decode!/encode! pass-through with no shape validation, so it accepts the array and round-trips it instead of exiting nonzero. This is the same permissiveness class as go-schema-pattern-properties, which Elixir already skips. Skip empty-object.schema for Elixir; the positive and negative cases still run for all other schema languages (verified locally with schema-javascript and schema-golang). Co-Authored-By: Claude <noreply@anthropic.com>
#2991) The Haskell fixture driver encodes a failed decode's Maybe result as the JSON literal null and exits 0, so expected-failure schema samples can never be detected — already documented and worked around for nested-intersection-union.schema, prefix-items.schema, and direct-union.schema. The new empty-object.schema fixture (added earlier on this branch) hits the same limitation; add it to the same skip group. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
Resolve additive skipSchema conflicts in test/languages.ts by keeping both the empty-object.schema skips from this branch and the integer-before-number.schema skips from master. Co-Authored-By: Claude <noreply@anthropic.com>
Generated-output differences34 files differ — 6 modified, 28 new, 0 deleted |
Generated-output differences39 files differ — 10 modified, 29 new, 0 deleted |
# Conflicts: # packages/quicktype-core/src/language/TypeScriptFlow/TypeScriptFlowBaseRenderer.ts
Generated-output differences31 files differ — 2 modified, 29 new, 0 deleted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Reported in #2642: converting an empty-object JSON Schema (
{"type":"object","properties":{}}) to TypeScript or Flow produced no usable public type declaration.--just-types: empty output.Root cause
An empty-object schema is represented as a top-level
MapType.TypeScriptFlowBaseRenderer.emitTypesemitted aliases only for primitive and array top levels, while named classes, enums, and unions were handled separately. A bare map therefore fell through both paths.The fix
emitTypesnow reusesnamedTypeToNameForTopLevel, the renderer's existing naming decision. If a nested named type claims the top-level name, no alias is emitted; otherwise the top level gets a declaration. This:export type EmptySchema = { [key: string]: unknown };(or Flow'smixedequivalent) for the reported case;Test coverage
empty-object.schemawith positive and negative samples for fixture coverage.Verification
npm run buildnpm run lintnpm run test:unit(233 passed after conflict resolution)schema-typescriptempty-object fixture passedflowis not installed; Flow rendering is covered by the unit test and CIFixes #2642.