Skip to content

Commit

Permalink
#4781 Jackson/@JsonUnwrapped - when innerModel.$ref not null - unwrap…
Browse files Browse the repository at this point in the history
…ping does not happen
  • Loading branch information
mironbalcerzak committed Nov 16, 2024
1 parent e8bb595 commit b82e212
Showing 1 changed file with 8 additions and 3 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,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();
Expand Down Expand Up @@ -1307,7 +1309,10 @@ protected boolean ignore(final Annotated member, final XmlAccessorType xmlAccess
return false;
}

private void handleUnwrapped(List<Schema> props, Schema innerModel, String prefix, String suffix, List<String> requiredProps) {
private void handleUnwrapped(ModelConverterContext context, List<Schema> props, Schema innerModel, String prefix, String suffix, List<String> requiredProps) {
if (StringUtils.isNotBlank(innerModel.get$ref())) {
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());
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b82e212

Please sign in to comment.