All Projects → Willing-Xyz → RestDoc

Willing-Xyz / RestDoc

Licence: Apache-2.0 license
在运行时,使用Javadoc文档注释生成Swagger/OpenAPI规范

Programming Languages

java
68154 projects - #9 most used programming language
CSS
56736 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to RestDoc

Jeecg
JEECG是一款基于代码生成器的J2EE快速开发平台,开源界“小普元”超越传统商业企业级开发平台。引领新的开发模式(Online Coding模式(自定义表单) - > 代码生成器模式 - > 手工MERGE智能开发), 可以帮助解决Java项目90%的重复工作,让开发更多关注业务逻辑。既能快速提高开发效率,帮助公司节省人力成本,同时又不失灵活性。具备:表单配置能力(无需编码)、移动配置能力、工作流配置能力、报表配置能力(支持移动端)、插件开发能力(可插拔)
Stars: ✭ 2,027 (+3117.46%)
Mutual labels:  swagger-ui, springmvc
jeecg
JEECG是一款基于代码生成器的J2EE快速开发平台,开源界“小普元”超越传统商业企业级开发平台。引领新的开发模式(Online Coding模式(自定义表单) - > 代码生成器模式 - > 手工MERGE智能开发), 可以帮助解决Java项目90%的重复工作,让开发更多关注业务逻辑。既能快速提高开发效率,帮助公司节省人力成本,同时又不失灵活性。具备:表单配置能力(无需编码)、移动配置能力、工作流配置能力、报表配置能力(支持移动端)、插件开发能力(可插拔)
Stars: ✭ 2,090 (+3217.46%)
Mutual labels:  swagger-ui, springmvc
project-tracking-system-backend-app
Enterprise project tracker, tracks commits done by employees after getting assigned to a couple of projects by their managers
Stars: ✭ 62 (-1.59%)
Mutual labels:  javadoc
springfox-enum-plugin
✏️ Annotate your enums and have this Springfox-plugin automatically enhance your Swagger documents with it.
Stars: ✭ 39 (-38.1%)
Mutual labels:  springfox
DocDex
JSON API & Discord Bot for Javadocs
Stars: ✭ 31 (-50.79%)
Mutual labels:  javadoc
jd2chm
Create HTML Help project files from existing Javadoc and triggers the HHC compiler to generate a CHM file.
Stars: ✭ 17 (-73.02%)
Mutual labels:  javadoc
therapi-runtime-javadoc
Read Javadoc comments at run time.
Stars: ✭ 50 (-20.63%)
Mutual labels:  javadoc
marklet
Marklet is a custom Java Doclet which aims to generate a Javadoc in a markdown format which is ready to use in GitHub.
Stars: ✭ 24 (-61.9%)
Mutual labels:  javadoc
helm-swagger-ui
Helm Chart for Swagger UI
Stars: ✭ 23 (-63.49%)
Mutual labels:  swagger-ui
CodeDex
CodeDex Android source code, javadoc and github viewer
Stars: ✭ 32 (-49.21%)
Mutual labels:  javadoc
dubbo-springfox
extent springfox to support generate dubbo-api document 扩展springfox支持dubbo接口的文档化与图形化调用
Stars: ✭ 16 (-74.6%)
Mutual labels:  springfox
ForgeJavaDocs-NG
Minecraft Forge Javadocs for 1.12.2 - 1.18.2.
Stars: ✭ 17 (-73.02%)
Mutual labels:  javadoc
Spiget-Update
Spigot & Bungeecord updater API
Stars: ✭ 25 (-60.32%)
Mutual labels:  javadoc
Javaparser
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13
Stars: ✭ 3,972 (+6204.76%)
Mutual labels:  javadoc
javadoc-coverage
A Doclet to generate JavaDoc coverage reports ☕️🧪📗
Stars: ✭ 23 (-63.49%)
Mutual labels:  javadoc
jframework
基于对spring boot的二次封装,目的是减少重复代码,提高开发效率
Stars: ✭ 88 (+39.68%)
Mutual labels:  springfox
CompactNPCLib
Library to create NPCs
Stars: ✭ 22 (-65.08%)
Mutual labels:  javadoc
apidoc
通过JavaDoc生成OpenAPI文档
Stars: ✭ 25 (-60.32%)
Mutual labels:  javadoc
Mock.java
This is a framework for generating fake data, similar to Mock.js. 你可以通过这个框架简便的构建一个JavaBean假数据模板并生成假数据,就像Mock.js一样的语法~
Stars: ✭ 32 (-49.21%)
Mutual labels:  javadoc
WarmSearch
🏫 失物招领网站 (SpringBoot + MybatisPlus + JWT) 实现前后端分离项目的后台管理系统
Stars: ✭ 38 (-39.68%)
Mutual labels:  swagger-ui

介绍

该项目用于在运行时使用javadoc生成swagger文档,并使用swagger-ui进行显示。

示例

使用

第一步, 为SpringBoot项目中配置依赖, 配置RestDocConfig

Maven项目增加依赖:

<dependency>
     <groupId>cn.willingxyz.restdoc</groupId>
     <artifactId>RestDocSpringSwagger3</artifactId>
     <version>0.2.1.4</version>
</dependency>
<dependency>
    <groupId>com.github.therapi</groupId>
    <artifactId>therapi-runtime-javadoc-scribe</artifactId>
    <version>0.9.0</version>
    <scope>provided</scope>
</dependency>

新建配置文件,如下:

@Configuration
@EnableSwagger3
public class SwaggerConfig {
    @Bean
    RestDocConfig _swaggerConfig()
    {
            return RestDocConfig.builder()
                    .apiTitle("rest doc title")
                    .apiDescription("rest doc desc")
                    .apiVersion("api version")
                    .packages(Arrays.asList("cn.willingxyz.restdoc.spring.examples"))
                    .build();
    }
}

主要需要修改包名为自己的应用包名。

其他配置参考

第二步,启用Annotation Processors

  • IntelliJ IDEA: File > Settings > Preferences > Build, Execution, Deployment > Compiler > Annotation Processors > 勾选"Enable annotation processing". 编译设置

启动应用后,打开 http://host/swagger-ui/index.html 浏览

具体可参考 RestDocSpringExamples

BeanValidation支持

如果需要BeanValidation的支持,需要增加以下依赖:

<dependency>
    <groupId>cn.willingxyz.restdoc</groupId>
    <artifactId>RestDocBeanValidation</artifactId>
    <version>0.2.1.4</version>
</dependency>

支持BeanValidation的注解:

  • NotNull
  • AssertFalse
  • AssertTrue
  • DecimalMax
  • DecimalMin
  • Email (不支持正则表达式)
  • Max
  • Min
  • NegativeOrZero
  • Negative
  • NotBlank
  • NotEmpty
  • NotNull
  • Null
  • PositiveOrZero
  • Positive

Jackson支持

如果需要Jackson的支持,增加以下依赖:

<dependency>
    <groupId>cn.willingxyz.restdoc</groupId>
    <artifactId>RestDocJackson</artifactId>
    <version>0.2.1.4</version>
</dependency>

支持的Jackson注解:

  • JsonGetter
  • JsonSetter
  • JsonIgnore
  • JsonIgnoreType
  • JsonProperty (不支持对枚举的操作)
  • JsonIgnoreProperties (仅支持value属性)

配置参考

@Bean
RestDocConfig _swaggerConfig()
{
        return RestDocConfig.builder()
                //配置文档标题
                .apiTitle("rest doc title")
                //配置文档描述
                .apiDescription("rest doc desc")
                //配置文档版本
                .apiVersion("api version")
                //是否将类的javadoc解析为swagger显示名称
                .resolveJavaDocAsTypeName(true)
                //是否隐藏没有方法的Controller
                .hideEmptyController(true)
                //配置扫描的包
                .packages(Arrays.asList("cn.willingxyz.restdoc.spring.examples"))
                //启用httpBasic认证
                .httpBasicAuth(new RestDocConfig.HttpBasicAuth("restdoc","restdoc"))
                //配置接口地址
                .servers(Arrays.asList(RestDocConfig.Server.builder().description("url desc").url("localhost:8080").build()))
                //配置field前缀
                .fieldPrefix("_")
                .build();
}

其中 fieldPrefix表示字段前缀。 因为在获取javadoc时,会从field、get方法、set方法上获取,因此如果field有前缀,需要通过fieldPrefix设置,否则将无法获取到javadoc。 如:

public class Response {
    /**
    * name javadoc
    */
    private String _name;
    public String getName() {
           return _name;
    }
    public void setName(String name) {
        _name = name;
    }
}

Name属性对应的字段是_name,因此 fieldPrefix应该设置为 .fieldPrefix("_")

使用swagger2

如果需要使用Swagger2(兼容其他文档工具),替换依赖为:

<dependency>
     <groupId>cn.willingxyz.restdoc</groupId>
     <artifactId>RestDocSpringSwagger2</artifactId>
     <version>0.2.1.4</version>
</dependency>
<dependency>
    <groupId>com.github.therapi</groupId>
    <artifactId>therapi-runtime-javadoc-scribe</artifactId>
    <version>0.9.0</version>
    <scope>provided</scope>
</dependency>

将EnableSwagger3改为EnableSwagger2

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    //...
}

docker

docker通过以下命令运行:

docker run --rm -d -p 8084:8084 willingxyz/restdoc:0.2.1.4

swagger3规范打开 http://localhost:8084/swagger-ui/index.html 查看。 swagger2规范打开 http://localhost:8084/swagger2-ui/index.html 查看。

原理

通过注解处理器在编译时生成javadoc的json文件, 将这些文件转换为Swagger-ui的OpenApi数据格式。

更多信息请参考 Wiki

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].