Generate typed enums for inline enums in array items#76
Open
halotukozak wants to merge 9 commits into
Open
Conversation
Inline enums declared in array `items` (or inline on a property) were emitted as plain `String`, dropping enum values and type safety. Add `TypeRef.InlineEnum`; the parser now emits it for enum schemas that are not named components. `ModelGenerator` collects, deduplicates, names, and generates an `EnumModel` for each, resolving references like inline objects. The shared collect/dedup/name pipeline for inline objects and enums is unified in `collectInlineDefinitions`. Closes #74 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Coverage Report
|
Traversal order is irrelevant downstream (results are sorted by contextHint then deduplicated), so drop the addFirst container handling. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
collectInlineTypeRefs and collectInlineEnumRefs were the same tree walk differing only in the collected variant. Replace both with walkTypeRefs; callers filterIsInstance for the variant they need. Structural dedup already happens downstream via distinctBy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the manual ArrayDeque loop with a DeepRecursiveFunction that returns each node plus its descendants, matching the codebase idiom used by containsUnknown. Stack-safe on deeply nested schemas. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The marker named a capability ("has a context hint") rather than the
concept. InlineType is a proper sealed subtype grouping Inline and
InlineEnum: schemas defined anonymously inline that must be hoisted into
named declarations, with contextHint as the naming seed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move the inline schema/enum collection (walk, dedup, name, model) out of ModelGenerator into InlineCollector, alongside the resolution half. The generic pipeline is now collectInlineSchemas/collectInlineEnums building on inlineRefs + toNamedModels. ModelGenerator stays focused on KotlinPoet generation (729 -> 634 lines). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
inlineRefs now returns a Sequence and toNamedModels consumes it directly, removing the intermediate flatMap/filterIsInstance lists before the sort. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Lazy from the roots through descendants/filter into the sort, dropping the intermediate root lists and the asSequence hop in inlineRefs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes #74. Inline enums declared directly in array
items(or inline on a property) were generated as plainString, losing both the enum values and type safety.Before
After
Changes
TypeRef.InlineEnumvariant.SpecParseremitsInlineEnumfor enum schemas that are not named components (named component enums still resolve toReference). Null enum entries (nullable markers) are filtered.ModelGeneratorcollects inline enums, deduplicates structurally (InlineEnumKey), registers names via the sharedNameRegistry, generates anEnumModel, and resolves references — mirroring inline-object handling.collectInlineDefinitions+topLevelTypeRefs.Tests
SpecParserInlineEnumTest— parser producesArray(InlineEnum)from the spec.ModelGeneratorInlineEnumTest— a typed enum class is generated and the property references it.<Parent>_<Property>Item).Out of scope (separate follow-ups, noted in #74)
uniqueItems: truestill maps toList(notSet).defaultis still dropped (nullable property defaults tonull).🤖 Generated with Claude Code