为什么swagger注释会生成带有默认路径前缀的api-docs

时间:2014-09-04 20:56:28

标签: java spring-mvc swagger swagger-maven-plugin

我使用下面的maven插件将swagger与我的应用程序集成 https://github.com/martypitt/swagger-springmvc

我在我的spring servlet xml

中配置了以下内容
<mvc:annotation-driven/> <!-- Required so swagger-springmvc can access spring's RequestMappingHandlerMapping  -->
<bean class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />

<mvc:default-servlet-handler/>

 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations" >
            <list>

                <value>/WEB-INF/swagger.properties</value>
            </list>
        </property>
    </bean>

我的招摇属性如下所示

documentation.services.basePath = http://payrollservice.com/customservice documentation.services.version = 1.0

我生成的api-docs.json如下所示,我不确定为什么它没有基本路径,为什么它有前缀&#34; / default&#34;

{
apiVersion: "1.0",
swaggerVersion: "1.2",
apis: [
{
path: "/default/custom-controller",
description: "backupset API"
}
],
info: {
title: "default Title",
description: "Api Description",
termsOfServiceUrl: "Api terms of service",
contact: "Contact Email",
license: "Licence Type",
licenseUrl: "License URL"
}
}

1 个答案:

答案 0 :(得分:7)

此“默认”是“招摇组”的默认名称

https://github.com/martypitt/swagger-springmvc#swagger-group

  

swagger组是此库引入的概念,它只是应用程序中Swagger资源列表的唯一标识符。引入此概念的原因是为了支持需要多个资源列表的应用程序。

您通常只有一个组,并将其命名为“默认”。如果要更改它,则应在swagger配置创建的SwaggerSpringMvcPlugin中设置组名。像这样:

@Configuration
@EnableSwagger
public class MySwaggerConfig {
    private SpringSwaggerConfig springSwaggerConfig;

    @Autowired
    public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
      this.springSwaggerConfig = springSwaggerConfig;
    }


    @Bean
    public SwaggerSpringMvcPlugin customImplementation() {
      return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
            .swaggerGroup("my-group");
    }
...
}

之后,您应该在Swagger中生成如下所示的API JSON URL:

...
apis: [
{
    path: "/my-group/custom-controller",
    description: "backupset API"
}
....