Skip to content

fix(cli): honor --src-lang schema for directory inputs - #3018

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

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

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Bug

quicktype --src-lang schema <directory>/ -o Models.ts ignored --src-lang
entirely: every .json file inside the directory was parsed as a JSON
data 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 the
directory-scanning code path.

Root cause

In src/index.ts, single-file/URL inputs go through typeSourcesForURIs(),
which correctly switches on options.srcLang to decide whether a source is
JSON data or a JSON Schema document. Directory inputs, however, go through
getSources() -> samplesFromDirectory(), which classified every file
purely by its extension (.json/.url -> JSON data, .schema -> JSON
Schema, .gqlschema/.graphql -> GraphQL) without ever consulting
options.srcLang. As a result --src-lang schema had no effect on .json
files found inside a directory.

Fix

samplesFromDirectory() now takes the source language as a parameter. When
it is "schema", .json/.url files inside the directory are constructed
as kind: "schema" sources (matching what typeSourcesForURIs() already
does for explicit file arguments) instead of kind: "json" data samples.
Behavior for .schema, .gqlschema, .graphql files, and the default
(json) source language is unchanged.

Test coverage

Added test/unit/directory-schema-input.test.ts, which drives the actual
CLI entry point (main() in src/index.ts) against a temp directory
containing two .json JSON Schema files with --src-lang schema, and
asserts 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.ts language-fixture harness) because
this bug lives specifically in CLI argument/directory-scanning logic
(getSources/samplesFromDirectory), a code path the fixture harness does
not exercise since it drives the Input/InputData API directly with a
single source.

Verification

  • npm run build passes.
  • npm run test:unit: all 164 unit tests pass, including the new regression
    test.
  • Manually re-ran the issue's exact repro (--src-lang schema schemas/ -o Models.ts against a directory containing the issue's alert_schema.json)
    and confirmed the output now correctly reflects the schema's properties
    (alert_type_id, issue_id, options) instead of the schema document's
    own keys.
  • Ran QUICKTEST=true FIXTURE=schema-typescript script/test (67 tests) as a
    sanity check for schema-handling regressions elsewhere; all passed.
  • CI will run the full fixture matrix across all target languages.

Fixes #1910

🤖 Generated with Claude Code

schani and others added 2 commits July 20, 2026 17:47
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>
@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: allow muliple json schema files as input

1 participant