2014-09-04 26 views
3

我用下面的Maven插件来招摇着我的应用程序 https://github.com/martypitt/swagger-springmvc为什么招摇的注释生成API的文档的默认路径前缀

整合我配置了下面我春天的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获取生成的样子如下,我不知道为什么它没有一个基本路径,为什么它有一个前缀“/默认”

{ 
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" 
} 
} 

回答

7

这种“默认”是“招摇组”

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

招摇组是由这个库这简直是一个扬鞭资源清单应用程序中的唯一标识符引入一个概念的默认名称。引入这个概念的原因是为了支持需要多个资源列表的应用程序。

您通常只会有一个组,它被命名为“default”。如果你想改变它,你应该在你的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"); 
    } 
... 
} 

之后,你应该在你扬鞭生成的API JSON的URL是这样的:

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