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

com.gitee.easyopen.doc.ParamMarkdownHtmlBuilder Maven / Gradle / Ivy

Go to download

easyopen mini版,保留基本签名校验,文档功能。https://gitee.com/durcframework/easyopen

There is a newer version: 1.0.4
Show newest version
package com.gitee.easyopen.doc;

import org.apache.commons.collections.CollectionUtils;

import java.util.List;

/**
 * @author tanghc
 */
public class ParamMarkdownHtmlBuilder {

    private static final String START_TD = "";
    private static final String END_TD = "";
    private static final String START_TR = "";
    private static final String END_TR = "";
    private static final String TRUE = "true";


    public String buildHtml(ApiDocFieldDefinition definition) {
        StringBuilder html = new StringBuilder();
        html.append(START_TR)
                .append(wrapTD(definition.getName()))
                .append("" + definition.getDataType() + END_TD)
                .append(wrapTD(this.getRequireHtml(definition)))
                .append(wrapTD(buildExample(definition)))
                .append(wrapTD(definition.getDescription()));
        html.append(END_TR);

        return html.toString();
    }

    private String wrapTD(String content) {
        return START_TD + content + END_TD;
    }

    protected String buildExample(ApiDocFieldDefinition definition) {
        StringBuilder html = new StringBuilder();
        if (CollectionUtils.isNotEmpty(definition.getElements())) {
            html.append("")
                    .append(START_TR)
                    .append("")
                    .append("")
                    .append("")
                    .append("")
                    .append("")
                    .append(END_TR);

            List els = definition.getElements();
            for (ApiDocFieldDefinition apiDocFieldDefinition : els) {
                html.append(START_TR)
                        .append(wrapTD(apiDocFieldDefinition.getName()))
                        .append("
名称类型是否必须示例值描述" + apiDocFieldDefinition.getDataType() + END_TD) .append(wrapTD(getRequireHtml(apiDocFieldDefinition))) .append(wrapTD(buildExample(apiDocFieldDefinition))) .append(wrapTD(apiDocFieldDefinition.getDescription())) .append(END_TR); } html.append("
"); } else { html.append(buildExampleValue(definition)); } return html.toString(); } private String getRequireHtml(ApiDocFieldDefinition definition) { if (TRUE.equals(definition.getRequired())) { return ""; } else { return "否"; } } protected String buildExampleValue(ApiDocFieldDefinition definition) { return definition.getExample(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy