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 16, 2024
1 parent e2ab9b8 commit 4f7c6df
Showing 1 changed file with 5 additions and 6 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 @@ -1308,11 +1310,8 @@ protected boolean ignore(final Annotated member, final XmlAccessorType xmlAccess
}

private void handleUnwrapped(ModelConverterContext context, List<Schema> props, Schema innerModel, String prefix, String suffix, List<String> requiredProps) {
if (innerModel.get$ref() != null && innerModel.getProperties() == null) {
Schema resolvedByRef = context.getDefinedModels().get(innerModel.get$ref().substring(21));
if (resolvedByRef != null) {
innerModel = resolvedByRef;
}
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) {
Expand Down Expand Up @@ -2284,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 4f7c6df

Please sign in to comment.