Search in sources :

Example 1 with Parameter

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);
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) ArrayList(java.util.ArrayList) Parameter(com.webcohesion.enunciate.api.resources.Parameter) TemplateModel(freemarker.template.TemplateModel) Method(com.webcohesion.enunciate.api.resources.Method)

Example 2 with Parameter

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();
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) HashMap(java.util.HashMap) Resource(com.webcohesion.enunciate.api.resources.Resource) Parameter(com.webcohesion.enunciate.api.resources.Parameter) TemplateModel(freemarker.template.TemplateModel) Method(com.webcohesion.enunciate.api.resources.Method)

Aggregations

Method (com.webcohesion.enunciate.api.resources.Method)2 Parameter (com.webcohesion.enunciate.api.resources.Parameter)2 TemplateModel (freemarker.template.TemplateModel)2 TemplateModelException (freemarker.template.TemplateModelException)2 Resource (com.webcohesion.enunciate.api.resources.Resource)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1