Skip to content

Commit e2014b0

Browse files
refactor: annotation parsing as methods
1 parent 576ea45 commit e2014b0

1 file changed

Lines changed: 35 additions & 25 deletions

File tree

modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,9 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
179179
}
180180

181181
final Annotation resolvedSchemaOrArrayAnnotation = AnnotationsUtils.mergeSchemaAnnotations(annotatedType.getCtxAnnotations(), type);
182-
final io.swagger.v3.oas.annotations.media.Schema resolvedSchemaAnnotation =
183-
resolvedSchemaOrArrayAnnotation == null ?
184-
null :
185-
resolvedSchemaOrArrayAnnotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
186-
((io.swagger.v3.oas.annotations.media.ArraySchema) resolvedSchemaOrArrayAnnotation).schema() :
187-
(io.swagger.v3.oas.annotations.media.Schema) resolvedSchemaOrArrayAnnotation;
188-
189-
final io.swagger.v3.oas.annotations.media.ArraySchema resolvedArrayAnnotation =
190-
resolvedSchemaOrArrayAnnotation == null ?
191-
null :
192-
resolvedSchemaOrArrayAnnotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
193-
(io.swagger.v3.oas.annotations.media.ArraySchema) resolvedSchemaOrArrayAnnotation :
194-
null;
182+
final io.swagger.v3.oas.annotations.media.Schema resolvedSchemaAnnotation = getSchemaAnnotation(resolvedSchemaOrArrayAnnotation);
183+
184+
final io.swagger.v3.oas.annotations.media.ArraySchema resolvedArrayAnnotation = getArraySchemaAnnotation(resolvedSchemaOrArrayAnnotation);
195185

196186
final BeanDescription beanDesc;
197187
{
@@ -744,12 +734,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
744734
propName = propSchemaName;
745735
}
746736
Annotation propSchemaOrArray = AnnotationsUtils.mergeSchemaAnnotations(annotations, propType);
747-
final io.swagger.v3.oas.annotations.media.Schema propResolvedSchemaAnnotation =
748-
propSchemaOrArray == null ?
749-
null :
750-
propSchemaOrArray instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
751-
((io.swagger.v3.oas.annotations.media.ArraySchema) propSchemaOrArray).arraySchema() :
752-
(io.swagger.v3.oas.annotations.media.Schema) propSchemaOrArray;
737+
final io.swagger.v3.oas.annotations.media.Schema propResolvedSchemaAnnotation = getSchemaAnnotationForArray(propSchemaOrArray);
753738

754739
io.swagger.v3.oas.annotations.media.Schema.AccessMode accessMode = resolveAccessMode(propDef, type, propResolvedSchemaAnnotation);
755740
io.swagger.v3.oas.annotations.media.Schema.RequiredMode requiredMode = resolveRequiredMode(propResolvedSchemaAnnotation, propType);
@@ -3040,12 +3025,7 @@ protected void resolveSchemaMembers(Schema schema, AnnotatedType annotatedType,
30403025
}
30413026

30423027
final Annotation resolvedSchemaOrArrayAnnotation = AnnotationsUtils.mergeSchemaAnnotations(annotatedType.getCtxAnnotations(), type);
3043-
final io.swagger.v3.oas.annotations.media.Schema schemaAnnotation =
3044-
resolvedSchemaOrArrayAnnotation == null ?
3045-
null :
3046-
resolvedSchemaOrArrayAnnotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
3047-
((io.swagger.v3.oas.annotations.media.ArraySchema) resolvedSchemaOrArrayAnnotation).schema() :
3048-
(io.swagger.v3.oas.annotations.media.Schema) resolvedSchemaOrArrayAnnotation;
3028+
final io.swagger.v3.oas.annotations.media.Schema schemaAnnotation = getSchemaAnnotation(resolvedSchemaOrArrayAnnotation);
30493029

30503030
final BeanDescription beanDesc = _mapper.getSerializationConfig().introspect(type);
30513031
Annotated a = beanDesc.getClassInfo();
@@ -3564,6 +3544,36 @@ private Optional<Schema> resolveArraySchemaWithCycleGuard(
35643544
return reResolvedProperty;
35653545
}
35663546

3547+
private io.swagger.v3.oas.annotations.media.Schema getSchemaAnnotationForArray(Annotation annotation) {
3548+
if (annotation == null) {
3549+
return null;
3550+
} else {
3551+
return annotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
3552+
((io.swagger.v3.oas.annotations.media.ArraySchema) annotation).arraySchema() :
3553+
(io.swagger.v3.oas.annotations.media.Schema) annotation;
3554+
}
3555+
}
3556+
3557+
private io.swagger.v3.oas.annotations.media.Schema getSchemaAnnotation(Annotation annotation) {
3558+
if (annotation == null) {
3559+
return null;
3560+
} else {
3561+
return annotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
3562+
((io.swagger.v3.oas.annotations.media.ArraySchema) annotation).schema() :
3563+
(io.swagger.v3.oas.annotations.media.Schema) annotation;
3564+
}
3565+
}
3566+
3567+
private io.swagger.v3.oas.annotations.media.ArraySchema getArraySchemaAnnotation(Annotation annotation) {
3568+
if (annotation == null) {
3569+
return null;
3570+
} else {
3571+
return annotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
3572+
(io.swagger.v3.oas.annotations.media.ArraySchema) annotation :
3573+
null;
3574+
}
3575+
}
3576+
35673577
/**
35683578
* Checks if the given JavaType represents a java.util.stream.Stream
35693579
*/

0 commit comments

Comments
 (0)