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

Generator creates enum property types that can collide with user-defined types, causing generation failures

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

还没有人认领这个 Issue。

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

描述

Describe the bug

When the generator creates a new Python type to represent a schema property's enum type it can sometimes get unlucky by generating the name of a user-defined type that already exists in the schema.

When this happens, the generator gives up and issues a warning. The Python type for the enum property and the generated API client are only partially generated as a result. This warning manifests as a runtime error in the Python client when affected endpoints are accessed by the generated Python code. I have so far been unable to figure out any configuration-based way of working around the issue.

OpenAPI Spec File

This issue can be reproduced deterministically by running:

openapi-python-client generate --url https://raw.githubusercontent.com/EvanBacon/App-Store-Connect-OpenAPI-Spec/refs/heads/main/specs/3.6.0.json --overwrite

Relevant warning output is in the "Additional context" section below.

Desktop (please complete the following information):

  • OS: macOS 15.1.1
  • Python Version: 3.12.1
  • openapi-python-client version 0.21.6

Additional context

We discovered this "in the wild" while attempting to generate a Python client for the Apple App Store Connect API.

When we ran the generator on version 3.6.0 of the App Store Connect OpenAPI schema, we saw this (among other) warnings:

Unable to process schema /components/schemas/Certificate:

Found conflicting enums named CertificateType with incompatible values.

Failure to process schema has resulted in the removal of:
/components/schemas/Certificate
/components/schemas/CertificatesWithoutIncludesResponse
/components/schemas/CertificatesResponse
/components/schemas/CertificateResponse

Schema(title=None, multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=['certificates'], const=None, type=<DataType.STRING: 'string'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties=None, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None)

This was happening because the generator was attempting to create a type called "CertificateType" when it was traversing the properties of the "Certificate" object, who had a child enum property called "type", excerpt below:

      "Certificate": {
        "type": "object",
        "title": "Certificate",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "certificates"
            ]

The generator took the name of the parent, and concatenated it with the name of the property to create the name "CertificateType".

Sadly, as noted above, that type name was already taken in the API by a separate user-defined "CertificateType", excerpted below:

"CertificateType": {
        "type": "string",
        "enum": [
          "IOS_DEVELOPMENT",
          "IOS_DISTRIBUTION",

贡献指南

打开贡献指南

从这里开始

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

调研方向

使用提供的 openapi-python-client generate 命令和 App Store Connect 3.6.0 schema 重现该故障,然后追踪 Certificate 对象的 type 枚举如何变为 CertificateType 并与现有 schema 类型发生冲突。完成的标准是:生成过程不再丢弃受影响的 schema,也不再生成一个在访问这些 endpoint 时会在运行时失败的 client。

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

评估

技术栈
openapi, python
领域
tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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