private boolean hasGlobalConsumes(ITypeModel type) { if (type.hasAnnotation(JAVAX_CONSUMES)) { return true; } IAnnotationModel apiAnn = type.getAnnotation(SWAGGER_API); if (apiAnn == null) { return false; } String consumes = apiAnn.getValue(JAVAX_CONSUMES.toLowerCase()); if (consumes != null) { return true; } return false; }
/** * process. * * @param packages a {@link java.util.Collection} object. */ public void process(Collection<CtPackage> packages) { if (packages == null) { return; } for (CtPackage package_ : packages) { processPackage(package_); } for (ITypeModel type : registry.getTypes()) { boolean hasGlobalConsumes = hasGlobalConsumes(type); for (IMethodModel method : type.getMethods()) { adjustReturnedAndBodyType(method, hasGlobalConsumes); } } }
private void adjustReturnedAndBodyType(IMethodModel method_, boolean hasGlobalConsumes) { if (!(method_ instanceof MethodModel)) { return; } MethodModel method = (MethodModel) method_; ITypeModel returnedType = method.getReturnedType(); if (returnedType != null) { if (returnedType instanceof ProxyType) { ITypeModel rt = registry.getType(returnedType.getFullyQualifiedName()); method.setReturnedType(rt); } } boolean hasConsumes = hasGlobalConsumes; IAnnotationModel apiOperation = method.getAnnotation(API_OPERATION); if (apiOperation != null) { IAnnotationModel[] subAnn = apiOperation.getSubAnnotations(JAVAX_CONSUMES.toLowerCase()); if (subAnn != null) { hasConsumes = true; } } IAnnotationModel consumes = method.getAnnotation(JAVAX_CONSUMES); if (consumes != null) { hasConsumes = true; } if (!hasConsumes) { return; } IParameterModel[] parameters = method.getParameters(); for (IParameterModel param_ : parameters) { String paramType = param_.getParameterType(); // if(paramType.startsWith("java.")){ // continue; // } if (isPrimitive(paramType)) { continue; } if (param_.hasAnnotation("QueryParam")) { continue; } if (param_.hasAnnotation("HeaderParam")) { continue; } if (param_.hasAnnotation("PathParam")) { continue; } if (param_.hasAnnotation("FormParam")) { continue; } if (param_.hasAnnotation("Context")) { continue; } ITypeModel type = registry.getType(paramType); if (type == null) { continue; } // IAnnotationModel typeAnnotation = type.getAnnotation(JAVAX_XML_TYPE); // if(typeAnnotation==null){ // continue; // } method.setBodyType(type); if (registry.isTargetType(paramType)) { break; } } }