Java Code Examples for io.swagger.jaxrs.ext.SwaggerExtension#extractParameters()

The following examples show how to use io.swagger.jaxrs.ext.SwaggerExtension#extractParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtendedSwaggerReader.java    From msf4j with Apache License 2.0 5 votes vote down vote up
private List<Parameter> getParameters(Type type, List<Annotation> annotations) {
    final Iterator<SwaggerExtension> chain = SwaggerExtensions.chain();
    if (!chain.hasNext()) {
        return Collections.emptyList();
    }
    LOGGER.debug("getParameters for " + type);
    Set<Type> typesToSkip = new HashSet<>();
    final SwaggerExtension extension = chain.next();
    LOGGER.debug("trying extension " + extension);

    final List<Parameter> parameters = extension.extractParameters(annotations, type, typesToSkip, chain);
    if (parameters.size() > 0) {
        final List<Parameter> processed = new ArrayList<>(parameters.size());
        processed.addAll(parameters.stream().filter(parameter -> ParameterProcessor
                                                                         .applyAnnotations(swagger, parameter, type,
                                                                                           annotations) != null)
                                   .collect(Collectors.toList()));
        return processed;
    } else {
        LOGGER.debug("no parameter found, looking at body params");
        final List<Parameter> body = new ArrayList<>();
        if (!typesToSkip.contains(type)) {
            Parameter param = ParameterProcessor.applyAnnotations(swagger, null, type, annotations);
            if (param != null) {
                body.add(param);
            }
        }
        return body;
    }
}
 
Example 2
Source File: AbstractReader.java    From swagger-maven-plugin with Apache License 2.0 5 votes vote down vote up
protected List<Parameter> getParameters(Type type, List<Annotation> annotations, Set<Type> typesToSkip) {
    if (!hasValidAnnotations(annotations) || isApiParamHidden(annotations)) {
        return Collections.emptyList();
    }

    Iterator<SwaggerExtension> chain = SwaggerExtensions.chain();
    List<Parameter> parameters = new ArrayList<>();
    Class<?> cls = TypeUtils.getRawType(type, type);
    LOG.debug("Looking for path/query/header/form/cookie params in " + cls);

    if (chain.hasNext()) {
        SwaggerExtension extension = chain.next();
        LOG.debug("trying extension " + extension);
        parameters = extension.extractParameters(annotations, type, typesToSkip, chain);
    }

    if (!parameters.isEmpty()) {
        for (Parameter parameter : parameters) {
            ParameterProcessor.applyAnnotations(swagger, parameter, type, annotations);
        }
    } else {
        LOG.debug("Looking for body params in " + cls);
        // parameters is guaranteed to be empty at this point, replace it with a mutable collection
        parameters = Lists.newArrayList();
        if (!typesToSkip.contains(type)) {
            Parameter param = ParameterProcessor.applyAnnotations(swagger, null, type, annotations);
            if (param != null) {
                parameters.add(param);
            }
        }
    }
    return parameters;
}
 
Example 3
Source File: Reader.java    From proteus with Apache License 2.0 4 votes vote down vote up
private List<Parameter> getParameters(Type type, List<Annotation> annotations, java.lang.reflect.Parameter methodParameter, List<String> pathParamNames) {
      final Iterator<SwaggerExtension> chain = SwaggerExtensions.chain();
      
       
      if (!chain.hasNext()) {
          return Collections.emptyList();
      }
 
      
   //   LOGGER.debug("getParameters for {}", type);
      Set<Type> typesToSkip = new HashSet<>();
      typesToSkip.add(TypeFactory.defaultInstance().constructType(ServerRequest.class));
      typesToSkip.add(TypeFactory.defaultInstance().constructType(HttpServerExchange.class));
      typesToSkip.add(TypeFactory.defaultInstance().constructType(ServerResponse.class));
      typesToSkip.add(TypeFactory.defaultInstance().constructType(HttpHandler.class));
      typesToSkip.add(TypeFactory.defaultInstance().constructType(io.undertow.server.session.Session.class));

      final SwaggerExtension extension = chain.next();
            
      if (typesToSkip.contains(type)) {
          return Collections.emptyList();
      }
 
 
      annotations = new ArrayList<>(annotations);

       
      if(! annotations.stream().filter( a -> a instanceof ApiParam ).findFirst().isPresent() )
      {
      	annotations.add( AnnotationHelper.createApiParam( methodParameter ) ) ; 
      }
      

if(type.getTypeName().contains("java.nio.file.Path") || type.getTypeName().contains("java.nio.ByteBuffer")  || type.getTypeName().contains("java.io.File"))
      { 
	  if(type.getTypeName().contains("java.nio.file.Path") || type.getTypeName().contains("java.nio.ByteBuffer"))
      {
      	type = java.io.File.class;
      }
	
	  annotations.add(AnnotationHelper.createFormParam(methodParameter));
	  
      }

      if(annotations.size() == 1)
      {
      	if( annotations.get(0) instanceof ApiParam)
      	{ 
      	    // If there is only one ApiParam and the parameter type is a member of the java.lang and the name of that parameter is in the path operation's path make the assumption that this is a path param
      		if(methodParameter.getType().getName().indexOf("java.lang") > -1 && pathParamNames.contains(methodParameter.getName()))
      		{
      			annotations.add(AnnotationHelper.createPathParam(methodParameter));

      		}
      	    // If there is only one ApiParam and the parameter type is a member of the java.lang or java.util package we make the assumption that this is a query param
      		else if( methodParameter.getType().getName().indexOf("java.lang") > -1 || methodParameter.getType().getName().indexOf("java.util") > -1 )
      		{
      			annotations.add(AnnotationHelper.createQueryParam(methodParameter));
      		}
      	}
      }
      
      final List<Parameter> parameters = extension.extractParameters(annotations, type, typesToSkip, chain);
      if (!parameters.isEmpty()) {
          final List<Parameter> processed = new ArrayList<Parameter>(parameters.size());
          for (Parameter parameter : parameters) {
          	
            //  LOGGER.debug("getParameters for {}", type);

              if (ParameterProcessor.applyAnnotations(swagger, parameter, type, annotations) != null) {
              	
                  processed.add(parameter);
              }
          }
          return processed;
      } else {
        //  LOGGER.debug("no parameter found, looking at body params");
          final List<Parameter> body = new ArrayList<Parameter>();
          if (!typesToSkip.contains(type)) {
          	
              Parameter param = ParameterProcessor.applyAnnotations(swagger, null, type, annotations);
              if (param != null) {
              	 
                  body.add(param);
              }
          }
          return body;
      }
  }