/* * * * Copyright 2019-2020 the original author or authors. * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * https://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * */ package test.org.springdoc.api.app89; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.WildcardType; import java.util.Iterator; import com.fasterxml.jackson.databind.type.SimpleType; import io.swagger.v3.core.converter.AnnotatedType; import io.swagger.v3.core.converter.ModelConverter; import io.swagger.v3.core.converter.ModelConverterContext; import io.swagger.v3.oas.models.media.Schema; import org.springframework.stereotype.Component; @Component public class GenericWildcardTypeModelConverter implements ModelConverter { @Override public Schema resolve( AnnotatedType annotatedType, ModelConverterContext modelConverterContext, Iterator iterator) { if (annotatedType.getType() instanceof SimpleType) { SimpleType type = (SimpleType) annotatedType.getType(); if(type.getBindings().size() !=0 && Object.class.equals(type.getBindings().getBoundType(0).getRawClass())){ annotatedType = new AnnotatedType(type.getRawClass()).jsonViewAnnotation(annotatedType.getJsonViewAnnotation()).resolveAsRef(true); return this.resolve(annotatedType, modelConverterContext, iterator); } } else if (annotatedType.getType() instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) annotatedType.getType(); Type type = parameterizedType.getActualTypeArguments()[0]; if (type instanceof WildcardType) { WildcardType wildcardType = (WildcardType) type; if (Object.class.equals(wildcardType.getUpperBounds()[0])) { annotatedType = new AnnotatedType(parameterizedType.getRawType()).jsonViewAnnotation(annotatedType.getJsonViewAnnotation()).resolveAsRef(true); return this.resolve(annotatedType, modelConverterContext, iterator); } } } if (iterator.hasNext()) { return iterator.next().resolve(annotatedType, modelConverterContext, iterator); } else { return null; } } }