use of com.webcohesion.enunciate.api.resources.Parameter in project enunciate by stoicflame.
the class ValidParametersMethod method exec.
public Object exec(List list) throws TemplateModelException {
if (list.size() < 1) {
throw new TemplateModelException("The responsesOf method must have a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = FreemarkerUtil.unwrap(from);
if (unwrapped instanceof Method) {
Method method = (Method) unwrapped;
ArrayList<Parameter> params = new ArrayList<Parameter>();
for (Parameter parameter : method.getParameters()) {
String type = parameter.getTypeLabel().toLowerCase();
if (type.contains("path")) {
params.add(new SwaggerParameter(parameter, "path"));
} else if (type.contains("form")) {
params.add(new SwaggerParameter(parameter, "formData"));
} else if (type.contains("query")) {
params.add(new SwaggerParameter(parameter, "query"));
} else if (type.contains("header")) {
params.add(new SwaggerParameter(parameter, "header"));
}
}
return params;
}
throw new TemplateModelException("No parameters for: " + unwrapped);
}
use of com.webcohesion.enunciate.api.resources.Parameter in project enunciate by stoicflame.
the class UniquePathParametersForMethod method exec.
public Object exec(List list) throws TemplateModelException {
if (list.size() < 1) {
throw new TemplateModelException("The uniqueMediaTypesFor method must have a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = FreemarkerUtil.unwrap(from);
Map<String, Parameter> uniquePathParams = new HashMap<String, Parameter>();
if (unwrapped instanceof Resource) {
Resource entity = (Resource) unwrapped;
List<? extends Method> methods = entity.getMethods();
if (methods != null) {
for (Method method : methods) {
List<? extends Parameter> params = method.getParameters();
if (params != null) {
for (Parameter param : params) {
if (param.getTypeLabel().equals("path")) {
uniquePathParams.put(param.getName(), param);
}
}
}
}
}
}
return uniquePathParams.values();
}
Aggregations