<commit_before>package org.voovan.http.server.module.annontationRouter.swagger;

import org.voovan.Global;
import org.voovan.http.message.HttpStatic;
import org.voovan.http.server.*;
import org.voovan.http.server.module.annontationRouter.annotation.*;
import org.voovan.http.server.module.annontationRouter.router.AnnotationRouter;
import org.voovan.http.server.module.annontationRouter.router.RouterInfo;
import org.voovan.http.server.module.annontationRouter.swagger.entity.*;
import org.voovan.http.server.module.annontationRouter.swagger.entity.Property;
import org.voovan.tools.TFile;
import org.voovan.tools.TObject;
import org.voovan.tools.TProperties;
import org.voovan.tools.TString;
import org.voovan.tools.json.JSON;
import org.voovan.tools.log.Logger;
import org.voovan.tools.reflect.TReflect;
import org.voovan.tools.reflect.annotation.NotSerialization;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Swagger 配置构造类
 *
 * @author: helyho
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class SwaggerApi {
    public static ConcurrentHashMap<String,Swagger> MODULE_SWAGGER = new ConcurrentHashMap<String, Swagger>();

    static {
    }

    public static void init(HttpModule httpModule) {
        WebServer webserver = httpModule.getWebServer();
        Map<String, Object> swaggerConfig = (Map<String, Object>) httpModule.getModuleConfig().getParameter("Swagger");
        if(swaggerConfig == null) {
            swaggerConfig = TObject.asMap();
        }

        String  moduleName      = httpModule.getModuleConfig().getName();
        String  modulePath      = httpModule.getModuleConfig().getPath();
        Boolean enable          = (Boolean) swaggerConfig.getOrDefault("Enable", true);

        if(enable == false) {
            return;
        }

        String  routePath       = (String)  swaggerConfig.getOrDefault("RoutePath", "/swagger");
        Integer refreshInterval = (Integer) swaggerConfig.getOrDefault("RefreshInterval", 30);
        String  description     = (String)  swaggerConfig.getOrDefault("Description", "");
        String  version         = (String)  swaggerConfig.get("Version");

        MODULE_SWAGGER.put(moduleName, new Swagger(httpModule.getModuleConfig().getPath(), description, version));

        if(enable) {
            SwaggerApi.buildModuleSwagger(moduleName);
            Global.getHashWheelTimer().addTask(()->{
                MODULE_SWAGGER.put(moduleName, new Swagger(modulePath, description, version));

                SwaggerApi.buildModuleSwagger(moduleName);
            }, refreshInterval);

            String swaggerPath = routePath + (modulePath.startsWith("/") ? modulePath : ("/" + modulePath));
            swaggerPath = HttpDispatcher.fixRoutePath(swaggerPath);

            webserver.get(swaggerPath+"-ui", new HttpRouter() {
                @Override
                public void process(HttpRequest request, HttpResponse response) throws Exception {
                    response.header().put(HttpStatic.CONTENT_TYPE_STRING, HttpStatic.TEXT_HTML_STRING);
                    response.write(TFile.loadResource("org/voovan/http/server/conf/swagger.html"));
                }<commit_msg>imp: swagger 默认不刷新 swagger 信息<commit_after>package org.voovan.http.server.module.annontationRouter.swagger;

import org.voovan.Global;
import org.voovan.http.message.HttpStatic;
import org.voovan.http.server.*;
import org.voovan.http.server.module.annontationRouter.annotation.*;
import org.voovan.http.server.module.annontationRouter.router.AnnotationRouter;
import org.voovan.http.server.module.annontationRouter.router.RouterInfo;
import org.voovan.http.server.module.annontationRouter.swagger.entity.*;
import org.voovan.http.server.module.annontationRouter.swagger.entity.Property;
import org.voovan.tools.TFile;
import org.voovan.tools.TObject;
import org.voovan.tools.TProperties;
import org.voovan.tools.TString;
import org.voovan.tools.json.JSON;
import org.voovan.tools.log.Logger;
import org.voovan.tools.reflect.TReflect;
import org.voovan.tools.reflect.annotation.NotSerialization;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Swagger 配置构造类
 *
 * @author: helyho
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class SwaggerApi {
    public static ConcurrentHashMap<String,Swagger> MODULE_SWAGGER = new ConcurrentHashMap<String, Swagger>();

    static {
    }

    public static void init(HttpModule httpModule) {
        WebServer webserver = httpModule.getWebServer();
        Map<String, Object> swaggerConfig = (Map<String, Object>) httpModule.getModuleConfig().getParameter("Swagger");
        if(swaggerConfig == null) {
            swaggerConfig = TObject.asMap();
        }

        String  moduleName      = httpModule.getModuleConfig().getName();
        String  modulePath      = httpModule.getModuleConfig().getPath();
        Boolean enable          = (Boolean) swaggerConfig.getOrDefault("Enable", true);

        if(enable == false) {
            return;
        }

        String  routePath       = (String)  swaggerConfig.getOrDefault("RoutePath", "/swagger");
        Integer refreshInterval = (Integer) swaggerConfig.getOrDefault("RefreshInterval", -1);
        String  description     = (String)  swaggerConfig.getOrDefault("Description", "");
        String  version         = (String)  swaggerConfig.get("Version");

        MODULE_SWAGGER.put(moduleName, new Swagger(httpModule.getModuleConfig().getPath(), description, version));

        if(enable) {
            SwaggerApi.buildModuleSwagger(moduleName);

            if(refreshInterval > 0) {
                Global.getHashWheelTimer().addTask(() -> {
                    MODULE_SWAGGER.put(moduleName, new Swagger(modulePath, description, version));

                    SwaggerApi.buildModuleSwagger(moduleName);
                }, refreshInterval);
            }

            String swaggerPath = routePath + (modulePath.startsWith("/") ? modulePath : ("/" + modulePath));
            swaggerPath = HttpDispatcher.fixRoutePath(swaggerPath);

            webserver.get(swaggerPath+"-ui", new HttpRouter() {
                @Override
                public void process(HttpRequest request, HttpResponse response) throws Exception {
                    response.header().put(HttpStatic.CONTENT_TYPE_STRING, HttpStatic.TEXT_HTML_STRING);
                    response.write(TFile.loadResource("org/voovan/http/server/conf/swagger.html"));
                }
{'fraction_non_alphanumeric': 0.11532385466034756, 'fraction_numerical': 0.0008616975441619991, 'mean_word_length': 3.363408521303258, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2658284', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1966, 'n_words': 328}