Skip to content

fix: hoist inline string enums in array items to named enums#34

Open
lightsofapollo wants to merge 2 commits into
mainfrom
fix/array-item-enum
Open

fix: hoist inline string enums in array items to named enums#34
lightsofapollo wants to merge 2 commits into
mainfrom
fix/array-item-enum

Conversation

@lightsofapollo

Copy link
Copy Markdown
Contributor

Fixes #33

Problem

Array items with type: string + enum collapsed to Vec<String>:

pub languages: Option<Vec<String>>,

analyze_array_schema mapped string items straight to a String primitive, while property-level inline enums were already hoisted into named StringEnum types by analyze_property_schema_with_context.

Fix

Extracted the property path's enum-hoisting logic (naming, same-value dedup, collision disambiguation with value/numeric suffixes) into a shared hoist_inline_string_enum helper, and routed array items through it. Item enums are named {Parent}Item, matching the existing {Parent}Item convention for inline objects in arrays:

pub languages: Option<Vec<GetProfileResponseLanguagesItem>>,

pub enum GetProfileResponseLanguagesItem {
    #[serde(rename = "EN")] En,
    #[serde(rename = "ES")] Es,
}

Covers the issue's exact anyOf [array, null] repro, plain arrays of enums, and typeless OpenAPI 3.1 enum items (items: {enum: [...]} with no type). Plain string arrays are unchanged.

Verification

  • 5 new regression tests in tests/array_item_enum_test.rs with insta snapshots
  • Full suite: cargo test --all-features — 411 passed, 0 failed, no churn in existing snapshots
  • cargo clippy --all-features -- -D warnings and cargo fmt --check clean
  • Generated the issue's repro spec, compiled the output as a real crate against REQUIRED_DEPS.toml, and verified a serde roundtrip through the new enum types

🤖 Generated with Claude Code

Array items with `type: string` + `enum` collapsed to `Vec<String>`
because analyze_array_schema mapped string items straight to a String
primitive, while property-level inline enums were already hoisted to
named StringEnum types.

Extract the property path's hoisting (naming, same-value dedup,
collision disambiguation) into hoist_inline_string_enum and route array
items through it, naming item enums `{Parent}Item`. Covers plain
arrays, anyOf-nullable arrays, and typeless OpenAPI 3.1 enum items.

Fixes #33

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openapi-to-rust Ready Ready Preview, Comment Jul 17, 2026 2:53pm

Request Review

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

[bug]: Array items with a string enum are generated as String, not an enum

1 participant