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

com.wordnik.swagger.jersey.SwaggerJerseyJaxrs Maven / Gradle / Ivy

There is a newer version: 1.5.3-M1
Show newest version
package com.wordnik.swagger.jersey;

import com.wordnik.swagger.converter.ModelConverters;
import com.wordnik.swagger.jaxrs.ext.*;
import com.wordnik.swagger.models.parameters.*;
import com.wordnik.swagger.models.properties.*;

import com.sun.jersey.multipart.FormDataParam;
import com.sun.jersey.api.core.InjectParam;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.lang.annotation.Annotation;

public class SwaggerJerseyJaxrs implements SwaggerExtension {
  static Logger LOGGER = LoggerFactory.getLogger(SwaggerJerseyJaxrs.class);

  public List extractParameters(Annotation[] annotations, Class cls, boolean isArray, Set> classesToSkip, Iterator chain) {
    List output = new ArrayList();
    if(shouldIgnoreClass(cls) || classesToSkip.contains(cls)) {
      // stop the processing chain
      classesToSkip.add(cls);
      return output;
    }
    for(Annotation annotation : annotations) {
      if(annotation instanceof FormDataParam) {
        FormDataParam fd = (FormDataParam) annotation;
        if(java.io.InputStream.class.equals(cls)) {
          Parameter param = new FormParameter().type("file").name(fd.value());
          output.add(param);
          return output;
        }
        else {
          FormParameter fp = new FormParameter().name(fd.value());
          Property schema = ModelConverters.getInstance().readAsProperty(cls);
          if(schema != null)
            fp.setProperty(schema);
          output.add(fp);
          return output;
        }
      }
    }
    if(chain.hasNext())
      return chain.next().extractParameters(annotations, cls, isArray, classesToSkip, chain);
    return null;
  }

  public boolean shouldIgnoreClass(Class cls) {
    boolean output = false;
    if(com.sun.jersey.core.header.FormDataContentDisposition.class.equals(cls))
      output = true;
    else
      output = false;
    LOGGER.debug("should ignore " + cls + ": " + output);
    return output;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy