Skip to content

Commit e35c15c

Browse files
author
bnasslahsen
committed
Need Graceful Handling for Exceptions. Fixes #606
1 parent ad8a599 commit e35c15c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocAnnotationsUtils.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@
3838
import io.swagger.v3.oas.models.media.StringSchema;
3939
import org.apache.commons.lang3.ArrayUtils;
4040
import org.apache.commons.lang3.StringUtils;
41+
import org.slf4j.Logger;
42+
import org.slf4j.LoggerFactory;
4143

4244
@SuppressWarnings({ "rawtypes" })
4345
public class SpringDocAnnotationsUtils extends AnnotationsUtils {
4446

47+
private static final Logger LOGGER = LoggerFactory.getLogger(SpringDocAnnotationsUtils.class);
48+
49+
private static final String GRACEFUL_EXCEPTION_OCCURRED = "Graceful exception occurred";
50+
4551
public static Schema resolveSchemaFromType(Class<?> schemaImplementation, Components components,
4652
JsonView jsonView, Annotation[] annotations) {
4753
Schema schemaObject = extractSchema(components, schemaImplementation, jsonView, annotations);
@@ -55,9 +61,16 @@ public static Schema resolveSchemaFromType(Class<?> schemaImplementation, Compon
5561

5662
public static Schema extractSchema(Components components, Type returnType, JsonView jsonView, Annotation[] annotations) {
5763
Schema schemaN = null;
58-
ResolvedSchema resolvedSchema = ModelConverters.getInstance()
59-
.resolveAsResolvedSchema(
60-
new AnnotatedType(returnType).resolveAsRef(true).jsonViewAnnotation(jsonView).ctxAnnotations(annotations));
64+
ResolvedSchema resolvedSchema = null;
65+
try {
66+
resolvedSchema = ModelConverters.getInstance()
67+
.resolveAsResolvedSchema(
68+
new AnnotatedType(returnType).resolveAsRef(true).jsonViewAnnotation(jsonView).ctxAnnotations(annotations));
69+
}
70+
catch (Exception e) {
71+
LOGGER.error(GRACEFUL_EXCEPTION_OCCURRED, e);
72+
return new StringSchema();
73+
}
6174
if (resolvedSchema.schema != null) {
6275
schemaN = resolvedSchema.schema;
6376
Map<String, Schema> schemaMap = resolvedSchema.referencedSchemas;
@@ -167,7 +180,7 @@ private static MediaType getMediaType(Schema schema, Components components, Json
167180
return mediaType;
168181
}
169182

170-
private static boolean isArray(io.swagger.v3.oas.annotations.media.Content annotationContent){
183+
private static boolean isArray(io.swagger.v3.oas.annotations.media.Content annotationContent) {
171184
Class<?> schemaImplementation = annotationContent.schema().implementation();
172185
boolean isArray = false;
173186
if (schemaImplementation == Void.class) {

0 commit comments

Comments
 (0)