All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.swagger.jaxrs.ext.AbstractSwaggerExtension Maven / Gradle / Ivy

The newest version!
package io.swagger.jaxrs.ext;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.parameters.Parameter;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public abstract class AbstractSwaggerExtension implements SwaggerExtension {

    @Override
    public String extractOperationMethod(ApiOperation apiOperation, Method method, Iterator chain) {
        if (chain.hasNext()) {
            return chain.next().extractOperationMethod(apiOperation, method, chain);
        } else {
            return null;
        }
    }

    @Override
    public List extractParameters(List annotations, Type type, Set typesToSkip,
                                             Iterator chain) {
        if (chain.hasNext()) {
            return chain.next().extractParameters(annotations, type, typesToSkip, chain);
        } else {
            return Collections.emptyList();
        }
    }

    protected boolean shouldIgnoreClass(Class cls) {
        return false;
    }

    protected boolean shouldIgnoreType(Type type, Set typesToSkip) {
        if (typesToSkip.contains(type)) {
            return true;
        }
        if (shouldIgnoreClass(constructType(type).getRawClass())) {
            typesToSkip.add(type);
            return true;
        }
        return false;
    }

    protected JavaType constructType(Type type) {
        return TypeFactory.defaultInstance().constructType(type);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy