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

Aberta
#25,604 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@1cbyc já está trabalhando nisso.

Desde 10/11/2026.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
java
Domínio
devtools

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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).

Linguagem predominante
Java
Estrelas
26.9k
Forks
7.8k
Merge médio
2d 10h
PRs com merge (30d)
180

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de OpenAPITools/openapi-generator

Todas as issues de OpenAPITools/openapi-generator

Issues semelhantes

Mais issues de Java

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.