Setting dateLibrary=java11 fails to map "java.time" types

Đang mở Phù hợp với người mới
#1,433 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

Đọc AbstractJavaCodegen.java quanh các dòng 488–515, sau đó kiểm tra processOpts() và các nhánh dateLibrary hiện có. Kiểm tra cách mô tả tùy chọn java11 và cách cấu hình ánh xạ ngày tháng cùng các import cho những thư viện ngày tháng liên quan. Công việc hoàn tất khi chọn dateLibrary=java11 sẽ cấu hình các ánh xạ và import java.time như mong đợi mà không cần tùy chọn java11=true riêng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/java/io/swagger/codegen/v3/generators/java/AbstractJavaCodegen.java#L488-L515

In the above source code of AbstractJavaCodegen, the dateLibrary enum registers "java11" in the CLI options list. However, the processOpts() method only checks for "threetenbp", "joda", dateLibrary.startsWith("java8"), and "legacy":
• Missing if branch. Because there is no else if ("java11".equals(dateLibrary)) block in AbstractJavaCodegen.processOpts(), the generator skips setting up java.time type mappings and imports.
• Fallback to java.util.Date. By default, AbstractJavaCodegen initializes typeMapping.put("date", "Date"), which resolves to java.util.Date when no dateLibrary branch overrides it.
• Flag discrepancy. Although the CLI description claims "java11" automatically sets java11=true, the code only reads java11 if you explicitly pass true in your configuration.

This leads to the required strange combination of configuration options:

<configOptions>
    <!-- don't use "java11" - a bug in swagger lets this fall back to "legacy" -->
    <dateLibrary>java8</dateLibrary>
    <java11>true</java11>
    <jakarta>true</jakarta>
</configOptions>
Ngôn ngữ chính
Mustache
Star
299
Fork
439
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của swagger-api/swagger-codegen-generators

Tất cả issue của swagger-api/swagger-codegen-generators

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.