-
-
Notifications
You must be signed in to change notification settings - Fork 548
Description
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
ofspringdoc-openapi-starter-webmvc-ui
2.2.38
ofswagger-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?