openapi-generators / openapi-generators/openapi-python-client
union types and nullables can create unnecessary class suffixes (and related problems)
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
In some valid specs, the use of anyOf, oneOf, nullable, and/or type as a list, can cause generated class names to have unnecessary suffixes (and, sometimes, for spurious extra copies of classes to appear). These problems seem to all ultimately come from the behavior of UnionProperty.
The problem cases are all included in the attached specs files. Looking at the code generated from these specs—
in both 3.0 & 3.1:
ExampleModel.nullableObjectWithOneOfcorrectly has the typeUnion[MyObject, None, Unset].ExampleModel.inlineNullableObjectgenerates a model class calledExampleModelInlineNullableObjectType0. It should be justExampleModelInlineNullableObject, since there are no other named types for this property.- Similarly, the
MyEnumschema, which is a nullable enum, generates the classMyEnumType1even though there is noType0. - The
MyEnumWithExplicitTypeschema is the same asMyEnumexcept it specifically indicatestype, and the result is a bit wilder: it generates enum classesMyEnumWithExplicitTypeType1,MyEnumWithExplicitType2Type1, andMyEnumWithExplicitType3Type1, all of which are exactly the same.
only applicable to 3.1:
ExampleModel.nullableObjectWithExplicitTypes, which is the same asnullable_object_with_one_ofexcept that it also (unnecessarily, but validly) specifiestype: ["object", "null"], also works correctly.ExampleModel.one_of_enums_with_explicit_types, which combines a string enum with an int enum and specifies `type: ["string", "integer"], has the problem where three classes are created for each enum.
OpenAPI Spec Files
3.0: https://gist.github.com/eli-bl/7bea406525fb3b1452a71781ada5c1c0
3.1: https://gist.github.com/eli-bl/c03c88eb69312053e0122d1d8a06c2a0
Desktop (please complete the following information):
- OS: macOS 14.5
- Python Version: 3.8.15
- openapi-python-client version 0.21.5
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.
Hướng nghiên cứu
Bắt đầu với hành vi của UnionProperty và tạo các client từ các tệp đặc tả OpenAPI 3.0 và 3.1 được liên kết. So sánh tên các class được tạo và các model trùng lặp với những ví dụ được mô tả trong issue. Hoàn thành khi các schema nullable và union không còn nhận các hậu tố không cần thiết hoặc tạo ra các class bổ sung giống hệt nhau.
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
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100