use of com.fasterxml.jackson.databind.jsontype.NamedType in project swagger-core by swagger-api.
the class ModelResolver method removeSuperSubTypes.
private void removeSuperSubTypes(List<NamedType> resultTypes, Class<?> superClass) {
JavaType superType = _mapper.constructType(superClass);
BeanDescription superBean = _mapper.getSerializationConfig().introspect(superType);
final List<NamedType> superTypes = _intr.findSubtypes(superBean.getClassInfo());
if (superTypes != null) {
resultTypes.removeAll(superTypes);
}
}
use of com.fasterxml.jackson.databind.jsontype.NamedType in project swagger-core by swagger-api.
the class ModelResolver method resolveSubtypes.
private boolean resolveSubtypes(ModelImpl model, BeanDescription bean, ModelConverterContext context) {
final List<NamedType> types = _intr.findSubtypes(bean.getClassInfo());
if (types == null) {
return false;
}
/**
* As the introspector will find @JsonSubTypes for a child class that are present on its super classes, the
* code segment below will also run the introspector on the parent class, and then remove any sub-types that are
* found for the parent from the sub-types found for the child. The same logic all applies to implemented
* interfaces, and is accounted for below.
*/
removeSuperClassAndInterfaceSubTypes(types, bean);
int count = 0;
final Class<?> beanClass = bean.getClassInfo().getAnnotated();
for (NamedType subtype : types) {
final Class<?> subtypeType = subtype.getType();
if (!beanClass.isAssignableFrom(subtypeType)) {
continue;
}
final Model subtypeModel = context.resolve(subtypeType);
if (subtypeModel instanceof ModelImpl) {
final ModelImpl impl = (ModelImpl) subtypeModel;
// check if model name was inherited
if (impl.getName().equals(model.getName())) {
impl.setName(_typeNameResolver.nameForType(_mapper.constructType(subtypeType), TypeNameResolver.Options.SKIP_API_MODEL));
}
// remove shared properties defined in the parent
final Map<String, Property> baseProps = model.getProperties();
final Map<String, Property> subtypeProps = impl.getProperties();
if (baseProps != null && subtypeProps != null) {
for (Map.Entry<String, Property> entry : baseProps.entrySet()) {
if (entry.getValue().equals(subtypeProps.get(entry.getKey()))) {
subtypeProps.remove(entry.getKey());
}
}
}
impl.setDiscriminator(null);
ComposedModel child = new ComposedModel().parent(new RefModel(model.getName())).child(impl);
context.defineModel(impl.getName(), child, subtypeType, null);
++count;
}
}
return count != 0;
}
Aggregations