oss-lib-swagger

Better swagger lib for spring-boot application

License

License

Categories

Categories

Swagger Program Interface REST Frameworks
GroupId

GroupId

cn.home1
ArtifactId

ArtifactId

oss-lib-swagger
Last Version

Last Version

1.0.8.OSS
Release Date

Release Date

Type

Type

xml
Description

Description

oss-lib-swagger
Better swagger lib for spring-boot application
Project URL

Project URL

https://github.com/home1-oss/oss-lib-swagger
Source Code Management

Source Code Management

https://github.com/home1-oss/oss-lib-swagger

Download oss-lib-swagger

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • oss-lib-swagger-spring-boot-1.4.1.RELEASE
  • oss-lib-swagger-spring-boot-1.4.2.RELEASE

oss-lib-swagger

Indroduction

通过引入oss-lib-swagger自动生成RESTful的api的接口文档,出于安全的考虑生成环境(production)暂不生成api文档。

使用方式

直接在spring boot工程中添加依赖,在非production发布时会生成对应的文档。

  1. 添加依赖
  2. 部署应用
  3. 访问swagger-ui: http://127.0.0.1:8080:8080/swagger-ui.html 接口说明文档 configserver.png swagger-ui交互请求结果 configserver.png
  4. 访问api-docs: http://127.0.0.1:8080:8080/v2/api-docs api-docks configserver.png swagger.ed插件示意图 configserver.png

依赖

    <dependency>
        <groupId>cn.home1</groupId>
        <artifactId>oss-lib-swagger-spring-boot-${spring-boot.version}</artifactId>
    </dependency>

application.yml:

springfox.documentation.swagger.v1.path: '/api-docs'
springfox.documentation.swagger.v2.path: '/v2/api-docs'

NOTES:如果项目开启了自定义的SpringMVC,即@EnableWebMvc,需要配置指定swagger-ui.html的路径,如下:

@Configuration
@EnableWebMvc
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }

}

参考文档

official docs

swagger-editor springfox-plugin-for-adding-auth-params

usage-of-swagger-2-0-in-spring-boot-applications-to-document-apis

Could it work without RequestMapping annotations? #511 Ability to add custom ApiDescriptions not described via request mappings #1335

cn.home1

home1-oss

Versions

Version
1.0.8.OSS
1.0.7.OSS