refactor: Compact schema_generation to <150 LOC#855
Open
MQ37 wants to merge 1 commit into
Open
Conversation
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
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.
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.
src/utils/schema_generation.tstests/unit/schema_generation.test.tsWorth your attention
it.eachtables. Same regression coverage: NYC sushi case, heterogeneous keys, format false-positive guard.!non-null assertions added inmerge. Both inside branches guarded by&&/||predicates immediately above (ap[k] && bp[k]anda.items || b.items). The narrowing alternative was 4 LOC longer.JsonSchemaArray,JsonSchemaObject,SchemaGenerationOptions, and theremoveEmptyArraysexport were all unused outside the module.JsonSchemaPropertystays (imported byactor_execution.ts).Open