Skip to content

Commit

Permalink
refs #4247 - fix composed schema resolving on props
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Sep 7, 2022
1 parent 5c5bcf8 commit cb2776c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
return new Schema();
}

List<Class<?>> composedSchemaReferencedClasses = getComposedSchemaReferencedClasses(type.getRawClass(), annotatedType.getCtxAnnotations(), resolvedSchemaAnnotation);
boolean isComposedSchema = composedSchemaReferencedClasses != null;

if (isPrimitive) {
XML xml = resolveXml(beanDesc.getClassInfo(), annotatedType.getCtxAnnotations(), resolvedSchemaAnnotation);
if (xml != null) {
Expand All @@ -346,7 +349,9 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
// Return the model as a ref only property
model = new Schema().$ref(Components.COMPONENTS_SCHEMAS_REF + name);
}
return model;
if (!isComposedSchema) {
return model;
}
}

/**
Expand Down Expand Up @@ -384,9 +389,6 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
return context.resolve(aType);
}

List<Class<?>> composedSchemaReferencedClasses = getComposedSchemaReferencedClasses(type.getRawClass(), annotatedType.getCtxAnnotations(), resolvedSchemaAnnotation);
boolean isComposedSchema = composedSchemaReferencedClasses != null;

if (type.isContainerType()) {
// TODO currently a MapSchema or ArraySchema don't also support composed schema props (oneOf,..)
isComposedSchema = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import io.swagger.v3.core.resolving.resources.TestObjectTicket2620;
import io.swagger.v3.core.resolving.resources.TestObjectTicket2620Subtypes;
import io.swagger.v3.core.resolving.resources.TestObjectTicket2900;
import io.swagger.v3.core.resolving.resources.TestObjectTicket4247;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.core.util.Yaml;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.ComposedSchema;
import io.swagger.v3.oas.models.media.Schema;
Expand Down Expand Up @@ -125,4 +127,16 @@ public void readComposedSchema_ticket2616() {
model = schemas.get("objects");
Assert.assertNull(model);
}

@Test(description = "read composed schem refs #4247")
public void readComposedSchema_ticket4247() {
Map<String, Schema> schemas = ModelConverters.getInstance().readAll(TestObjectTicket4247.class);
Schema model = schemas.get("TestObjectTicket4247");
Assert.assertNotNull(model);
Map<String, Schema> properties = model.getProperties();
Assert.assertNotNull(properties.get("value"));
Assert.assertTrue(((ComposedSchema)properties.get("value")).getOneOf().size() == 2);
Assert.assertEquals(((ComposedSchema)properties.get("value")).getOneOf().get(0).getType(), "string");
Assert.assertEquals(((ComposedSchema)properties.get("value")).getOneOf().get(1).getType(), "number");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.swagger.v3.core.resolving.resources;

import io.swagger.v3.oas.annotations.media.Schema;

public class TestObjectTicket4247 {

@Schema(
oneOf = { String.class, Number.class }
)
public Object value;

}

0 comments on commit cb2776c

Please sign in to comment.