[BUG][3.1] "Failed to get the schema name: null" for a schema with additionalProperties: false that has an additionalProperties: true property

Đang mở
#25,604 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

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

Từ ngày 10/11/2026.

  • #25605 của @1cbyc — đ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
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
devtools

Hướng nghiên cứu

Start with OpenAPINormalizer.isSelfReference and fixSelfReferenceSchema, using the stack trace and reproducer in the issue to follow how a schema without $ref reaches ModelUtils.getSimpleRef. Check the existing normalizer tests for self-reference handling and add coverage for the supplied OpenAPI 3.1 schema; done when generation no longer logs the warning. Pull request #25605 is already open against this issue.

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

Mô tả

Version

openapi-generator 7.27.0. Verified with kotlin-spring; the warning comes from the core OpenAPINormalizer, so it should not depend on the generator. OpenAPI 3.1.0 spec.

Reproducer

openapi: 3.1.0
info:
  title: repro
  version: 1.0.0
paths:
  /things:
    post:
      operationId: createThing
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Thing'
      responses:
        '200':
          description: ok
components:
  schemas:
    Thing:
      type: object
      additionalProperties: false
      properties:
        state:
          type: object
          additionalProperties: true

Run a generator on it (verified with kotlin-spring).

Actual

WARN ModelUtils - Failed to get the schema name: null

Code path (stack trace from a patched ModelUtils):

ModelUtils.getSimpleRef(ModelUtils.java:397)
OpenAPINormalizer.isSelfReference(OpenAPINormalizer.java:949)
OpenAPINormalizer.fixSelfReferenceSchema(OpenAPINormalizer.java:940)
OpenAPINormalizer.normalizeComponentsSchemas(OpenAPINormalizer.java:869)
OpenAPINormalizer.normalize(OpenAPINormalizer.java:442)
DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:272)

fixSelfReferenceSchema checks schema.getAdditionalProperties() instanceof Schema and then calls isSelfReference(name, ap), which calls getSimpleRef(ap.get$ref()).

For Thing, getAdditionalProperties() at that point is a Schema with every field null, including $ref, rather than the boolean false. So getSimpleRef(null) logs the warning.

Without the nested additionalProperties: true property, the same schema reaches the method with ap=false and no warning is logged. The empty Schema appears only when a property carries additionalProperties: true. I did not trace which earlier normalization step rewrites it.

Expected

No warning. An additionalProperties schema without a $ref cannot be a self-reference, so isSelfReference should return false when subSchema.get$ref() == null, without calling getSimpleRef. The generated output is not affected by this bug.

Suggested fix

protected boolean isSelfReference(String name, Schema subSchema) {
    return subSchema != null && subSchema.get$ref() != null
        && name.equals(ModelUtils.getSimpleRef(subSchema.get$ref()));
}

I searched existing issues for "Failed to get the schema name" (the matches were about unrelated $ref resolution) and for fixSelfReferenceSchema (#17755, unrelated).

Ngôn ngữ chính
Java
Star
26.9k
Fork
7.8k
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
180

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.