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

com.yanyun.go.plugin.SwaggerToGoTestPlugin Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package com.yanyun.go.plugin;

import com.yanyun.go.properties.GoProperties;
import com.yanyun.go.service.ApiToGoTestService;
import org.springframework.util.StringUtils;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.OperationBuilderPlugin;
import springfox.documentation.spi.service.contexts.OperationContext;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Swagger支持GO测试的插件
 */
public class SwaggerToGoTestPlugin implements OperationBuilderPlugin {

    //GO 测试的配置
    private GoProperties goProperties;
    // api 生成服务
    private ApiToGoTestService apiToGoTestService;

    public SwaggerToGoTestPlugin(GoProperties goProperties, ApiToGoTestService apiToGoTestService) {
        this.goProperties = goProperties;
        this.apiToGoTestService = apiToGoTestService;
    }

    //提供go语言测试显示
    @Override
    public void apply(OperationContext context) {
        String info = apiToGoTestService.apiToStr(context).toString();
        String name = context.getName();

        String encode ="";
        try {
            encode = URLEncoder.encode(info, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        //暂时显示到notes部分
        String notes = context.operationBuilder().build().getNotes();
        if (StringUtils.isEmpty(notes)){

            context.operationBuilder().notes("下载Go测试代码样例");
        }else {
            context.operationBuilder().notes(notes +"\n"+ "下载Go测试代码样例");
        }
    }


    @Override
    public boolean supports(DocumentationType delimiter) {
        return goProperties.isEnable();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy