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

com.github.kongchen.swagger.docgen.mustache.MustacheResponseClass Maven / Gradle / Ivy

There is a newer version: 3.1.8
Show newest version
package com.github.kongchen.swagger.docgen.mustache;

import com.github.kongchen.swagger.docgen.TypeUtils;
import com.wordnik.swagger.core.util.ModelUtil;
import com.wordnik.swagger.model.Model;
import scala.Option;
import scala.Tuple2;

import java.util.LinkedList;

public class MustacheResponseClass {
    private String className;
    private String classLinkName;
    private LinkedList genericClasses;

    public MustacheResponseClass(String responseClass) {
        if ((TypeUtils.genericPattern.matcher(responseClass).matches())) {
            String trueType = TypeUtils.getTrueType(responseClass);
            this.classLinkName = trueType;
            this.className = trueType;
            genericClasses = new LinkedList();
            while (true) {
                int idx1 = responseClass.indexOf('<');
                int idx2 = responseClass.lastIndexOf('>');
                if (idx1 == -1 || idx2 == -1) {
                    break;
                }
                responseClass = responseClass.substring(idx1 + 1, idx2);
                if (responseClass.contains(",")) {
                    for (String c : responseClass.split(",")){
                        genericClasses.add(new MustacheResponseClass(c));
                    }
                } else {
                    genericClasses.add(new MustacheResponseClass(responseClass));
                }
            }
        } else {
            String trueType = TypeUtils.getTrueType(responseClass);
            Option> m = ModelUtil.modelFromString(responseClass);
            if (!m.isEmpty()) {
                this.classLinkName = m.get()._1();
                this.className = responseClass;
            }else if (trueType != null) {
                this.className = responseClass;
                this.classLinkName = trueType;
            }

            if (responseClass.equalsIgnoreCase("void")) {
                this.className = null;
            } else {
                this.className = responseClass;
            }

        }


    }

    public LinkedList getGenericClasses() {
        return genericClasses;
    }

    public void setGenericClasses(LinkedList genericClasses) {
        this.genericClasses = genericClasses;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getClassLinkName() {
        return classLinkName;
    }

    public void setClassLinkName(String classLinkName) {
        this.classLinkName = classLinkName;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy