Skip to content

Commit

Permalink
swagger-api#4781 Jackson/@JsonUnwrapped - when innerModel.$ref not nu…
Browse files Browse the repository at this point in the history
…ll - unwrapping does not happen
  • Loading branch information
mironbalcerzak committed Nov 17, 2024
1 parent e8bb595 commit 7aa8c86
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -727,7 +729,11 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
.ctxAnnotations(null)
.jsonUnwrappedHandler(null)
.resolveAsRef(false);
handleUnwrapped(props, context.resolve(t), uw.prefix(), uw.suffix(), requiredProps);
Schema innerModel = context.resolve(t);
if (StringUtils.isNotBlank(innerModel.get$ref())) {
innerModel = context.getDefinedModels().get(innerModel.get$ref().substring(SCHEMA_COMPONENT_PREFIX));
}
handleUnwrapped(props, innerModel, uw.prefix(), uw.suffix(), requiredProps);
return null;
} else {
return new Schema();
Expand Down Expand Up @@ -2278,7 +2284,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);
Expand Down

0 comments on commit 7aa8c86

Please sign in to comment.