fix: treat array without items as list of Any per OpenAPI 3.1 (#1435) by rifkir23 · Pull Request #1484 · openapi-generators/openapi-python-client · GitHub
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}.
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.
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
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.
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.