Skip to content

fix(cli): honor --src-lang schema for directory sources - #3015

Open
schani wants to merge 2 commits into
masterfrom
agent/fix-issue-2634
Open

fix(cli): honor --src-lang schema for directory sources#3015
schani wants to merge 2 commits into
masterfrom
agent/fix-issue-2634

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Bug

quicktype --lang <lang> --src-lang schema --src <directory> produced invalid
output when the directory contained schema files named with a .json
extension: the generated types were full of schema-document metadata
($schema, $id, title, properties, required) instead of the type the
schema actually describes. Passing the exact same files individually with
--src-lang schema --src file1.json --src file2.json ... worked correctly.

Root cause

samplesFromDirectory in src/index.ts classifies each file in a --src
directory purely by file extension (.json -> JSON sample, .schema -> JSON
Schema), and never consults options.srcLang. The non-directory code path
(typeSourcesForURIs) already branches correctly on options.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 schema files named *.json was always parsed as JSON samples
rather than JSON Schema documents.

Fix

Thread srcLang from options into samplesFromDirectory. When
srcLang === "schema", .json files found in the directory are now treated
as schema sources (kind: "schema") instead of JSON sample sources, matching
the behavior of the per-file invocation path. .schema, .url, and GraphQL
handling, plus the default --src-lang json directory behavior, are
unchanged.

Test coverage

Added test/unit/schema-directory-src-lang.test.ts: writes three
cross-referencing ($ref) JSON Schema documents (location.json,
person.json, product.json) to a temp directory, generates Rust from the
directory with --src-lang schema, generates Rust from the same three files
passed individually with --src-lang schema, and asserts the two outputs are
identical. This test fails on unfixed src/index.ts (directory output
contains schema-metadata structs) and passes with the fix.

This is CLI-level directory-scanning logic in src/index.ts, not
per-language generated-output shape, so it isn't expressible through the
test/inputs/{json,schema}/ fixture harness (which drives quicktype with
individual schema/JSON files, not a --src <directory> invocation with a
chosen --src-lang); a unit test is the appropriate mechanism here, matching
the existing precedent of test/unit/windows-schema-paths.test.ts for a
similar directory-handling issue.

Verification

  • npm run build passes.
  • npm run test:unit — all 164 unit tests pass, including the new one.
  • Manually re-ran the original repro (`--lang rust --src-lang schema --src ` vs. `--src-lang schema --src file1 --src file2 --src file3` individually) — outputs are now identical and correctly reflect the schemas' modeled types (`Location { latitude, longitude }`, etc.) with no schema-metadata fields.
  • Ran the full rust fixture 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

schani and others added 2 commits July 20, 2026 17:42
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>
@github-actions

Copy link
Copy Markdown

No generated-output differences

✅ Generated outputs are unchanged between the PR base and head revisions.

@github-actions

Copy link
Copy Markdown

No generated-output differences

✅ Generated outputs are unchanged between the PR base and head revisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Generating from a folder of schema files gives invalid results

1 participant