Skip to content

[BUG]: addSource with an empty samples array succeeds and renders boilerplate for a nonexistent type #2934

Description

@schani

Issue Type

quicktype-core API (input validation).

Context (Environment, Version, Language)

Input Format: JSON
Output Language: any (tested with TypeScript)

CLI, npm, or app.quicktype.io: npm (quicktype-core)
Version: 25.0.0-pre1 (also reproduces on 24.0.2)

Description

Calling addSource with samples: [] neither throws nor produces an error later — quicktype() happily renders output (168 lines of TypeScript converter boilerplate in my test) for a type that has no evidence at all:

const { quicktype, InputData, jsonInputForTargetLanguage } = require("quicktype-core");

const jsonInput = jsonInputForTargetLanguage("typescript");
await jsonInput.addSource({ name: "X", samples: [] });   // no samples!
const inputData = new InputData();
inputData.addInput(jsonInput);
const result = await quicktype({ inputData, lang: "typescript" });
console.log(result.lines.length); // 168 — full converter scaffolding, no meaningful type

An empty samples array is almost certainly a caller bug (e.g. a glob that matched nothing, or a filtered list that came up empty), and the current behavior masks it.

Expected Behavior

addSource({ name, samples: [] }) should throw a clear error, the same way malformed JSON in a sample already does (Syntax error in input JSON X: ...).

🤖 Filed with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions