Attempted to generate duplicate models with name "TypenameFieldnameItem"
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Bắt đầu bằng cách chạy openapi-python-client generate --path=example.yaml --overwrite với hai schema trong issue, sau đó lần theo entry point của quá trình tạo model xử lý phần tử array inline và model được tham chiếu. Công việc được xem là hoàn tất khi dạng inline không còn báo cáo model ResultAThingsItem bị trùng lặp và response GET được giữ lại trong client được tạo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
I stumbled on a weirdly specific bug that causes the generator to attempt to generate duplicate models.
Apparently we need:
- a OneOf type (A), which references an Object type (B)
- An object type (B) with an array-of-object field
- An Object type (C) for the array-of-object field
- array-of-C and C must be declared inline inside B
OpenAPI Spec File
This works
openapi: 3.0.3
info:
title: Minimal example for error "Attempted to generate duplicate models"
version: 1.0.0
components:
schemas:
Result:
oneOf:
- $ref: "#/components/schemas/ResultA"
discriminator:
propertyName: type
mapping:
"A": "#/components/schemas/ResultA"
ResultA:
type: object
properties:
things:
type: array
items:
$ref: "#/components/schemas/ResultAThingsItem"
ResultAThingsItem:
type: object
properties:
name:
type: string
paths:
/something:
get:
summary: Returns a list of users.
responses:
'200':
description: A successful response returning the list of users.
content:
application/json:
schema:
$ref: '#/components/schemas/Result'
This should be the same, but doesn't work:
openapi: 3.0.3
info:
title: Minimal example for error "Attempted to generate duplicate models"
version: 1.0.0
components:
schemas:
Result:
oneOf:
- $ref: "#/components/schemas/ResultA"
discriminator:
propertyName: type
mapping:
"A": "#/components/schemas/ResultA"
ResultA:
type: object
properties:
things:
type: array
items:
type: object
properties:
name:
type: string
paths:
/something:
get:
summary: Returns a list of users.
responses:
'200':
description: A successful response returning the list of users.
content:
application/json:
schema:
$ref: '#/components/schemas/Result'
Output:
$ pipx run openapi-python-client generate --path=example.yaml --overwrite
Generating <...>/minimal-example-for-error-attempted-to-generate-duplicate-models-client
Warning(s) encountered while generating. Client was generated, but some pieces may be missing
WARNING parsing GET /something within default.
Cannot parse response for status code 200 (Could not find reference in parsed models or enums), response will be omitted from generated client
Reference(ref='#/components/schemas/Result')
Unable to process schema /components/schemas/Result:
Attempted to generate duplicate models with name "ResultAThingsItem"
Failure to process schema has resulted in the removal of:
/components/schemas/ResultA
/components/schemas/Result
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=None, const=None, type=<DataType.OBJECT: 'object'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, prefixItems=[], properties={'name': 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=None, 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)}, 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)
If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose
**Desktop (please complete the following information):**
- OS: Ubuntu 25.04
- Python Version: 3.12.3
- openapi-python-client version: 0.28.0
- Ngôn ngữ chính
- Python
- Star
- 2k
- Fork
- 293
- Merge trung bình
- 34 phút
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openapi-generators/openapi-python-client
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
openapi-generators/openapi-python-client#1451 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
openapi-generators/openapi-python-client#1435 · 1 bình luận ·
Tất cả issue của openapi-generators/openapi-python-client
Issue tương tự
-
🐛 Bug 🔔 Pending processing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·