java – 为什么swagger注释会生成带有默认路径前缀的api-docs
我使用下面的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 我生成的api-docs.json如下所示,我不确定为什么它没有基本路径,为什么它有前缀“/ default” { 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" } } 解决方法
这个“默认”是“招摇组”的默认名称
https://github.com/martypitt/swagger-springmvc#swagger-group
您通常只有一个组,它被命名为“默认”.如果要更改它,则应在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" } .... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |