Skip to content

fix(cli): infer JSON Schema target language from a .json output extension - #3010

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

fix(cli): infer JSON Schema target language from a .json output extension#3010
schani wants to merge 2 commits into
masterfrom
agent/fix-issue-1579

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Bug

quicktype's own --help Examples section documents:

$ quicktype -o schema.json https://blockchain.info/latestblock
$ quicktype -o bitcoin.ts --src-lang schema schema.json

but running the first command fails with:

Error: Unknown output language json.

Root cause

inferLang() in src/index.ts derives the target language from the output
file's extension by taking path.extname(options.out) verbatim (json for
schema.json) and using that as the language name. That candidate is then
checked against each registered language's names array via
isLanguageName().

Every language's extension field is itself one of the entries in its own
names array (e.g. C# has extension: "cs" and names: ["cs", "csharp"]),
except JSON Schema, which is registered with extension: "schema" but
names: ["schema", "json-schema"] — no language is registered under json.
So -o schema.json resolves to the candidate "json", which matches no
language, and DriverUnknownOutputLanguage fires.

Fix

inferLang() now maps a .json output extension to the "schema" language
name, matching the behavior the help text documents. All other extension
inference (.ts, .py, .cs, etc.) is unchanged, and explicit
--lang json / --src-lang json behavior is unaffected (source-language and
target-language name spaces are separate).

Test coverage

Added test/unit/cli-output-language-inference.test.ts, which:

  • Confirms -o schema.json input.json (no explicit --lang) resolves to the
    JSON Schema language — this is a regression test that failed before the fix.
  • Confirms --src-lang json (the JSON source format) still works unaffected.
  • Confirms explicit --lang json still produces the existing
    "Unknown output language json" error (the fix only affects extension
    inference, not the language namespace).

A unit test was used rather than a generated-output fixture test because this
bug is in CLI argument/extension parsing (inferLang), not in a language's
generated code, per the repo's testing conventions (fixtures are the
required vehicle for changes affecting generated output; unit tests cover
what fixtures can't express, including CLI-level behavior).

Verification

  • npm run build passes.
  • npx vitest run test/unit — all 166 unit tests pass (no regressions).
  • Manually reran the exact repro from the issue:
    • node dist/index.js -o schema.json latestblock.json now exits 0 and
      writes valid JSON Schema to schema.json (previously errored).
    • The full documented two-step example (-o schema.json ... then
      -o bitcoin.ts --src-lang schema schema.json) now works end-to-end.
    • Spot-checked other output extensions (.ts, .py) are unaffected.
  • CI will additionally run the full fixture suite across languages.

Fixes #1579

🤖 Generated with Claude Code

schani and others added 2 commits July 20, 2026 17:27
…sion (#1579)

The CLI's own help text documents `quicktype -o schema.json <input>` as the
way to generate JSON Schema, but inferLang() returned the raw output
extension ("json") as the target language name, and no language is
registered under that name (JSON Schema is registered as "schema" /
"json-schema"), so the command failed with "Unknown output language json."

Map a .json output extension to the "schema" language in inferLang(), since
JSON Schema is the one language whose registered extension ("schema")
doesn't match a name commonly used for its output files. Other extension
inference and explicit --lang/--src-lang json handling are unchanged.

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.

Error: Unknown output language json.

1 participant