Skip to content

Commit 6c95bfb

Browse files
committed
Add support for OAS 3.1 schema.types processing to make top level type: object visible in generated spec
1 parent fcf98fc commit 6c95bfb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,18 +536,24 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
536536
}
537537
}
538538
} else if (isComposedSchema) {
539-
model = new ComposedSchema()
540-
.type("object")
541-
.name(name);
539+
model = new ComposedSchema().name(name);
540+
if (openapi31 && resolvedArrayAnnotation == null){
541+
model.addType("object");
542+
}else{
543+
model.type("object");
544+
}
542545
} else {
543546
AnnotatedType aType = ReferenceTypeUtils.unwrapReference(annotatedType);
544547
if (aType != null) {
545548
model = context.resolve(aType);
546549
return model;
547550
} else {
548-
model = new Schema()
549-
.type("object")
550-
.name(name);
551+
model = new Schema().name(name);
552+
if (openapi31 && resolvedArrayAnnotation == null){
553+
model.addType("object");
554+
}else{
555+
model.type("object");
556+
}
551557
}
552558
}
553559

@@ -2980,7 +2986,7 @@ public void setOpenapi31(boolean openapi31) {
29802986
}
29812987

29822988
protected boolean isObjectSchema(Schema schema) {
2983-
return "object".equals(schema.getType()) || (schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
2989+
return (schema.getTypes() != null && schema.getTypes().contains("object")) || "object".equals(schema.getType()) || (schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
29842990
}
29852991

29862992
protected Schema buildRefSchemaIfObject(Schema schema, ModelConverterContext context) {

0 commit comments

Comments
 (0)