Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,24 @@ private static void assignType(Schema swaggerSchema, SchemaObject.SchemaObjectBu
Set<String> types = schemaTypes == null ? new HashSet<>() : new HashSet<>(schemaTypes);

String schemaType = swaggerSchema.getType();
if (schemaType == null) {
if (types.isEmpty()) {
// Leave type unset when the schema is composed and does not declare a concrete type
// (e.g. oneOf/anyOf/allOf without a base type).
return;
}
if (isNullable) {
types.add("null");
}
builder.type(types);
return;
}

if (!types.contains(schemaType)) {
// required while swagger v2 does not populate types. Leave type unset when the schema is composed
// and does not declare a concrete type (e.g. oneOf/anyOf/allOf without a base type).
if (schemaType != null) {
// required while swagger v2 does not populate types
if (isNullable) {
builder.type(Set.of(schemaType, "null"));
} else {
builder.type(Set.of(schemaType));
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ void getStringSchemas() {
.build());
}

@Test
void getOpenApi31NullTypeSchemas() {
io.swagger.v3.oas.models.media.Schema<?> swaggerSchema = new io.swagger.v3.oas.models.media.Schema<>();
Set<String> types = Set.of(SchemaType.STRING.getValue(), SchemaType.NULL.getValue());
swaggerSchema.setTypes(types);
SwaggerSchemaMapper mapper = new SwaggerSchemaMapper(configProperties);

assertThat(mapper.mapSchema(swaggerSchema).getSchema())
.isEqualTo(SchemaObject.builder().type(types).build());

swaggerSchema.setType(SchemaType.STRING.getValue());
assertThat(mapper.mapSchema(swaggerSchema).getSchema())
.isEqualTo(SchemaObject.builder().type(types).build());
}

@Test
void getArraySchemas() {
componentsService.resolvePayloadSchema(ArrayFoo.class, CONTENT_TYPE_APPLICATION_JSON);
Expand Down Expand Up @@ -235,7 +250,6 @@ private static class NotSupportedFoo {
@Schema(
hidden = true, // currently not supported
defaultValue = "default", // currently not supported
nullable = true, // currently not supported
contains = Void.class, // currently not supported
additionalItems = Void.class, // currently not supported
additionalProperties = Schema.AdditionalPropertiesValue.TRUE, // currently not supported
Expand Down
Loading