Skip to content

refactor: Compact schema_generation to <150 LOC#855

Open
MQ37 wants to merge 1 commit into
fix/dataset-schema-merge-empty-shapesfrom
refactor/schema-generation-under-150-loc
Open

refactor: Compact schema_generation to <150 LOC#855
MQ37 wants to merge 1 commit into
fix/dataset-schema-merge-empty-shapesfrom
refactor/schema-generation-under-150-loc

Conversation

@MQ37
Copy link
Copy Markdown
Contributor

@MQ37 MQ37 commented May 16, 2026

Context

Reviewer ceiling for src/utils/schema_generation.ts + tests is 150 LOC of code (comments / blank lines free). The fix in #854 lands at 387.

Solution

Compact both files to 148 combined LOC with the same behavior. Stacked on top of #854 so the diff in this PR is purely the compression — no behavior change to review here.

File #854 This PR
src/utils/schema_generation.ts 122 69
tests/unit/schema_generation.test.ts 265 79
Combined 387 148

Worth your attention

  • Coverage equivalent, fewer test blocks. 28 → 21 tests. The 6 type-union cases and 5 format-detection cases are folded into two it.each tables. Same regression coverage: NYC sushi case, heterogeneous keys, format false-positive guard.
  • Two ! non-null assertions added in merge. Both inside branches guarded by &&/|| predicates immediately above (ap[k] && bp[k] and a.items || b.items). The narrowing alternative was 4 LOC longer.
  • Internal types dropped, public surface unchanged. JsonSchemaArray, JsonSchemaObject, SchemaGenerationOptions, and the removeEmptyArrays export were all unused outside the module. JsonSchemaProperty stays (imported by actor_execution.ts).

Open

Same behavior as the previous commit (set-union merge, type-array
unions, format detection, NYC regression coverage). Tightening:

- Inline `inferType` into `infer`.
- Drop `JsonSchemaArray` / `JsonSchemaObject` types (redundant with
  `JsonSchemaProperty`).
- Drop `SchemaGenerationOptions` type (inlined into signature).
- Tests use `it.each` tables for the 6 type-union cases and 5
  format-detection cases; 28 \u2192 21 tests, coverage equivalent.

src/utils/schema_generation.ts:   122 \u2192 69 LOC
tests/unit/schema_generation.test.ts: 265 \u2192 79 LOC
Combined: 387 \u2192 148 LOC
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.

2 participants