Skip to content

fix: treat top-level array schemas with non-trivial items as real models, not aliases#23268

Open
marineotter wants to merge 2 commits intoOpenAPITools:masterfrom
marineotter:fix/array-model-generation
Open

fix: treat top-level array schemas with non-trivial items as real models, not aliases#23268
marineotter wants to merge 2 commits intoOpenAPITools:masterfrom
marineotter:fix/array-model-generation

Conversation

@marineotter
Copy link

@marineotter marineotter commented Mar 16, 2026

Why

Top-level type: array schemas like AnimalFarm (an array of Animal) are legitimate named models that users expect to see generated. However, the current code treats all array schemas as simple aliases (e.g. List<String>) and skips model generation entirely.

This happens because shouldGenerateArrayModel() only checks schema.getProperties() — a field that array schemas never use. Array schemas describe their element type via items, not properties, so the check always returns false.

This means any top-level array schema with a $ref, composed type (oneOf/anyOf/allOf), or inline object in its items silently disappears from the generated output.

For reference, tested against the GitHub REST API OpenAPI schema (12MB, 916 schemas): out of 14 top-level array schemas, 12 were silently skipped despite having non-trivial items — only the 2 primitive aliases (List, List) should have been skipped.

Intent

The fix teaches shouldGenerateArrayModel() to look at items — the same place every other part of the codebase already looks for array element types. This brings it to parity with shouldGenerateMapModel(), which already handles the analogous case for maps.

Primitive aliases like List<String> or List<Integer> remain correctly skipped.

Note on sample regeneration

Running generate-samples.sh produces a large number of new files across many generators, as previously skipped array models are now correctly generated. The regenerated samples are intentionally not included in this PR to keep the review focused. Happy to add them in a follow-up commit if preferred.

Related Issues

…posed schema

Previously, shouldGenerateArrayModel() only checked schema.getProperties()
to decide whether to generate a model class for a top-level array schema.
Since array schemas use 'items' rather than 'properties', this check always
returned false, causing all array schemas to be treated as simple aliases
and skipped during model generation.

After InlineModelResolver.flatten() runs, complex inline items are extracted
to #/components/schemas/ and replaced with a $ref. The updated check now
inspects the items schema for:
- $ref (resolved reference to an extracted component)
- inline properties
- composed schema (oneOf/anyOf/allOf)

Simple primitive aliases like List<String> or List<Integer> remain correctly
skipped as they match none of the above conditions.

Fixes OpenAPITools#7802
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

@marineotter marineotter marked this pull request as draft March 16, 2026 13:00
@marineotter marineotter changed the title fix: generate array model when items contain $ref, properties, or composed schema (#7802) fix: treat top-level array schemas with non-trivial items as real models, not aliases Mar 16, 2026
@marineotter marineotter marked this pull request as ready for review March 16, 2026 14:51
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

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] OpenAPI Generator fails to generate array models

1 participant