Why swagger annotations generate api-docs with default path prefix
I used the below maven plugin to integrate swagger with my app https://github.com/martypitt/swagger-springmvc
I configured below in my spring xml servlet
<mvc:annotation-driven/> <!-- Required so swagger-springmvc can access spring 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>
My swagger properties looked like below
documentation.services.basePath = http://payrollservice.com/customservice documentation.services.version = 1.0
My api-docs.json that is generated looks like below and I'm not sure why it doesn't have a base path and why it has the "/ default" prefix
{
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"
}
}
source to share
This "default" is the default "markup group"
https://github.com/martypitt/swagger-springmvc#swagger-group
The swagger group is a concept introduced by this library, which is simply a unique identifier for a list of Swagger resources in your application. The reason this concept was introduced was to support applications that require more than one resource list.
Usually you will have only one group, and it is called "default". If you want to change it, you must set the group name in the SwaggerSpringMvcPlugin generated by your swagger config. Something like that:
@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");
}
...
}
After that, you should have in your Swagger generated JSON API URLs like this:
...
apis: [
{
path: "/my-group/custom-controller",
description: "backupset API"
}
....
source to share