diff --git a/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java b/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java index 7b6b7cefa9..fd3738f164 100644 --- a/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java +++ b/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java @@ -118,6 +118,8 @@ public class ModelResolver extends AbstractModelConverter implements ModelConver public static boolean composedModelPropertiesAsSibling = System.getProperty(SET_PROPERTY_OF_COMPOSED_MODEL_AS_SIBLING) != null; + private static final int SCHEMA_COMPONENT_PREFIX = "#/components/schemas/".length(); + /** * Allows all enums to be resolved as a reference to a scheme added to the components section. */ @@ -727,7 +729,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context .ctxAnnotations(null) .jsonUnwrappedHandler(null) .resolveAsRef(false); - handleUnwrapped(props, context.resolve(t), uw.prefix(), uw.suffix(), requiredProps); + handleUnwrapped(context, props, context.resolve(t), uw.prefix(), uw.suffix(), requiredProps); return null; } else { return new Schema(); @@ -1307,7 +1309,10 @@ protected boolean ignore(final Annotated member, final XmlAccessorType xmlAccess return false; } - private void handleUnwrapped(List props, Schema innerModel, String prefix, String suffix, List requiredProps) { + private void handleUnwrapped(ModelConverterContext context, List props, Schema innerModel, String prefix, String suffix, List requiredProps) { + if (innerModel.get$ref() != null) { + innerModel = context.getDefinedModels().get(innerModel.get$ref().substring(SCHEMA_COMPONENT_PREFIX)); + } if (StringUtils.isBlank(suffix) && StringUtils.isBlank(prefix)) { if (innerModel.getProperties() != null) { props.addAll(innerModel.getProperties().values()); @@ -2278,7 +2283,7 @@ protected void resolveDiscriminatorProperty(JavaType type, ModelConverterContext if (StringUtils.isNotBlank(typeInfoProp)) { Schema modelToUpdate = model; if (StringUtils.isNotBlank(model.get$ref())) { - modelToUpdate = context.getDefinedModels().get(model.get$ref().substring(21)); + modelToUpdate = context.getDefinedModels().get(model.get$ref().substring(SCHEMA_COMPONENT_PREFIX)); } if (modelToUpdate.getProperties() == null || !modelToUpdate.getProperties().keySet().contains(typeInfoProp)) { Schema discriminatorSchema = new StringSchema().name(typeInfoProp);