fix(cli): honor --src-lang schema for directory inputs - #3018
Open
schani wants to merge 2 commits into
Open
Conversation
Directory input scanning classified every .json file as a JSON data sample regardless of --src-lang, ignoring the flag entirely (unlike single-file input, which already respected it via typeSourcesForURIs). samplesFromDirectory now takes the source language and treats .json files as schema sources when --src-lang schema is given. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
No generated-output differences✅ Generated outputs are unchanged between the PR base and head revisions. |
No generated-output differences✅ Generated outputs are unchanged between the PR base and head revisions. |
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.
Bug
quicktype --src-lang schema <directory>/ -o Models.tsignored--src-langentirely: every
.jsonfile inside the directory was parsed as a JSONdata sample (interfaces mirroring the schema document's own keys like
type/required/properties) instead of as a JSON Schema document.Passing the exact same file directly (
--src-lang schema schemas/alert_schema.json) worked correctly, so the bug was specific to thedirectory-scanning code path.
Root cause
In
src/index.ts, single-file/URL inputs go throughtypeSourcesForURIs(),which correctly switches on
options.srcLangto decide whether a source isJSON data or a JSON Schema document. Directory inputs, however, go through
getSources()->samplesFromDirectory(), which classified every filepurely by its extension (
.json/.url-> JSON data,.schema-> JSONSchema,
.gqlschema/.graphql-> GraphQL) without ever consultingoptions.srcLang. As a result--src-lang schemahad no effect on.jsonfiles found inside a directory.
Fix
samplesFromDirectory()now takes the source language as a parameter. Whenit is
"schema",.json/.urlfiles inside the directory are constructedas
kind: "schema"sources (matching whattypeSourcesForURIs()alreadydoes for explicit file arguments) instead of
kind: "json"data samples.Behavior for
.schema,.gqlschema,.graphqlfiles, and the default(
json) source language is unchanged.Test coverage
Added
test/unit/directory-schema-input.test.ts, which drives the actualCLI entry point (
main()insrc/index.ts) against a temp directorycontaining two
.jsonJSON Schema files with--src-lang schema, andasserts the generated TypeScript interfaces reflect the schemas' declared
properties rather than the schema documents' own top-level keys. This test
fails on unfixed code and passes after the fix. A CLI-level unit test was
used (rather than the
test/fixtures.tslanguage-fixture harness) becausethis bug lives specifically in CLI argument/directory-scanning logic
(
getSources/samplesFromDirectory), a code path the fixture harness doesnot exercise since it drives the
Input/InputDataAPI directly with asingle source.
Verification
npm run buildpasses.npm run test:unit: all 164 unit tests pass, including the new regressiontest.
--src-lang schema schemas/ -o Models.tsagainst a directory containing the issue'salert_schema.json)and confirmed the output now correctly reflects the schema's properties
(
alert_type_id,issue_id,options) instead of the schema document'sown keys.
QUICKTEST=true FIXTURE=schema-typescript script/test(67 tests) as asanity check for schema-handling regressions elsewhere; all passed.
Fixes #1910
🤖 Generated with Claude Code