Skip to content

Commit 87be600

Browse files
refactor: annotation parsing as methods
1 parent a252004 commit 87be600

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
{
@@ -741,12 +731,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
741731
propName = propSchemaName;
742732
}
743733
Annotation propSchemaOrArray = AnnotationsUtils.mergeSchemaAnnotations(annotations, propType);
744-
final io.swagger.v3.oas.annotations.media.Schema propResolvedSchemaAnnotation =
745-
propSchemaOrArray == null ?
746-
null :
747-
propSchemaOrArray instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
748-
((io.swagger.v3.oas.annotations.media.ArraySchema) propSchemaOrArray).arraySchema() :
749-
(io.swagger.v3.oas.annotations.media.Schema) propSchemaOrArray;
734+
final io.swagger.v3.oas.annotations.media.Schema propResolvedSchemaAnnotation = getSchemaAnnotationForArray(propSchemaOrArray);
750735

751736
io.swagger.v3.oas.annotations.media.Schema.AccessMode accessMode = resolveAccessMode(propDef, type, propResolvedSchemaAnnotation);
752737
io.swagger.v3.oas.annotations.media.Schema.RequiredMode requiredMode = resolveRequiredMode(propResolvedSchemaAnnotation, propType);
@@ -3037,12 +3022,7 @@ protected void resolveSchemaMembers(Schema schema, AnnotatedType annotatedType,
30373022
}
30383023

30393024
final Annotation resolvedSchemaOrArrayAnnotation = AnnotationsUtils.mergeSchemaAnnotations(annotatedType.getCtxAnnotations(), type);
3040-
final io.swagger.v3.oas.annotations.media.Schema schemaAnnotation =
3041-
resolvedSchemaOrArrayAnnotation == null ?
3042-
null :
3043-
resolvedSchemaOrArrayAnnotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ?
3044-
((io.swagger.v3.oas.annotations.media.ArraySchema) resolvedSchemaOrArrayAnnotation).schema() :
3045-
(io.swagger.v3.oas.annotations.media.Schema) resolvedSchemaOrArrayAnnotation;
3025+
final io.swagger.v3.oas.annotations.media.Schema schemaAnnotation = getSchemaAnnotation(resolvedSchemaOrArrayAnnotation);
30463026

30473027
final BeanDescription beanDesc = _mapper.getSerializationConfig().introspect(type);
30483028
Annotated a = beanDesc.getClassInfo();
@@ -3561,6 +3541,36 @@ private Optional<Schema> resolveArraySchemaWithCycleGuard(
35613541
return reResolvedProperty;
35623542
}
35633543

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

0 commit comments

Comments
 (0)