Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[BUG] ExampleGenerator returns the string "{}" (or null) for `type: object` schemas without `properties`

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

Maintainer thường phản hồi trong vòng 1 ngày

@manduinca đang làm issue này rồi.

Từ ngày 14/10/2026.

  • #25253 của @manduinca — đang mở

Đá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, openapi
Lĩnh vực
api

Hướng nghiên cứu

Tìm resolvePropertyToExample và resolveModelToExample trong mã Java triển khai ExampleGenerator; issue không nêu tên tệp chứa chúng hoặc một bài kiểm thử. Bắt đầu bằng cách tái hiện lỗi với lược đồ OpenAPI được cung cấp và kiểm tra cách xử lý các giá trị $ref chưa được phân giải. Công việc được xem là hoàn tất khi các lược đồ đối tượng không có thuộc tính tạo ra một đối tượng JSON rỗng trong cả ví dụ lồng nhau lẫn ví dụ cấp cao nhất, thay vì một chuỗi hoặc null.

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

Mô tả

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

resolvePropertyToExample returns the Java string literal "{}" for an object schema without properties and for a $ref that cannot be resolved. Json.pretty then serializes it as a JSON string ("metadata" : "{}") instead of an empty object ("metadata" : { }), so the example has the wrong type (JSON Schema Validation wright-00, 5.21).

The same happens one level up. For a top-level model type: object without properties, resolveModelToExample falls through to return null, and generate(null, ["application/json"], "Anything") returns the example null. Through the CLI this model gets unaliased first, so the operation simply has no example; only programmatic callers see null.

openapi-generator version

7.25.0 (also current master).

OpenAPI declaration file content or url
components:
  schemas:
    Reading:
      type: object
      properties:
        metadata:
          type: object
Steps to reproduce

generate -g html → "Example data" shows "metadata" : "{}". Expected: "metadata" : { }.

Suggest a fix

Return new LinkedHashMap<>() (an empty map) instead of the string "{}" in both branches of resolvePropertyToExample, and also for object schemas without properties in resolveModelToExample.

Ngôn ngữ chính
Java
Star
26.8k
Fork
7.7k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
146

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

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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 OpenAPITools/openapi-generator

Tất cả issue của OpenAPITools/openapi-generator

Issue tương tự

Thêm issue về Java

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.