use of io.swagger.v3.oas.annotations.media.DiscriminatorMapping in project swagger-core by swagger-api.
the class ModelResolver method resolveDiscriminator.
protected Discriminator resolveDiscriminator(JavaType type, ModelConverterContext context) {
io.swagger.v3.oas.annotations.media.Schema declaredSchemaAnnotation = AnnotationsUtils.getSchemaDeclaredAnnotation(type.getRawClass());
String disc = (declaredSchemaAnnotation == null) ? "" : declaredSchemaAnnotation.discriminatorProperty();
if (disc.isEmpty()) {
// longer method would involve AnnotationIntrospector.findTypeResolver(...) but:
JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class);
if (typeInfo != null) {
disc = typeInfo.property();
}
}
if (!disc.isEmpty()) {
Discriminator discriminator = new Discriminator().propertyName(disc);
if (declaredSchemaAnnotation != null) {
DiscriminatorMapping[] mappings = declaredSchemaAnnotation.discriminatorMapping();
if (mappings != null && mappings.length > 0) {
for (DiscriminatorMapping mapping : mappings) {
if (!mapping.value().isEmpty() && !mapping.schema().equals(Void.class)) {
discriminator.mapping(mapping.value(), constructRef(context.resolve(new AnnotatedType().type(mapping.schema())).getName()));
}
}
}
}
return discriminator;
}
return null;
}
Aggregations