|
37 | 37 | import java.util.Set;
|
38 | 38 |
|
39 | 39 | import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
| 40 | +import com.fasterxml.jackson.databind.BeanDescription; |
40 | 41 | import com.fasterxml.jackson.databind.JavaType;
|
| 42 | +import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition; |
41 | 43 | import io.swagger.v3.core.converter.AnnotatedType;
|
42 | 44 | import io.swagger.v3.core.converter.ModelConverter;
|
43 | 45 | import io.swagger.v3.core.converter.ModelConverterContext;
|
@@ -120,17 +122,28 @@ else if (resolvedSchema.getProperties().containsKey(javaType.getRawClass().getSi
|
120 | 122 | public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
|
121 | 123 | JavaType javaType = springDocObjectMapper.jsonMapper().constructType(type.getType());
|
122 | 124 | if (javaType != null) {
|
123 |
| - for (Field field : FieldUtils.getAllFields(javaType.getRawClass())) { |
124 |
| - if (field.isAnnotationPresent(JsonUnwrapped.class)) { |
| 125 | + BeanDescription javaTypeIntrospection = springDocObjectMapper.jsonMapper().getDeserializationConfig().introspect(javaType); |
| 126 | + for (BeanPropertyDefinition property : javaTypeIntrospection.findProperties()) { |
| 127 | + boolean isUnwrapped = (property.getField() != null && property.getField().hasAnnotation(JsonUnwrapped.class)) || |
| 128 | + (property.getGetter() != null && property.getGetter().hasAnnotation(JsonUnwrapped.class)); |
| 129 | + |
| 130 | + if (isUnwrapped) { |
125 | 131 | if (!TypeNameResolver.std.getUseFqn())
|
126 | 132 | PARENT_TYPES_TO_IGNORE.add(javaType.getRawClass().getSimpleName());
|
127 | 133 | else
|
128 | 134 | PARENT_TYPES_TO_IGNORE.add(javaType.getRawClass().getName());
|
129 | 135 | }
|
130 |
| - else if (field.isAnnotationPresent(io.swagger.v3.oas.annotations.media.Schema.class)) { |
131 |
| - io.swagger.v3.oas.annotations.media.Schema declaredSchema = field.getDeclaredAnnotation(io.swagger.v3.oas.annotations.media.Schema.class); |
132 |
| - if (ArrayUtils.isNotEmpty(declaredSchema.oneOf()) || ArrayUtils.isNotEmpty(declaredSchema.allOf())) { |
133 |
| - TYPES_TO_SKIP.add(field.getType().getSimpleName()); |
| 136 | + else { |
| 137 | + io.swagger.v3.oas.annotations.media.Schema declaredSchema = null; |
| 138 | + if (property.getField() != null) { |
| 139 | + declaredSchema = property.getField().getAnnotation(io.swagger.v3.oas.annotations.media.Schema.class); |
| 140 | + } else if (property.getGetter() != null) { |
| 141 | + declaredSchema = property.getGetter().getAnnotation(io.swagger.v3.oas.annotations.media.Schema.class); |
| 142 | + } |
| 143 | + |
| 144 | + if (declaredSchema != null && |
| 145 | + (ArrayUtils.isNotEmpty(declaredSchema.oneOf()) || ArrayUtils.isNotEmpty(declaredSchema.allOf()))) { |
| 146 | + TYPES_TO_SKIP.add(property.getPrimaryType().getRawClass().getSimpleName()); |
134 | 147 | }
|
135 | 148 | }
|
136 | 149 | }
|
|
0 commit comments