openapi-generators / openapi-generators/openapi-python-client

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

Đang mở
#1,435 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
2k
Fork
293
Merge trung bình
34 phút
Pull request đã merge (30 ngày)
1

Mô tả

Describe the bug
When a schema has "type": "array" without an "items" field, the generator fails to produce a property for it. In JSON Schema 2020-12 (used by OpenAPI 3.1), omitting items is valid and means "array of any type". The generator should treat it as equivalent to "items": {} (i.e., generate a List[Any] property) rather than silently failing.

OpenAPI Spec File
We encountered this in two forms:
Case 1 — bare array with no constraints:

{
  "type": "array",
  "description": "Array of objects representing a row of metrics data - can be any format."
}

Case 2 — array with maxItems but no items:

{
  "anyOf": [
    { "type": "array", "maxItems": 0 },
    { "type": "object", "properties": { "tag": { "type": "array", "items": { "type": "string" } } } }
  ]
}

In both cases the generator silently skips the schema (or the anyOf branch) without an error. Adding ["items": {}] to each fixes the generation.

Expected behaviour: {"type": "array"} (with or without other constraints like maxItems) should generate a List[Any] property, consistent with how JSON Schema 2020-12 defines it.

Desktop (please complete the following information):

  • OS: Ubuntu 24.04.3 LTS
  • Python Version: 3.12.3
  • openapi-python-client 0.28.1
  • OpenAPI version: 3.1.1 (JSON Schema 2020-12)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách theo dõi cách generator xử lý các array schema và các nhánh anyOf khi items không có, sử dụng hai schema trong issue làm đầu vào. Thêm kiểm thử hồi quy cho các array cơ bản và các array có maxItems, sau đó chạy generator và xác nhận rằng cả hai đều tạo ra một thuộc tính List[Any] thay vì bị bỏ qua.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
openapi, python
Lĩnh vực
api, tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
64/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.