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

com.hzlinks.swagger.rpc.config.DubboPropertyConfig Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package com.hzlinks.swagger.rpc.config;

import com.hzlinks.swagger.rpc.boot.RpcSwaggerProperties;
import com.hzlinks.swagger.rpc.http.ReferenceManager;
import io.swagger.config.SwaggerConfig;
import io.swagger.models.Contact;
import io.swagger.models.Info;
import io.swagger.models.Swagger;
import java.text.MessageFormat;
import javax.annotation.Resource;
import javax.servlet.ServletContext;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.springframework.stereotype.Component;

/**
 * @author harold
 */
@Component
public class DubboPropertyConfig implements SwaggerConfig {


    @Resource
    private RpcSwaggerProperties rpcSwaggerProperties;

    @Resource
    private ServletContext servletContext;

    private static final String mavenDependency = "<dependency>
" + "    <groupId>{0}</groupId>
" + "    <artifactId>{1}</artifactId>
" + "    <version>{2}</version>
" + "</dependency>
"; @Override public Swagger configure(Swagger swagger) { ApplicationConfig application = ReferenceManager.getInstance().getApplication(); if (null != application) { Info info = swagger.getInfo(); if (info == null) { info = new Info(); swagger.setInfo(info); } info.setTitle(application.getName()); String version = StringUtils.isNotBlank(rpcSwaggerProperties.getVersion()) ? rpcSwaggerProperties.getVersion() : application.getVersion(); String groupId = rpcSwaggerProperties.getGroupId(); String artifactId = rpcSwaggerProperties.getArtifactId(); if (StringUtils.isNotBlank(groupId) && StringUtils.isNotBlank(artifactId) && StringUtils.isNotBlank(version)) { info.setDescription(MessageFormat.format(mavenDependency, groupId, artifactId, version)); } info.setVersion(StringUtils.isNotBlank(version) ? version : ""); Contact contact = new Contact(); info.setContact(contact); contact.setName(application.getOwner()); } setBashPath(swagger); return swagger; } private void setBashPath(Swagger swagger) { if (StringUtils.isEmpty(swagger.getBasePath())) { swagger.setBasePath( StringUtils.isEmpty(servletContext.getContextPath()) ? "/" : servletContext.getContextPath()); } } @Override public String getFilterClass() { return null; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy