Java – why does the swagger annotation generate API docs with a default path prefix

I use the Maven plug-in below to integrate swagger with my application

I configured the following in my 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>

My swagger attributes are as follows

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

I generated API docs JSON is shown below. I'm not sure why it doesn't have a basic path and why it has the prefix "/ 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"
}
}

Solution

This "default" is the default name of the "swagger group"

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

You usually have only one group, which is named "default" If you want to change it, you should set the group name in the swaggerspring mvcplugin created by the swagger configuration Something like this:

@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 generate the following API JSON URL in swagger:

...
apis: [
{
    path: "/my-group/custom-controller",description: "backupset API"
}
....
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>