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

未关闭
#1,435 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
2k
派生
293
平均合并
34 分钟
30 天内合并 PR
1

描述

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)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 issue 中的两个 schema 作为输入,跟踪 generator 在缺少 items 时如何处理 array schema 和 anyOf 分支。为裸 array 以及带有 maxItems 的 array 添加回归覆盖,然后运行 generator 并确认二者都会生成 List[Any] 属性,而不是被跳过。

由索引模型根据 Issue 内容生成。

评估

技术栈
openapi, python
领域
api, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
描述清楚
新手友好度
64/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。