Skip to content

Type field missing from generated OpenAPI 3.1 schema with custom ModelResolver #3102

@jackwhelpton

Description

@jackwhelpton

Describe the bug

OpenAPI 3.1 docs omit type information.

To Reproduce
Steps to reproduce the behavior:

Given a simple POJO:

@Data
@Schema(name = "quantityInStatus", description = "Quantity in status model")
public class QuantityInStatus {

    @Schema(example = "10", description = "Created")
    private long created;
}

The OpenAPI 3.0 output is:

QuantityInStatus:
  description: Quantity in status model
  properties:
    created:
      description: Created
      example: 10
      format: int64
      type: integer
  type: object

For 3.1, we see only:

QuantityInStatus:
  description: Quantity in status model
  properties:
    created:
      description: Created
      example: 10
      format: int64
      type: integer

Observe the missing type information.

  • What version of spring-boot you are using? 3.5.6

  • What modules and versions of springdoc-openapi are you using?

    • 2.8.13 of springdoc-openapi-starter-webmvc-ui
    • 2.2.38 of swagger-core (updated/pinned in pom.xml)
  • Provide with a sample code (HelloController) or Test that reproduces the problem

This test doesn't reproduce the actual schema generation part, but it may show the underlying cause.

@Schema
record TestResource(int quantity) {}

@Test
void shouldIncludeTypeWithOpenApi3_0() {
    ResolvedSchema resolvedSchema = ModelConverters.getInstance(false)
            .resolveAsResolvedSchema(new AnnotatedType(TestResource.class).resolveAsRef(false));

    String type = resolvedSchema.schema.getType();

    assertThat(type).isEqualTo("object");
}

@Test
void shouldIncludeTypeWithOpenApi3_1() {
    ResolvedSchema resolvedSchema = ModelConverters.getInstance(true)
            .resolveAsResolvedSchema(new AnnotatedType(TestResource.class).resolveAsRef(false));

    String type = resolvedSchema.schema.getType();

    assertThat(type).isEqualTo("object");
}

@Test
void shouldIncludeTypesWithOpenApi3_1() {
    ResolvedSchema resolvedSchema = ModelConverters.getInstance(true)
            .resolveAsResolvedSchema(new AnnotatedType(TestResource.class).resolveAsRef(false));

    Set<String> types = resolvedSchema.schema.getTypes();

    assertThat(types).containsExactly("object");
}

Observe that the ResolvedSchema for 3.1 has null type property (shouldIncludeTypeWithOpenApi3_1 fails), but instead populates the types set (shouldIncludeTypesWithOpenApi3_1 passes).

Is it possible the types field isn't being used when generating the actual docs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions