fix(cli): honor --src-lang schema for directory sources - #3015
Open
schani wants to merge 2 commits into
Open
Conversation
samplesFromDirectory classified files in a --src directory purely by extension (.json -> JSON sample, .schema -> JSON Schema), ignoring options.srcLang entirely. Passing --src-lang schema --src <dir> with schema files named *.json produced structs full of schema metadata ($schema, $id, title, properties) instead of the modeled type, while passing the same files individually with --src-lang schema worked correctly. Thread srcLang into samplesFromDirectory and treat .json files as schema sources when srcLang is "schema", matching the branching typeSourcesForURIs already does for non-directory sources. Added test/unit/schema-directory-src-lang.test.ts, which compares output from a directory of schema files against the equivalent per-file invocation and fails on unfixed code. 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 --lang <lang> --src-lang schema --src <directory>produced invalidoutput when the directory contained schema files named with a
.jsonextension: the generated types were full of schema-document metadata
(
$schema,$id,title,properties,required) instead of the type theschema actually describes. Passing the exact same files individually with
--src-lang schema --src file1.json --src file2.json ...worked correctly.Root cause
samplesFromDirectoryinsrc/index.tsclassifies each file in a--srcdirectory purely by file extension (
.json-> JSON sample,.schema-> JSONSchema), and never consults
options.srcLang. The non-directory code path(
typeSourcesForURIs) already branches correctly onoptions.srcLang("json" vs "schema") regardless of extension, but that branching was never
threaded through to the directory-scanning path, so a directory of
--src-lang schemafiles named*.jsonwas always parsed as JSON samplesrather than JSON Schema documents.
Fix
Thread
srcLangfromoptionsintosamplesFromDirectory. WhensrcLang === "schema",.jsonfiles found in the directory are now treatedas schema sources (
kind: "schema") instead of JSON sample sources, matchingthe behavior of the per-file invocation path.
.schema,.url, and GraphQLhandling, plus the default
--src-lang jsondirectory behavior, areunchanged.
Test coverage
Added
test/unit/schema-directory-src-lang.test.ts: writes threecross-referencing (
$ref) JSON Schema documents (location.json,person.json,product.json) to a temp directory, generates Rust from thedirectory with
--src-lang schema, generates Rust from the same three filespassed individually with
--src-lang schema, and asserts the two outputs areidentical. This test fails on unfixed
src/index.ts(directory outputcontains schema-metadata structs) and passes with the fix.
This is CLI-level directory-scanning logic in
src/index.ts, notper-language generated-output shape, so it isn't expressible through the
test/inputs/{json,schema}/fixture harness (which drives quicktype withindividual schema/JSON files, not a
--src <directory>invocation with achosen
--src-lang); a unit test is the appropriate mechanism here, matchingthe existing precedent of
test/unit/windows-schema-paths.test.tsfor asimilar directory-handling issue.
Verification
npm run buildpasses.npm run test:unit— all 164 unit tests pass, including the new one.rustfixture suite locally (QUICKTEST=true FIXTURE=rust script/test, 57/57 tests) to confirm no regressions in Rust codegen;remaining language fixtures are left to CI.
Fixes #2634
🤖 Generated with Claude Code