fix(cli): infer JSON Schema target language from a .json output extension - #3010
Open
schani wants to merge 2 commits into
Open
fix(cli): infer JSON Schema target language from a .json output extension#3010schani wants to merge 2 commits into
schani wants to merge 2 commits into
Conversation
…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>
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's own
--helpExamples section documents:but running the first command fails with:
Root cause
inferLang()insrc/index.tsderives the target language from the outputfile's extension by taking
path.extname(options.out)verbatim (jsonforschema.json) and using that as the language name. That candidate is thenchecked against each registered language's
namesarray viaisLanguageName().Every language's
extensionfield is itself one of the entries in its ownnamesarray (e.g. C# hasextension: "cs"andnames: ["cs", "csharp"]),except JSON Schema, which is registered with
extension: "schema"butnames: ["schema", "json-schema"]— no language is registered underjson.So
-o schema.jsonresolves to the candidate"json", which matches nolanguage, and
DriverUnknownOutputLanguagefires.Fix
inferLang()now maps a.jsonoutput extension to the"schema"languagename, matching the behavior the help text documents. All other extension
inference (
.ts,.py,.cs, etc.) is unchanged, and explicit--lang json/--src-lang jsonbehavior is unaffected (source-language andtarget-language name spaces are separate).
Test coverage
Added
test/unit/cli-output-language-inference.test.ts, which:-o schema.json input.json(no explicit--lang) resolves to theJSON Schema language — this is a regression test that failed before the fix.
--src-lang json(the JSON source format) still works unaffected.--lang jsonstill 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'sgenerated 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 buildpasses.npx vitest run test/unit— all 166 unit tests pass (no regressions).node dist/index.js -o schema.json latestblock.jsonnow exits 0 andwrites valid JSON Schema to
schema.json(previously errored).-o schema.json ...then-o bitcoin.ts --src-lang schema schema.json) now works end-to-end..ts,.py) are unaffected.Fixes #1579
🤖 Generated with Claude Code