|
21 | 21 | * * * *
|
22 | 22 | * * *
|
23 | 23 | * *
|
24 |
| - * |
| 24 | + * |
25 | 25 | */
|
26 | 26 |
|
27 | 27 | package org.springdoc.core.converters;
|
@@ -110,32 +110,35 @@ else if (resolvedSchema.getProperties().containsKey(javaType.getRawClass().getSi
|
110 | 110 | @Override
|
111 | 111 | public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
|
112 | 112 | JavaType javaType = springDocObjectMapper.jsonMapper().constructType(type.getType());
|
113 |
| - if (javaType != null) { |
114 |
| - for (Field field : FieldUtils.getAllFields(javaType.getRawClass())) { |
115 |
| - if (field.isAnnotationPresent(JsonUnwrapped.class)) { |
116 |
| - PARENT_TYPES_TO_IGNORE.add(javaType.getRawClass().getSimpleName()); |
117 |
| - } |
| 113 | + |
| 114 | + if (javaType == null || !chain.hasNext()) { |
| 115 | + return null; |
| 116 | + } |
| 117 | + |
| 118 | + for (Field field : FieldUtils.getAllFields(javaType.getRawClass())) { |
| 119 | + if (field.isAnnotationPresent(JsonUnwrapped.class)) { |
| 120 | + PARENT_TYPES_TO_IGNORE.add(javaType.getRawClass().getSimpleName()); |
118 | 121 | }
|
119 |
| - if (chain.hasNext()) { |
120 |
| - if (!type.isResolveAsRef() && type.getParent() != null |
121 |
| - && PARENT_TYPES_TO_IGNORE.stream().noneMatch(ignore -> type.getParent().getName().startsWith(ignore))) |
122 |
| - type.resolveAsRef(true); |
123 |
| - Schema<?> resolvedSchema = chain.next().resolve(type, context, chain); |
124 |
| - resolvedSchema = getResolvedSchema(javaType, resolvedSchema); |
125 |
| - if (resolvedSchema == null || resolvedSchema.get$ref() == null) { |
126 |
| - return resolvedSchema; |
127 |
| - } |
128 |
| - if(resolvedSchema.get$ref().contains(Components.COMPONENTS_SCHEMAS_REF)) { |
129 |
| - String schemaName = resolvedSchema.get$ref().substring(Components.COMPONENTS_SCHEMAS_REF.length()); |
130 |
| - Schema existingSchema = context.getDefinedModels().get(schemaName); |
131 |
| - if (existingSchema != null && existingSchema.getOneOf() != null) { |
132 |
| - return resolvedSchema; |
133 |
| - } |
134 |
| - } |
135 |
| - return composePolymorphicSchema(type, resolvedSchema, context.getDefinedModels().values()); |
| 122 | + } |
| 123 | + |
| 124 | + String parentName = type.getParent() == null ? null : type.getParent().getName(); |
| 125 | + if (parentName != null && PARENT_TYPES_TO_IGNORE.stream().noneMatch(parentName::startsWith)){ |
| 126 | + type.resolveAsRef(true); |
| 127 | + } |
| 128 | + |
| 129 | + Schema<?> resolvedSchema = getResolvedSchema(javaType, chain.next().resolve(type, context, chain)); |
| 130 | + if (resolvedSchema == null || resolvedSchema.get$ref() == null) { |
| 131 | + return resolvedSchema; |
| 132 | + } |
| 133 | + |
| 134 | + if(resolvedSchema.get$ref().contains(Components.COMPONENTS_SCHEMAS_REF)) { |
| 135 | + String schemaName = resolvedSchema.get$ref().substring(Components.COMPONENTS_SCHEMAS_REF.length()); |
| 136 | + Schema existingSchema = context.getDefinedModels().get(schemaName); |
| 137 | + if (existingSchema != null && existingSchema.getOneOf() != null) { |
| 138 | + return resolvedSchema; |
136 | 139 | }
|
137 | 140 | }
|
138 |
| - return null; |
| 141 | + return composePolymorphicSchema(type, resolvedSchema, context.getDefinedModels().values()); |
139 | 142 | }
|
140 | 143 |
|
141 | 144 | /**
|
|
0 commit comments