Bug Report: Incorrect Model Reference in Generated Paginated Envelope
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu với schema.yaml được cung cấp và tái hiện lệnh tạo bằng cách sử dụng hai định nghĩa envelope phân trang. Kiểm tra PaginatedTransactionEnvelope đã được tạo và so sánh kiểu dữ liệu cùng các import dùng cho việc giải tuần tự của nó với schema và envelope customer được tạo chính xác. Hoàn tất khi dữ liệu giao dịch được phân giải thành TransactionEntity mà không gặp lỗi trạng thái CustomerEntity.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report: Incorrect Model Reference in Generated Paginated Envelope
Summary
openapi-python-client incorrectly generates PaginatedTransactionEnvelope with CustomerEntity instead of TransactionEntity, despite the OpenAPI schema correctly specifying TransactionEntity.
Environment
- openapi-python-client version: 0.28.1
- Python version: 3.13
- Generation command:
openapi-python-client generate \ --path schema.yaml \ --output-path ./generated \ --meta none
Expected Behavior
The generated PaginatedTransactionEnvelope should use TransactionEntity based on this schema definition:
PaginatedTransactionEnvelope:
allOf:
- $ref: '#/components/schemas/PaginatedSuccessEnvelope'
- type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/TransactionEntity'
Expected generated code:
if TYPE_CHECKING:
from ..models.transaction_entity import TransactionEntity
from ..models.links import Links
@_attrs_define
class PaginatedTransactionEnvelope:
timestamp: datetime.datetime
path: str
data: list[TransactionEntity] # ✓ Correct
links: Links
Actual Behavior
The generator produces code using CustomerEntity instead:
if TYPE_CHECKING:
from ..models.customer_entity import CustomerEntity # ✗ Wrong!
from ..models.links import Links
@_attrs_define
class PaginatedTransactionEnvelope:
timestamp: datetime.datetime
path: str
data: list[CustomerEntity] # ✗ Wrong!
links: Links
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.customer_entity import CustomerEntity # ✗ Wrong!
from ..models.links import Links
# ...
for data_item_data in _data:
data_item = CustomerEntity.from_dict(data_item_data) # ✗ Wrong!
data.append(data_item)
Impact
This causes runtime errors when parsing API responses:
ValueError: 'failed' is not a valid CustomerEntityStatus
The parser attempts to deserialize transaction data as customer data, failing when transaction-specific status values don't exist in the CustomerEntityStatus enum.
Additional Context
The schema also defines PaginatedCustomerEnvelope (which correctly uses CustomerEntity). The generator may be incorrectly reusing or caching the entity type across similar paginated envelope structures.
Related schema definitions:
PaginatedCustomerEnvelope:
allOf:
- $ref: '#/components/schemas/PaginatedSuccessEnvelope'
- type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/CustomerEntity'
PaginatedTransactionEnvelope:
allOf:
- $ref: '#/components/schemas/PaginatedSuccessEnvelope'
- type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/TransactionEntity'
Workaround
We've added a post-generation fix script:
sed -i '' 's/from ..models.customer_entity import CustomerEntity/from ..models.transaction_entity import TransactionEntity/g' "$FILE"
sed -i '' 's/list\[CustomerEntity\]/list[TransactionEntity]/g' "$FILE"
sed -i '' 's/CustomerEntity\.from_dict/TransactionEntity.from_dict/g' "$FILE"
Reproduction
The issue appears when:
- Multiple paginated envelopes are defined using
allOfwith shared base schemas - Each envelope should use different entity types in the
dataarray - The generator confuses the entity types between envelopes
- 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 ·