Skip to content

fix: treat array without items as list of Any per OpenAPI 3.1 (#1435) - #1484

Open
rifkir23 wants to merge 2 commits into
openapi-generators:mainfrom
rifkir23:fix/array-without-items-list-any
Open

fix: treat array without items as list of Any per OpenAPI 3.1 (#1435)#1484
rifkir23 wants to merge 2 commits into
openapi-generators:mainfrom
rifkir23:fix/array-without-items-list-any

Conversation

@rifkir23

@rifkir23 rifkir23 commented Sep 3, 2026

Copy link
Copy Markdown

Problem

When a schema has "type": "array" with no items (and no prefixItems), the generator fails to produce a property, silently skipping the schema or the anyOf branch. In JSON Schema 2020-12 (used by OpenAPI 3.1), omitting items is valid and means "array of any type", so this should generate a list[Any] rather than failing.

Reported cases include a bare {"type": "array"} and an anyOf branch {"type": "array", "maxItems": 0}.

Fixes #1435

Fix

In ListProperty.build, when neither items nor prefixItems is present, use an empty schema (oai.Schema()) as the inner schema, which resolves to an AnyProperty. The property is generated as list[Any], equivalent to items: {}. Arrays that do declare items/prefixItems are unaffected.

Tests

Added TestArrayWithoutItems::test_array_without_items_becomes_list_of_any: a {"type": "array"} schema with no items now builds a ListProperty whose inner property is an AnyProperty and whose base type is list[Any]. Verified the test FAILS without the fix (returns a PropertyError) and PASSES with it. Full tests/ suite passes (322 passed, 4 skipped); ruff and mypy clean. Added a changeset per CONTRIBUTING.

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.

Generator fails on type: array without items even though it's valid in JSON Schema 2020-12 / OpenAPI 3.1

2 participants